diff options
Diffstat (limited to 'jamos')
-rwxr-xr-x | jamos | 46 |
1 files changed, 35 insertions, 11 deletions
@@ -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: |