Browse Source

AddUrl fixed

itec78 3 years ago
parent
commit
68fb737f9a
2 changed files with 31 additions and 23 deletions
  1. 24 20
      playlistalo.py
  2. 7 3
      trimaudio.sh

+ 24 - 20
playlistalo.py

@@ -106,13 +106,16 @@ def addurl(url, user = "-unknown-"):
     #trova l'id dall'url
     id = video_id(url)
     if id:
-        #cerca se ho gia' il json
-        if not glob(os.path.join("cache", id + ".json")):
+        #cerca se ho gia' il json e il file
+        if not (glob(os.path.join("cache", id + ".json")) and glob(os.path.join("cache", id + ".m4a"))):
             id = None
         else:
             #legge le info
             with open(os.path.join("cache", id + ".json")) as infile:
                 title = __normalizetext(json.load(infile)['title'])
+            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:
@@ -123,25 +126,26 @@ def addurl(url, user = "-unknown-"):
                 print(str(detail))
                 return ("Err: " + str(detail))
 
-            id = meta.get('id').strip()
-            title = __normalizetext(meta.get('title'))
-            #scrivo il json
-            with open(os.path.join("cache", id + ".json"), 'w') as outfile:
-                json.dump(meta, outfile, indent=4)
-            
-    print ('id:    %s' %(id))
-    print ('title: %s' %(title))
-
-    #ho letto le info, ora controllo se il file esiste altrimenti lo scarico
-    #miglioria: controllare se upload_date e' uguale a quella del json gia' esistente
-    filetemp = os.path.join("cache", id + ".m4a")
-    if not glob(filetemp):
-        print ('--- Scarico ---')
-        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
+        id = meta.get('id').strip()
+        title = __normalizetext(meta.get('title'))
+                
+        print ('id:    %s' %(id))
+        print ('title: %s' %(title))
+
+        #scrivo  il json
+        with open(os.path.join("cache", id + ".json"), 'w') as outfile:
+            json.dump(meta, outfile, indent=4)
+
+        #ho letto le info, ora controllo se il file esiste altrimenti lo scarico
+        #miglioria: controllare se upload_date e' uguale a quella del json gia' esistente
+        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
-    
-    if not os.path.isfile(filetemp):
-        return("Err: file non scaricato")
+        
+        if not os.path.isfile(filetemp):
+            return("Err: file non scaricato")
 
     return(add(filetemp, user, title, id))
 

+ 7 - 3
trimaudio.sh

@@ -12,6 +12,7 @@ temp3=$(mktemp /tmp/playlistalo.XXXXXXXX.wav)
 tempx=$(mktemp /tmp/playlistalo.XXXXXXXX.m4a)
 
 #step 1 rimuove il silenzio
+echo "Rimuovo il silenzio"
 ffmpeg -i "$1" -to $(($secmax + $sectol + 30)) -af "silenceremove=start_periods=1:start_duration=1:start_threshold=-60dB:detection=peak,aformat=dblp,areverse,silenceremove=start_periods=1:start_duration=1:start_threshold=-60dB:detection=peak,aformat=dblp,areverse" -v quiet -y $temp1
 
 
@@ -20,7 +21,8 @@ len=$(ffprobe -show_entries stream=duration -of default=noprint_wrappers=1:nokey
 len=${len%.*}
 
 if [ $len -gt $(($secmax + $sectol)) ];
-then 
+then
+    echo "Tronco e sfumo"
     ffmpeg -i $temp1 -to $secmax -af "afade=t=out:st=$(($secmax - $secfad)):d=$secfad" -v quiet -y $temp2
     rm $temp1
     mv $temp2 $temp3
@@ -29,7 +31,9 @@ else
 fi
 
 #step3 normalizza
-#ffmpeg -i $temp3 -af loudnorm $tempx
-ffmpeg-normalize -q -f $temp3 -c:a aac -o $tempx
+echo "Normalizzo"
+#ffmpeg-normalize -q -f $temp3 -c:a aac -o $tempx
+ffmpeg -i $temp3 -af loudnorm -v quiet -y $tempx
+
 rm $temp3
 mv $tempx "$2"