From c383aa2c3ff3cf2f0de69937023c6cecc8bdc1f3 Mon Sep 17 00:00:00 2001 From: Jackson Taylor Date: Tue, 9 Nov 2021 21:18:26 -0500 Subject: Move files once done tagging --- jamos | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/jamos b/jamos index 573dc1d..7e80212 100755 --- a/jamos +++ b/jamos @@ -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) + -- cgit v1.2.3