summaryrefslogtreecommitdiff
path: root/jamos
diff options
context:
space:
mode:
authorJackson Taylor <jackson@jacksontaylor.xyz>2022-08-07 09:17:34 -0400
committerJackson Taylor <jackson@jacksontaylor.xyz>2022-08-07 09:18:00 -0400
commitf20d63482029c02890239f70eb7057f696192021 (patch)
treec37ff2886e00ca8d0c59f7828a3a476545e0da0b /jamos
parenta77abffce117480343eb764a1d04431e17817db6 (diff)
Handle special characters in file names
Do this with a function to remove all of the special characters I've found so far.
Diffstat (limited to 'jamos')
-rwxr-xr-xjamos35
1 files changed, 25 insertions, 10 deletions
diff --git a/jamos b/jamos
index 12cfd07..bca6f0c 100755
--- a/jamos
+++ b/jamos
@@ -94,16 +94,32 @@ def get_video_urls_in_playlist(playlist_url, ytdl):
return urls
+def remove_special_characters_for_filename(filename):
+ special_chars = [
+ ['-', ' '],
+ ['(', ''],
+ [')', ''],
+ ['/', ' '],
+ ['/', ' '],
+ [' ', '_'],
+ ["'", ''],
+ ["&", 'and'],
+ [chr(8217), ''],
+ ['$', 's'],
+ ['.', '']
+ ]
+ new_name = filename
+
+ for char_set in special_chars:
+ new_name = new_name.replace(char_set[0], char_set[1])
+
+ return new_name.lower()
+
+
def move_file(file, metadata, output_directory):
- artist = metadata['artist'].replace(
- '-', ' ').replace("/", " ").replace(' ', '_').replace("'", "").replace(
- "&", "and").replace(chr(8217), "").lower()
- album = metadata['album'].replace(
- '-', ' ').replace("/", " ").replace(' ', '_').replace("'", "").replace(
- "&", "and").replace(chr(8217), "").lower()
- title = metadata['title'].replace(
- '-', ' ').replace("/", " ").replace(' ', '_').replace("'", "").replace(
- "&", "and").replace(chr(8217), "").lower()
+ artist = remove_special_characters_for_filename(metadata['artist'])
+ album = remove_special_characters_for_filename(metadata['album'])
+ title = remove_special_characters_for_filename(metadata['title'])
final_directory = os.path.join(
output_directory,
@@ -112,7 +128,6 @@ def move_file(file, metadata, output_directory):
Path(final_directory).mkdir(parents=True, exist_ok=True)
- # TODO: Include album title in filename
# TODO: Research converting to mp3 instead of just naming it such.
# TODO: Research better file formats over mp3?
os.rename(