|
@@ -32,7 +32,7 @@ def add(url, user = "-unknown-", sortrandom = False):
|
|
|
|
|
|
if not validators.url(url):
|
|
|
print ('--- URL malformato ---')
|
|
|
- return ("Errore: url non valido")
|
|
|
+ return ("Err: url non valido")
|
|
|
|
|
|
|
|
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
@@ -41,10 +41,10 @@ def add(url, user = "-unknown-", sortrandom = False):
|
|
|
except youtube_dl.DownloadError as detail:
|
|
|
print ('--- Errore video non disponibile ---')
|
|
|
print(str(detail))
|
|
|
- return (str(detail))
|
|
|
+ return ("Err: " + str(detail))
|
|
|
|
|
|
id = meta.get('id').strip()
|
|
|
- title = normalizetext(meta.get('title'))
|
|
|
+ title = __normalizetext(meta.get('title'))
|
|
|
|
|
|
print ('id : %s' %(id))
|
|
|
print ('title : %s' %(title))
|
|
@@ -63,10 +63,11 @@ def add(url, user = "-unknown-", sortrandom = False):
|
|
|
#se il file esiste gia' in playlist salto (potrebbe esserci, anche rinominato)
|
|
|
if glob(scriptpath + "/playlist/**/*|" + id + ".*"):
|
|
|
print ('--- File già presente ---')
|
|
|
- return ("Errore: %s [%s] già presente" %(title, id))
|
|
|
+ return ("Err: %s [%s] già presente" %(title, id))
|
|
|
|
|
|
- print ('--- Converto ---')
|
|
|
- #qui compone il nome del file
|
|
|
+ print ('--- Scarico ---')
|
|
|
+ if not os.path.exists("playlist/" + user):
|
|
|
+ os.makedirs("playlist/" + user) #qui compone il nome del file
|
|
|
if sortrandom:
|
|
|
fileout = str(random.randrange(10**6)).zfill(14) + "|" + title + "|" + id + ".m4a"
|
|
|
else:
|
|
@@ -74,27 +75,31 @@ def add(url, user = "-unknown-", sortrandom = False):
|
|
|
|
|
|
|
|
|
print (fileout)
|
|
|
-
|
|
|
- if not os.path.exists("playlist/" + user):
|
|
|
- os.makedirs("playlist/" + user)
|
|
|
-
|
|
|
fileout = os.path.join("playlist/" + user, fileout)
|
|
|
|
|
|
- if os.path.isfile(filetemp):
|
|
|
- #copia il file nella cartella playlist
|
|
|
- #shutil.copy(filetemp, fileout)
|
|
|
- print("ESEGUI")
|
|
|
- subprocess.call([scriptpath + "/trimaudio.sh", filetemp, fileout])
|
|
|
-
|
|
|
-
|
|
|
+ if not os.path.isfile(filetemp):
|
|
|
+ return("Err: file non scaricato")
|
|
|
+ #copia il file nella cartella playlist
|
|
|
+ #shutil.copy(filetemp, fileout)
|
|
|
+
|
|
|
+ print ('--- Converto ---')
|
|
|
+ subprocess.call([scriptpath + "/trimaudio.sh", filetemp, fileout])
|
|
|
+ if not os.path.isfile(fileout):
|
|
|
+ return("Err: file non convertito")
|
|
|
+
|
|
|
+ #cerca la posizione del pezzo appena inserito
|
|
|
+ pos = getposition(fileout)
|
|
|
+
|
|
|
print ('--- Fine ---')
|
|
|
print ("")
|
|
|
|
|
|
- return ("Scaricato %s [%s]" %(title, id))
|
|
|
+ return ("OK: %s [%s] aggiunto alla playlist in posizione %s" %(title, id, pos))
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
-def normalizetext(s):
|
|
|
+def __normalizetext(s):
|
|
|
if s is None:
|
|
|
return None
|
|
|
else:
|
|
@@ -231,15 +236,16 @@ def shufflefallback():
|
|
|
fname = os.path.dirname(file) + "/" + fname
|
|
|
os.rename(file, fname)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+def getposition(file):
|
|
|
+ pl = list()
|
|
|
+ try:
|
|
|
+ return([x[0] for x in pl].index(file) + 1)
|
|
|
+ except:
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
print ("This is a package, use other commands to run it")
|
|
|
-
|
|
|
+ getposition("playlist/Itec78/20200404145736|George Baker- Little Green Bag|4b1wt3-zpzQ.m4az")
|