From cffdebb997516da4790594fac4402b13ba0fb5b3 Mon Sep 17 00:00:00 2001 From: Jackson Taylor Date: Wed, 10 Nov 2021 14:03:24 -0500 Subject: Use default paths if metadata isn't available --- jamos | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'jamos') diff --git a/jamos b/jamos index 309ad6c..4435653 100755 --- a/jamos +++ b/jamos @@ -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__": -- cgit v1.2.3