|
@@ -15,6 +15,7 @@ import subprocess
|
|
|
import random
|
|
|
import configparser
|
|
|
import hashlib
|
|
|
+import urllib
|
|
|
|
|
|
from musicpd import MPDClient
|
|
|
|
|
@@ -82,7 +83,18 @@ def addurl(url, user = "-unknown-"):
|
|
|
print ('--- URL malformato ---')
|
|
|
return ("Err: url non valido")
|
|
|
|
|
|
-
|
|
|
+ # #trova l'id dall'url
|
|
|
+ # u = urllib.parse.urlparse(url)
|
|
|
+ # q = urllib.parse.parse_qs(u.query)
|
|
|
+ # if q:
|
|
|
+ # id=q["v"][0]
|
|
|
+
|
|
|
+ # #cerca se ho gia' il json
|
|
|
+ # if glob(os.path.join("cache", id + ".json")):
|
|
|
+ # #legge le info
|
|
|
+ # with open(os.path.join("cache", id + ".json")) as infile:
|
|
|
+ # title = __normalizetext(json.load(infile)['title'])
|
|
|
+
|
|
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
|
try:
|
|
|
meta = ydl.extract_info(url, download = False)
|
|
@@ -106,7 +118,8 @@ def addurl(url, user = "-unknown-"):
|
|
|
filetemp = os.path.join("cache", id + ".m4a")
|
|
|
if not glob(filetemp):
|
|
|
print ('--- Scarico ---')
|
|
|
- ydl.download([url]) #non ho capito perche' ma senza [] fa un carattere per volta
|
|
|
+ with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
|
+ ydl.download([url]) #non ho capito perche' ma senza [] fa un carattere per volta
|
|
|
|
|
|
if not os.path.isfile(filetemp):
|
|
|
return("Err: file non scaricato")
|
|
@@ -129,27 +142,33 @@ def add(filetemp, user = "-unknown-", title = None, id = None):
|
|
|
|
|
|
#se il file esiste gia' in playlist salto (potrebbe esserci, anche rinominato)
|
|
|
if glob("playlist/**/*|" + id + ".*"):
|
|
|
- print ('--- File già presente ---')
|
|
|
- return ("Err: %s [%s] già presente" %(title, id))
|
|
|
+ print ('--- File già presente ---')
|
|
|
+ return ("Err: %s [%s] già presente" %(title, id))
|
|
|
|
|
|
- os.makedirs("playlist/" + user, exist_ok=True)
|
|
|
+ os.makedirs("playlist/" + user, exist_ok=True)
|
|
|
#qui compone il nome del file
|
|
|
if SHUFFLESONGS:
|
|
|
fileout = str(random.randrange(10**6)).zfill(14) + "|" + title + "|" + id + ".m4a"
|
|
|
else:
|
|
|
fileout = time.strftime("%Y%m%d%H%M%S") + "|" + title + "|" + id + ".m4a"
|
|
|
fileout = os.path.join("playlist/" + user, fileout)
|
|
|
-
|
|
|
- print ('--- Converto ---')
|
|
|
- print (fileout)
|
|
|
- subprocess.call([scriptpath + "/trimaudio.sh", filetemp, fileout])
|
|
|
- if not os.path.isfile(fileout):
|
|
|
- return("Err: file non convertito")
|
|
|
-
|
|
|
- if ARCHIVE:
|
|
|
- os.makedirs("archive", exist_ok=True)
|
|
|
- if not glob("archive/*|" + id + ".*"):
|
|
|
- shutil.copy2(fileout, "archive")
|
|
|
+
|
|
|
+ #se il file esiste gia' in archive prendo quello
|
|
|
+ if glob("archive/*|" + id + ".*"):
|
|
|
+ print ('--- File in archivio ---')
|
|
|
+ copyfile(glob("archive/*|" + id + ".*")[0], fileout)
|
|
|
+ else:
|
|
|
+ print ('--- Converto ---')
|
|
|
+ print (fileout)
|
|
|
+
|
|
|
+ subprocess.call([scriptpath + "/trimaudio.sh", filetemp, fileout])
|
|
|
+ if not os.path.isfile(fileout):
|
|
|
+ return("Err: file non convertito")
|
|
|
+
|
|
|
+ if ARCHIVE:
|
|
|
+ os.makedirs("archive", exist_ok=True)
|
|
|
+ if not glob("archive/*|" + id + ".*"):
|
|
|
+ shutil.copy2(fileout, "archive")
|
|
|
|
|
|
#cerca la posizione del pezzo appena inserito
|
|
|
pos = getposition(fileout)
|