summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Taylor <jackson@jacksontaylor.xyz>2021-11-15 16:28:46 -0500
committerJackson Taylor <jackson@jacksontaylor.xyz>2022-04-05 16:52:10 -0400
commit71f924b7ef0da11cb366bbe950c5140d0d7362ce (patch)
treeb14832357817b8075551094f300ca79dec437802
parent41b5b868a748375648f4d7eb1441f0cb7a817790 (diff)
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.
-rwxr-xr-xjamos34
1 files changed, 29 insertions, 5 deletions
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()