count_len = len(str(index)) new_index = '0'*(6-count_len) + str(index) old_index = file_to_rename.rpartition('\\')[2][:6] new_filename = file_to_rename[:].replace(old_index, new_index) os.rename(file_to_rename, new_filename) def delete_dir(self, dir_): for the_file in os.listdir(dir_): file_path = os.path.join(dir_, the_file) if os.path.isfile(file_path): os.unlink(file_path) if __name__ == "__main__": app_data = os.getenv('LOCALAPPDATA') playlist_db = Playlists(app_data + '\\playlists_db\\') playlist_db.create_db() if sys.argv[1] == 'list': playlists = playlist_db.get_playlists() for key in playlists: print (playlists[key][0]) elif sys.argv[1] == 'add': playlist_db.add_playlist(sys.argv[2], sys.argv[3]) elif sys.argv[1] == 'remove': playlist_db.remove_playlist(sys.argv[2]) else: url = playlist_db.get_playlist_url(sys.argv[1]) directory = sys.argv[2] p = Downloader(url,directory) if len(sys.argv) > 4: if sys.argv[4] == '--del-all':
print ('Transcoding audio files. Do not interrupt!') #sys.stdout.write("\r" + ' 0.00%' + "\r") for input_song, output_song in in_and_out_files: sys.stdout.flush() print (self.detect_audio_level(input_song)) #os.system('ffmpeg -i "' + input_song+'" "' + output_song+'"') #sys.stdout.write("\r" + ' {:.2%}'.format(current/len(in_and_out_files)) + "\r") current += 1 ################################################# # DEL FILES!!! # if delete_original_files: # os.system('del "'+input_song+'"') if __name__ == "__main__": playlist_db = Playlists('C:\\Users\\User\\AppData\\Local\\playlists_db\\') playlist_db.create_db() print ('Created DB') url = playlist_db.get_playlist_url(sys.argv[1]) print ('Url: '+url) directory = sys.argv[2] print ('Dir: '+sys.argv[2]) p = Downloader(url,directory) #p.download_playlist() p.delete_incomplete_files(directory) print ('Deleted incomplete') if len(sys.argv) > 3: print ('Formating files') file_format = sys.argv[3] p.format_files(directory, file_format, True)