|
@@ -2,6 +2,7 @@
|
|
|
#Playlistalo - simpatico script che legge le cartelle e genera la playlist
|
|
|
#Requirements: youtube_dl Mastodon.py python-telegram-bot validators python-musicpd
|
|
|
|
|
|
+#import youtube_dlc as youtube_dl
|
|
|
import youtube_dl
|
|
|
import shutil
|
|
|
import sys
|
|
@@ -112,11 +113,17 @@ def addurl(url, user = "-unknown-"):
|
|
|
else:
|
|
|
#legge le info
|
|
|
with open(os.path.join("cache", id + ".json")) as infile:
|
|
|
- title = __normalizetext(json.load(infile)['title'])
|
|
|
+ j = json.load(infile)
|
|
|
+ title = normalizetext(j['title'])
|
|
|
+ track = normalizetext(j['track'])
|
|
|
+ artist = normalizetext(j['artist'])
|
|
|
+ album = normalizetext(j['album'])
|
|
|
filetemp = os.path.join("cache", id + ".m4a")
|
|
|
print ('id: %s' %(id))
|
|
|
print ('title: %s' %(title))
|
|
|
|
|
|
+
|
|
|
+
|
|
|
if not id:
|
|
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
|
try:
|
|
@@ -127,8 +134,11 @@ def addurl(url, user = "-unknown-"):
|
|
|
return ("Err: " + str(detail))
|
|
|
|
|
|
id = meta.get('id').strip()
|
|
|
- title = __normalizetext(meta.get('title'))
|
|
|
-
|
|
|
+ title = normalizetext(meta.get('title'))
|
|
|
+ track = normalizetext(meta.get('track'))
|
|
|
+ artist = normalizetext(meta.get('artist'))
|
|
|
+ album = normalizetext(meta.get('album'))
|
|
|
+
|
|
|
print ('id: %s' %(id))
|
|
|
print ('title: %s' %(title))
|
|
|
|
|
@@ -147,7 +157,7 @@ def addurl(url, user = "-unknown-"):
|
|
|
if not os.path.isfile(filetemp):
|
|
|
return("Err: file non scaricato")
|
|
|
|
|
|
- return(add(filetemp, user, title, id))
|
|
|
+ return(add(filetemp, user, title, id, track, artist, album))
|
|
|
|
|
|
|
|
|
def md5(fname):
|
|
@@ -157,12 +167,18 @@ def md5(fname):
|
|
|
hash_md5.update(chunk)
|
|
|
return hash_md5.hexdigest()
|
|
|
|
|
|
-def add(filetemp, user = "-unknown-", title = None, id = None):
|
|
|
+def add(filetemp, user = "-unknown-", title = None, id = None, track = None, artist = None, album = None):
|
|
|
if not id:
|
|
|
id = md5(filetemp)
|
|
|
if not title:
|
|
|
title = os.path.splitext(os.path.basename(filetemp))[0]
|
|
|
-
|
|
|
+ if not track:
|
|
|
+ track = ''
|
|
|
+ if not artist:
|
|
|
+ artist = ''
|
|
|
+ if not album:
|
|
|
+ album = ''
|
|
|
+
|
|
|
#se il file esiste gia' in playlist salto (potrebbe esserci, anche rinominato)
|
|
|
if glob("playlist/**/*|" + id + ".*"):
|
|
|
print ('--- File già presente ---')
|
|
@@ -170,10 +186,11 @@ def add(filetemp, user = "-unknown-", title = None, id = None):
|
|
|
|
|
|
os.makedirs("playlist/" + user, exist_ok=True)
|
|
|
#qui compone il nome del file
|
|
|
+ fnam = (artist + " - " + track).strip() + "|" + title + "|" + id + ".m4a"
|
|
|
if SHUFFLESONGS:
|
|
|
- fileout = str(random.randrange(10**6)).zfill(14) + "|" + title + "|" + id + ".m4a"
|
|
|
+ fileout = str(random.randrange(10**6)).zfill(14) + "|" + fnam
|
|
|
else:
|
|
|
- fileout = time.strftime("%Y%m%d%H%M%S") + "|" + title + "|" + id + ".m4a"
|
|
|
+ fileout = time.strftime("%Y%m%d%H%M%S") + "|" + fnam
|
|
|
fileout = os.path.join("playlist/" + user, fileout)
|
|
|
|
|
|
#se il file esiste gia' in archive prendo quello
|
|
@@ -203,7 +220,7 @@ def add(filetemp, user = "-unknown-", title = None, id = None):
|
|
|
|
|
|
|
|
|
|
|
|
-def __normalizetext(s):
|
|
|
+def normalizetext(s):
|
|
|
if s is None:
|
|
|
return None
|
|
|
else:
|
|
@@ -238,8 +255,13 @@ def listplaylist():
|
|
|
#print ("BASENAME: " + bn)
|
|
|
seq = seq + 1
|
|
|
dat = bn.split("|")[0]
|
|
|
- nam = bn.split("|")[1]
|
|
|
- cod = bn.split("|")[2]
|
|
|
+ if len(bn.split("|")) < 4:
|
|
|
+ nam = bn.split("|")[1]
|
|
|
+ cod = bn.split("|")[2]
|
|
|
+ else:
|
|
|
+ nam = bn.split("|")[2]
|
|
|
+ cod = bn.split("|")[3]
|
|
|
+
|
|
|
key = "-".join([str(seq).zfill(5), last, dat])
|
|
|
#print ("KEY: " + key)
|
|
|
|
|
@@ -264,8 +286,12 @@ def listfallback():
|
|
|
bn = os.path.splitext(os.path.basename(file))[0]
|
|
|
seq = seq + 1
|
|
|
dat = bn.split("|")[0]
|
|
|
- nam = bn.split("|")[1]
|
|
|
- cod = bn.split("|")[2]
|
|
|
+ if len(bn.split("|")) < 4:
|
|
|
+ nam = bn.split("|")[1]
|
|
|
+ cod = bn.split("|")[2]
|
|
|
+ else:
|
|
|
+ nam = bn.split("|")[2]
|
|
|
+ cod = bn.split("|")[3]
|
|
|
key = "-".join([str(seq).zfill(5), dat])
|
|
|
|
|
|
plsong = [key, file, "fallback", nam, cod]
|
|
@@ -500,7 +526,8 @@ def plaympd():
|
|
|
shutil.rmtree("mpd")
|
|
|
os.makedirs("mpd")
|
|
|
client.update()
|
|
|
-
|
|
|
+ while 'updating_db' in client.status():
|
|
|
+ pass
|
|
|
#aggiunge l'annuncio iniziale
|
|
|
#addstartannounce()
|
|
|
#resetta il lastannounce
|