diff --git a/README.md b/README.md index bd10c5e..81d54a4 100644 --- a/README.md +++ b/README.md @@ -87,27 +87,33 @@ To download a course included in a subscription plan that you did not purchase i # Advanced Usage ``` -usage: udemy_downloader [-h] -c COURSE_URL [-b BEARER_TOKEN] [-q QUALITY] [-l LANG] [-cd CONCURRENT_CONNECTIONS] [--skip-lectures] [--download-assets] [--download-captions] [--keep-vtt] [--skip-hls] [--info] - [--use-h265] [--h265-crf H265_CRF] [--ffmpeg-preset FFMPEG_PRESET] [--ffmpeg-framerate FFMPEG_FRAMERATE] [--h265-encoder H265_ENCODER] [-v] +usage: udemy_downloader [-h] -c COURSE_URL [-b BEARER_TOKEN] [-q QUALITY] [-l LANG] [-cd CONCURRENT_CONNECTIONS] + [--skip-lectures] [--download-assets] [--download-captions] [--keep-vtt] [--skip-hls] [--info] + [--use-h265] [--h265-crf H265_CRF] [--ffmpeg-preset FFMPEG_PRESET] + [--ffmpeg-framerate FFMPEG_FRAMERATE] [--h265-encoder H265_ENCODER] [--disable-ipv6] [-v] Udemy Downloader -optional arguments: +options: -h, --help show this help message and exit -c COURSE_URL, --course-url COURSE_URL The URL of the course to download -b BEARER_TOKEN, --bearer BEARER_TOKEN The Bearer token to use -q QUALITY, --quality QUALITY - Download specific video quality. If the requested quality isn't available, the closest quality will be used. If not specified, the best quality will be downloaded for each lecture - -l LANG, --lang LANG The language to download for captions, specify 'all' to download all captions (Default is 'en') + Download specific video quality. If the requested quality isn't available, the closest quality + will be used. If not specified, the best quality will be downloaded for each lecture + -l LANG, --lang LANG The language to download for captions, specify 'all' to download all captions (Default is + 'en') -cd CONCURRENT_CONNECTIONS, --concurrent-connections CONCURRENT_CONNECTIONS - The number of maximum concurrent connections per download for segments (HLS and DASH, must be a number 1-30) + The number of maximum concurrent connections per download for segments (HLS and DASH, must be + a number 1-30) --skip-lectures If specified, lectures won't be downloaded --download-assets If specified, lecture assets will be downloaded --download-captions If specified, captions will be downloaded --keep-vtt If specified, .vtt files won't be removed - --skip-hls If specified, hls streams will be skipped (faster fetching) (hls streams usually contain 1080p quality for non-drm lectures) + --skip-hls If specified, hls streams will be skipped (faster fetching) (hls streams usually contain 1080p + quality for non-drm lectures) --info If specified, only course information will be printed, nothing will be downloaded --use-h265 If specified, videos will be encoded with the H.265 codec --h265-crf H265_CRF Set a custom CRF value for H.265 encoding. FFMPEG default is 28 @@ -116,7 +122,9 @@ optional arguments: --ffmpeg-framerate FFMPEG_FRAMERATE Changes the FPS used for encoding. FFMPEG default is 30 --h265-encoder H265_ENCODER - Changes the HEVC encder that is used. Default is copy when not using h265, otherwise the default is libx265 + Changes the HEVC encder that is used. Default is copy when not using h265, otherwise the + default is libx265 + --disable-ipv6 If specified, ipv6 will be disabled in aria2 -v, --version show program's version number and exit ``` @@ -163,6 +171,16 @@ optional arguments: - Encode in H.265 with a custom framerate: - `python udemy_downloader -c --use-h265 --ffmpeg-framerate 24` +If you encounter errors while downloading such as + +`errorCode=1 Network problem has occurred. cause:Unknown socket error 10051 (0x2743)` + +or + +`errorCode=1 Network problem has occurred. cause:A socket operation was attempted to an unreachable network.` + +Then try disabling ipv6 in aria2 using the `--disable-ipv6` option + # Credits - https://github.com/Jayapraveen/Drm-Dash-stream-downloader - For the original code which this is based on diff --git a/udemy_downloader/UdemyDownloader.py b/udemy_downloader/UdemyDownloader.py index bc4a1a6..1b96706 100644 --- a/udemy_downloader/UdemyDownloader.py +++ b/udemy_downloader/UdemyDownloader.py @@ -84,6 +84,7 @@ ffmpeg_preset = "medium" h265_encoder = "copy" ffmpeg_framerate = "30" cookies = "" +disable_ipv6 = False def download_segments(url, format_id, video_title, output_path, lecture_file_name, chapter_dir): @@ -94,12 +95,17 @@ def download_segments(url, format_id, video_title, output_path, lecture_file_nam video_filepath_dec = file_name + ".decrypted.mp4" audio_filepath_dec = file_name + ".decrypted.m4a" print("> Downloading Lecture Tracks...") - ret_code = subprocess.Popen([ + args = [ "yt-dlp", "--force-generic-extractor", "--allow-unplayable-formats", "--concurrent-fragments", f"{concurrent_connections}", "--downloader", "aria2c", "--fixup", "never", "-k", "-o", f"{file_name}.encrypted.%(ext)s", - "-f", format_id, f"{url}" - ]).wait() + "-f", format_id + ] + if disable_ipv6: + args.append("--downloader-args") + args.append("aria2c:\"--disable-ipv6\"") + args.append(f"{url}") + ret_code = subprocess.Popen(args).wait() print("> Lecture Tracks Downloaded") print("Return code: " + str(ret_code)) @@ -199,10 +205,13 @@ def download_aria(url, file_dir, filename): @author Puyodead1 """ print(" > Downloading File...") - ret_code = subprocess.Popen([ + args = [ "aria2c", url, "-o", filename, "-d", file_dir, "-j16", "-s20", "-x16", "-c", "--auto-file-renaming=false", "--summary-interval=0" - ]).wait() + ] + if disable_ipv6: + args.append("--disable-ipv6") + ret_code = subprocess.Popen(args).wait() print(" > File Downloaded") print("Return code: " + str(ret_code)) @@ -360,13 +369,17 @@ def process_lecture(lecture, lecture_path, lecture_file_name, chapter_dir): if source_type == "hls": temp_filepath = lecture_path.replace( ".mp4", ".%(ext)s") - command = [ + args = [ "yt-dlp", "--force-generic-extractor", "--concurrent-fragments", f"{concurrent_connections}", "--downloader", - "aria2c", "-o", f"{temp_filepath}", f"{url}" + "aria2c", "-o", f"{temp_filepath}" ] - ret_code = subprocess.Popen(command).wait() + if disable_ipv6: + args.append("--downloader-args") + args.append("aria2c:\"--disable-ipv6\"") + args.append(f"{url}") + ret_code = subprocess.Popen(args).wait() if ret_code == 0: print(" > HLS Download success") @@ -882,6 +895,12 @@ def setup_parser(): default="libx265", help="Changes the HEVC encder that is used. Default is copy when not using h265, otherwise the default is libx265", ) + parser.add_argument( + "--disable-ipv6", + dest="disable_ipv6", + action="store_true", + help="If specified, ipv6 will be disabled in aria2", + ) parser.add_argument( "--iknowwhatimdoing", dest="iknowwhatimdoing", @@ -905,7 +924,7 @@ def setup_parser(): def process_args(args): - global course_url, bearer_token, dl_assets, dl_captions, caption_locale, skip_lectures, quality, keep_vtt, skip_hls, print_info, load_from_file, save_to_file, concurrent_connections, use_h265, h265_crf, ffmpeg_preset, iknowwhatimdoing, h265_encoder, ffmpeg_framerate + global course_url, bearer_token, dl_assets, dl_captions, caption_locale, skip_lectures, quality, keep_vtt, skip_hls, print_info, load_from_file, save_to_file, concurrent_connections, use_h265, h265_crf, ffmpeg_preset, iknowwhatimdoing, h265_encoder, ffmpeg_framerate, disable_ipv6 course_url = args.course_url if args.download_assets: @@ -956,6 +975,8 @@ def process_args(args): if args.ffmpeg_preset: ffmpeg_preset = args.ffmpeg_preset print("> Selected HEVC Encoder Preset: " + ffmpeg_preset) + if args.disable_ipv6: + disable_ipv6 = args.disable_ipv6 if args.load_from_file: print( "> 'load_from_file' was specified, data will be loaded from json files instead of fetched"