@@ -21,9 +21,11 @@ def get_min_bitrate(files):
2121 min_k = int (min (bitrates ) / 1000 )
2222 return f"{ min_k } k"
2323
24- def process_audio_optimized ():
24+ def process_audio_optimized (directory = '.' ):
2525 output_filename = "risultato_ottimizzato.mp3"
26- files = sorted ([f for f in os .listdir ('.' ) if f .endswith ('.mp3' ) and f != output_filename ])
26+ output_path = os .path .join (directory , output_filename )
27+ files = sorted ([f for f in os .listdir (directory ) if f .endswith ('.mp3' ) and f != output_filename ])
28+ files = [os .path .join (directory , f ) for f in files ]
2729
2830 if not files :
2931 print ("Nessun file MP3 trovato!" )
@@ -54,18 +56,33 @@ def process_audio_optimized():
5456 # 3. Esportazione finale
5557 print (f"Esportazione in corso ({ target_bitrate } , CBR)..." )
5658 combined .export (
57- output_filename ,
59+ output_path ,
5860 format = "mp3" ,
5961 bitrate = target_bitrate ,
6062 parameters = ["-write_xing" , "0" ] # Forza CBR puro per compatibilità timer
6163 )
6264
6365 print ("-" * 30 )
6466 print (f"COMPLETATO!" )
65- print (f"File: { output_filename } " )
67+ print (f"File: { output_path } " )
6668 print (f"Peso ottimizzato con bitrate: { target_bitrate } " )
6769 print (f"Durata totale: { len (combined ) / 1000 } secondi." )
6870 print ("-" * 30 )
6971
7072if __name__ == "__main__" :
71- process_audio_optimized ()
73+ import sys
74+ if len (sys .argv ) > 1 :
75+ dir_path = sys .argv [1 ]
76+ if not os .path .isdir (dir_path ):
77+ print (f"Errore: '{ dir_path } ' non è una directory valida" )
78+ sys .exit (1 )
79+ process_audio_optimized (dir_path )
80+ else :
81+ print ("Inserisci il percorso della cartella con i file MP3:" )
82+ dir_path = input ("> " ).strip ()
83+ if not dir_path :
84+ dir_path = '.'
85+ if not os .path .isdir (dir_path ):
86+ print (f"Errore: '{ dir_path } ' non è una directory valida" )
87+ sys .exit (1 )
88+ process_audio_optimized (dir_path )
0 commit comments