|
@@ -17,18 +17,19 @@ scriptpath = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
|
def add(url, user = "-unknown-", sortrandom = False):
|
|
|
- print ('--- Inizio ---')
|
|
|
+ #print ('--- Inizio ---')
|
|
|
init()
|
|
|
|
|
|
ydl_opts = {
|
|
|
'format': 'bestaudio[ext=m4a]',
|
|
|
'outtmpl': 'cache/%(id)s.m4a',
|
|
|
'noplaylist': True,
|
|
|
+ 'quiet': True,
|
|
|
}
|
|
|
|
|
|
url = url.strip()
|
|
|
- print (url)
|
|
|
- print (user)
|
|
|
+ print ("url: " + url)
|
|
|
+ print ("user: " + user)
|
|
|
|
|
|
if not validators.url(url):
|
|
|
print ('--- URL malformato ---')
|
|
@@ -46,8 +47,8 @@ def add(url, user = "-unknown-", sortrandom = False):
|
|
|
id = meta.get('id').strip()
|
|
|
title = __normalizetext(meta.get('title'))
|
|
|
|
|
|
- print ('id : %s' %(id))
|
|
|
- print ('title : %s' %(title))
|
|
|
+ print ('id: %s' %(id))
|
|
|
+ print ('title: %s' %(title))
|
|
|
|
|
|
#scrivo il json
|
|
|
with open(os.path.join("cache", id + ".json"), 'w') as outfile:
|
|
@@ -60,29 +61,25 @@ def add(url, user = "-unknown-", sortrandom = False):
|
|
|
print ('--- Scarico ---')
|
|
|
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")
|
|
|
+
|
|
|
#se il file esiste gia' in playlist salto (potrebbe esserci, anche rinominato)
|
|
|
if glob(scriptpath + "/playlist/**/*|" + id + ".*"):
|
|
|
print ('--- File già presente ---')
|
|
|
return ("Err: %s [%s] già presente" %(title, id))
|
|
|
|
|
|
- print ('--- Scarico ---')
|
|
|
if not os.path.exists("playlist/" + user):
|
|
|
- os.makedirs("playlist/" + user) #qui compone il nome del file
|
|
|
+ os.makedirs("playlist/" + user)
|
|
|
+ #qui compone il nome del file
|
|
|
if sortrandom:
|
|
|
fileout = str(random.randrange(10**6)).zfill(14) + "|" + title + "|" + id + ".m4a"
|
|
|
else:
|
|
|
fileout = time.strftime("%Y%m%d%H%M%S") + "|" + title + "|" + id + ".m4a"
|
|
|
-
|
|
|
-
|
|
|
- print (fileout)
|
|
|
fileout = os.path.join("playlist/" + user, fileout)
|
|
|
|
|
|
- if not os.path.isfile(filetemp):
|
|
|
- return("Err: file non scaricato")
|
|
|
- #copia il file nella cartella playlist
|
|
|
- #shutil.copy(filetemp, fileout)
|
|
|
-
|
|
|
- print ('--- Converto ---')
|
|
|
+ print ('--- Converto ---')
|
|
|
+ print (fileout)
|
|
|
subprocess.call([scriptpath + "/trimaudio.sh", filetemp, fileout])
|
|
|
if not os.path.isfile(fileout):
|
|
|
return("Err: file non convertito")
|
|
@@ -90,7 +87,7 @@ def add(url, user = "-unknown-", sortrandom = False):
|
|
|
#cerca la posizione del pezzo appena inserito
|
|
|
pos = getposition(fileout)
|
|
|
|
|
|
- print ('--- Fine ---')
|
|
|
+ #print ('--- Fine ---')
|
|
|
print ("")
|
|
|
|
|
|
return ("OK: %s [%s] aggiunto alla playlist in posizione %s" %(title, id, pos))
|