summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Taylor <jackson@jacksontaylor.xyz>2022-08-06 22:20:46 -0400
committerJackson Taylor <jackson@jacksontaylor.xyz>2022-08-06 22:20:46 -0400
commit4eac21b73c78c6bdfd1be28da4f23d2aae9dd798 (patch)
tree7c379efcc749bb442af16bbfec98799da5b118ca
parent71bcf9ffd22d4afd83b2d626bac76db30d8a7073 (diff)
Handle more special characters
Handle a unicode right quotation mark. Handle stupid /s in file names that cause you to debug for an hour.
-rwxr-xr-xjamos48
1 files changed, 35 insertions, 13 deletions
diff --git a/jamos b/jamos
index 9c666e2..a7d8051 100755
--- a/jamos
+++ b/jamos
@@ -9,6 +9,8 @@ from pathlib import Path
import sys
import youtube_dl
+DEBUG = False
+
def cleanup_metadata_files(music_directory):
files = glob.glob(os.path.join(music_directory, '*.json'))
@@ -80,14 +82,14 @@ def get_video_urls_in_playlist(playlist_url, ytdl):
def move_file(file, metadata, output_directory):
artist = metadata['artist'].replace(
- '-', ' ').replace(' ', '_').replace("'", "").replace(
- "&", "and").lower()
+ '-', ' ').replace("/", " ").replace(' ', '_').replace("'", "").replace(
+ "&", "and").replace(chr(8217), "").lower()
album = metadata['album'].replace(
- '-', ' ').replace(' ', '_').replace("'", "").replace(
- "&", "and").lower()
+ '-', ' ').replace("/", " ").replace(' ', '_').replace("'", "").replace(
+ "&", "and").replace(chr(8217), "").lower()
title = metadata['title'].replace(
- '-', ' ').replace(' ', '_').replace("'", "").replace(
- "&", "and").lower()
+ '-', ' ').replace("/", " ").replace(' ', '_').replace("'", "").replace(
+ "&", "and").replace(chr(8217), "").lower()
final_directory = os.path.join(
output_directory,
@@ -167,7 +169,8 @@ def create_downloader(music_directory, cookies):
},
{'key': 'FFmpegMetadata'},
],
- 'writeinfojson': True
+ 'writeinfojson': True,
+ 'quiet': not DEBUG
}
return youtube_dl.YoutubeDL(audio_options)
@@ -197,33 +200,52 @@ if __name__ == "__main__":
# cookie file. Youtube-dl doesn't break or throw if the file doesn't exist.
ytdl = create_downloader(music_directory, cookies)
- # TODO: Save urls to file so we can start in the
- # middle of the playlist if needed
+ print("Downloading urls...", end="")
urls = get_video_urls_in_playlist(playlist_url, ytdl)
+ print("Done.")
- save_urls_from_playlist_to_file(os.path.join(music_directory,
- "jamos_urls.txt"), urls)
-
+ failed_urls = []
for url in urls:
try:
+ print("Downloading: {}...".format(url), end='')
ytdl.extract_info(url, download=True)
+ print("Done.")
except Exception as ex:
- # TODO: Handle this better
print(ex)
+ print("Could not download: {}".format((url)))
+ failed_urls.append(url)
+
+ try:
+ if len(failed_urls) > 1:
+ print("Saving failed urls to txt file.")
+ save_urls_from_playlist_to_file(
+ os.path.join(music_directory, "jamos_failed_urls.txt"),
+ failed_urls)
+ except Exception as ex:
+ print(ex)
+ print("Saving failed urls to file failed! Printing failed urls:")
+ for url in failed_urls:
+ print(url)
files = get_all_files(music_directory)
counter = 1
for f in files:
try:
+ print("Adding metadata to {} ...".format(f), end="")
with open(f.replace('.mp3', '.info.json')) as json_file:
json_data = json.load(json_file)
metadata = get_song_metadata_from_json(json_data, counter)
write_metadata_to_song_file(f, metadata)
+ print("Done".format(f))
+ print("Moving file...", end="")
move_file(f, metadata, music_directory)
+ print("Done", end="")
counter += 1
except Exception as e:
# just gonna print this and move on to the next file.
print(e)
+ print("Cleaning up JSON files...", end='')
cleanup_metadata_files(music_directory)
+ print("Done.")