diff options
author | Jackson Taylor <jackson@jacksontaylor.xyz> | 2021-11-10 14:03:24 -0500 |
---|---|---|
committer | Jackson Taylor <jackson@jacksontaylor.xyz> | 2022-04-05 16:52:00 -0400 |
commit | cffdebb997516da4790594fac4402b13ba0fb5b3 (patch) | |
tree | ee5d6241c1d8ef06beef49f1b830c3da7f490259 | |
parent | 5f36cecd2d8b058939a3a5d8025d0679d494c1bf (diff) |
Use default paths if metadata isn't available
-rwxr-xr-x | jamos | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -121,19 +121,29 @@ def get_directories(): def move_file(file, metadata): - p = os.path.join( + artist = 'unknownartist' + album = 'unknownalbum' + title = 'unknownsong' + + if ('artist' in metadata.keys()) and (metadata['artist'] is not None): + artist = metadata['artist'].replace(' ', '_').lower() + + if ('album' in metadata.keys()) and (metadata['album'] is not None): + album = metadata['album'].replace(' ', '_').lower() + + if ('title' in metadata.keys()) and (metadata['title'] is not None): + title = metadata['title'].replace(' ', '_').lower() + + final_directory = os.path.join( MUSIC_DIRECTORY, - metadata['artist'].replace(' ', '_').lower(), - metadata['album'].replace(' ', '_').lower()) + artist, + album) - Path(p).mkdir(parents=True, exist_ok=True) + Path(final_directory).mkdir(parents=True, exist_ok=True) os.rename( file, - os.path.join( - p, - metadata['artist'].replace(' ', '_').lower() + - '_' + metadata['title'].replace(' ', '_').lower() + '.mp3')) + os.path.join(final_directory, artist + '_' + title + '.mp3')) if __name__ == "__main__": |