From a77abffce117480343eb764a1d04431e17817db6 Mon Sep 17 00:00:00 2001 From: Jackson Taylor Date: Sun, 7 Aug 2022 00:12:05 -0400 Subject: Add retry logic for failed files You can pass a file now for all the retry links. Now that I think of it though, I should just make it a file/url parameter and then you can pass in either without the need for another flag. You could also just create your own playlist file I guess. --- jamos | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'jamos') diff --git a/jamos b/jamos index 15a3200..12cfd07 100755 --- a/jamos +++ b/jamos @@ -46,23 +46,36 @@ def get_all_files(directory): def get_command_line_options(): parser = argparse.ArgumentParser( description="Download songs from YouTube Music") + parser.add_argument("url", - metavar="url", + metavar="https://music.youtube.com/playlist?list=1234", + nargs='?', + default=None, type=str, - help="Playlist or Song URL to download.", - ) + help="Playlist or Song URL to download.") + parser.add_argument("-c", "--cookies", metavar="cookiefile.txt", type=str, help="Cookie file to use.") + parser.add_argument("-o", "--output", metavar="output_directory", type=str, help="Output directory to use") - return parser.parse_args() + parser.add_argument("-r", + "--retryFile", + metavar="jamos_failed_urls.txt", + default=None, + type=str, + help="Output directory to use") + + args = parser.parse_args() + + return args # TODO: switch command line args to argparse @@ -191,19 +204,30 @@ def save_urls_from_playlist_to_file(filename, urls): if __name__ == "__main__": args = get_command_line_options() - # Get the playlist url from the command line - playlist_url = args.url + if args.retryFile and args.url: + print("Cannot have url and retry flag!") + sys.exit(1) - music_directory = args.output or "~/Music" - cookies = args.cookies or "~/cookies.txt" + music_directory = args.output or os.path.join(os.path.expanduser("~"), + "Music") + cookies = args.cookies or os.path.join(os.path.expanduser("~"), + "cookies.txt") # From some testing, if your playlist is public, you don't have to use a # cookie file. Youtube-dl doesn't break or throw if the file doesn't exist. ytdl = create_downloader(music_directory, cookies) - print("Downloading urls...", end="") - urls = get_video_urls_in_playlist(playlist_url, ytdl) - print("Done.") + urls = [] + + if args.url: + playlist_url = args.url + + print("Downloading urls...", end="") + urls = get_video_urls_in_playlist(playlist_url, ytdl) + print("Done.") + elif args.retryFile: + with open(args.retryFile) as retry_file: + urls = retry_file.read().splitlines() failed_urls = [] for url in urls: -- cgit v1.2.3