diff options
-rwxr-xr-x | jamos | 43 |
1 files changed, 26 insertions, 17 deletions
@@ -99,19 +99,16 @@ def complete(text, state): state -= 1 -def get_all_files(): - files = os.listdir() - global FILES - global DIRECTORIES +def get_all_files(directory): + things = glob.glob(os.path.join(directory, '*.mp3')) - for f in files: - if os.path.isfile(f): - FILES.append(f) - elif os.path.isdir(f): - DIRECTORIES.append(f) - else: - raise Exception("File wasn't a file or directory! " + f) - FILES.sort() + files = [] + + for thing in things: + if os.path.isfile(thing): + files.append(thing) + + return files def get_directories(): @@ -123,15 +120,27 @@ def get_directories(): DIRECTORIES.append(f) -def move_file(d, f): - # print("directory " + d + " file: " + f) - print(d + "/" + f) - os.rename(f, (d + "/" + f)) +def move_file(file, metadata): + p = os.path.join(MUSIC_DIRECTORY, metadata['artist'].replace(' ', '_').lower(), metadata['album'].replace(' ', '_').lower()) + Path(p).mkdir( parents=True, exist_ok=True ) + + os.rename(file, os.path.join(p, metadata['artist'].replace(' ', '_').lower() + '_' + metadata['title'].replace(' ', '_').lower() + '.mp3')) + if __name__ == "__main__": - # Get the playlist url from youtube music + # Get the playlist url from the command line playlist_url = get_playlist_url() + # Download the songs download_song(playlist_url) + files = get_all_files(MUSIC_DIRECTORY) + + for f in files: + json_data = None + with open(f.replace('.mp3', '.info.json')) as json_file: + json_data = json.load(json_file) + write_metadata_to_song_file(f, json_data) + move_file(f, json_data) + |