Browse Source

Fixed archive

itec 4 years ago
parent
commit
39e7489d34
1 changed files with 11 additions and 5 deletions
  1. 11 5
      playlistalo.py

+ 11 - 5
playlistalo.py

@@ -24,15 +24,13 @@ scriptpath = os.path.dirname(os.path.realpath(__file__))
 
 #Crea le cartelle
 os.makedirs("playlist", exist_ok=True)
-os.makedirs("cache", exist_ok=True)
 os.makedirs("fallback", exist_ok=True)
-os.makedirs("archive", exist_ok=True)
 
 #Scrivi la prima configurazione
 configfile = 'playlistalo.conf'
 if not os.path.exists(configfile):
     config = configparser.ConfigParser()
-    config['playlistalo'] = {'ShuffleUsers': False, 'ShuffleSongs': False, 'ShuffleFallback': False, 'Telegram_token': "", 'Mastodon_token': "", 'Mastodon_url': ""}
+    config['playlistalo'] = {'ShuffleUsers': False, 'ShuffleSongs': False, 'ShuffleFallback': False, 'Archive':True, 'Telegram_token': "", 'Mastodon_token': "", 'Mastodon_url': ""}
     with open(configfile, 'w') as f:
         config.write(f)
 
@@ -43,6 +41,7 @@ playlistaloconf = config['playlistalo']
 SHUFFLEUSERS = playlistaloconf.getboolean('ShuffleUsers')
 SHUFFLESONGS = playlistaloconf.getboolean('ShuffleSongs')
 SHUFFLEFALLBACK = playlistaloconf.getboolean('ShuffleFallback')
+ARCHIVE = playlistaloconf.getboolean('Archive')
 TELEGRAM_TOKEN = playlistaloconf.get('Telegram_token')
 MASTODON_TOKEN = playlistaloconf.get('Mastodon_token')
 MASTODON_URL = playlistaloconf.get('Mastodon_url')
@@ -54,6 +53,8 @@ MASTODON_URL = playlistaloconf.get('Mastodon_url')
 def addurl(url, user = "-unknown-"):
     #print ('--- Inizio ---')
 
+    os.makedirs("cache", exist_ok=True)
+
     ydl_opts = {
         'format': 'bestaudio[ext=m4a]',       
         'outtmpl': 'cache/%(id)s.m4a',        
@@ -133,6 +134,11 @@ def add(filetemp, user = "-unknown-", title = None, id = None):
     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)
         
@@ -220,7 +226,7 @@ def playloop():
     while True:
         plt = listtot(1)
         if plt:
-            song = plt[0]
+            song = plt[0][0]
             print(song)
             #qui fa play
             subprocess.call(["mplayer", "-nolirc", "-msglevel", "all=0:statusline=5", song])
@@ -345,7 +351,7 @@ def listtot(res = sys.maxsize):
 
 
 def consume(song):
-    if os.path.split(song)[0] == "playlist":
+    if song.split("/")[0] == "playlist":
         os.remove(song)
         if not [x for x in glob(os.path.dirname(song) + "/*") if not os.path.basename(x) == "last"]:
             shutil.rmtree(os.path.dirname(song))