diff options
author | Jackson Taylor <jackson@jacksontaylor.xyz> | 2021-11-09 21:18:26 -0500 |
---|---|---|
committer | Jackson Taylor <jackson@jacksontaylor.xyz> | 2022-04-05 16:51:55 -0400 |
commit | c383aa2c3ff3cf2f0de69937023c6cecc8bdc1f3 (patch) | |
tree | 0180d00830d9d4027205bc9ce9fd66e39a72bb9c /jamos | |
parent | 2a0d5283b1de4e4a2a77e672bb0121923db9568f (diff) |
Move files once done tagging
Diffstat (limited to 'jamos')
-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) + |