From 71f924b7ef0da11cb366bbe950c5140d0d7362ce Mon Sep 17 00:00:00 2001 From: Jackson Taylor Date: Mon, 15 Nov 2021 16:28:46 -0500 Subject: Handle invalid path values When there are special characters like / and & it can cause jamos to break when renaming files. To handle this for now, I have just replaced these characters with no character. --- jamos | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'jamos') diff --git a/jamos b/jamos index b3b04c7..9b9c150 100755 --- a/jamos +++ b/jamos @@ -108,7 +108,7 @@ def move_file(file, metadata): album = metadata['album'].replace(' ', '_').lower() if ('title' in metadata.keys()) and (metadata['title'] is not None): - title = metadata['title'].replace(' ', '_').lower() + title = metadata['title'].replace(' ', '_').replace('/', '').lower() final_directory = os.path.join( MUSIC_DIRECTORY, @@ -125,10 +125,34 @@ def move_file(file, metadata): def write_metadata_to_song_file(file, metadata): f = music_tag.load_file(file) - f['name'] = metadata['title'] - f['artist'] = metadata['artist'] - f['album'] = metadata['album'] - f['year'] = format_youtube_date(metadata['release_date']) + artist = 'unknownartist' + album = 'unknownalbum' + title = 'unknownsong' + year = 9999 + + if ('artist' in metadata.keys()) and (metadata['artist'] is not None): + if len(metadata['artist'].split(',')) > 1: + # If there are multiple artists, pick the first one + # NOTE: This may break if the artist has a comma in their name + artist = metadata['artist'].split(',')[0].replace(' ', '_').lower() + else: + artist = metadata['artist'].replace(' ', '_').lower() + + artist = artist.replace('&', 'and') + + 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() + + if ('release_date' in metadata.keys()): + year = format_youtube_date(metadata['release_date']) + + f['name'] = title + f['artist'] = artist + f['album'] = album + f['year'] = year f.save() -- cgit v1.2.3