mirror of
https://cdm-project.com/Download-Tools/udemy-downloader.git
synced 2025-04-30 05:04:27 +02:00
Use aria2c for asset downloading and non-drm lectures
This commit is contained in:
parent
05c6c84d55
commit
d20f15fb6a
43
main.py
43
main.py
@ -878,6 +878,20 @@ def download(url, path, filename):
|
|||||||
return file_size
|
return file_size
|
||||||
|
|
||||||
|
|
||||||
|
def download_aria(url, file_dir, filename):
|
||||||
|
"""
|
||||||
|
@author Puyodead1
|
||||||
|
"""
|
||||||
|
print("> Downloading File...")
|
||||||
|
ret_code = subprocess.Popen([
|
||||||
|
"aria2c", url, "-o", filename, "-d", file_dir, "-j16", "-s20", "-x16",
|
||||||
|
"-c", "--auto-file-renaming=false", "--summary-interval=0"
|
||||||
|
]).wait()
|
||||||
|
print("> File Downloaded")
|
||||||
|
|
||||||
|
print("Return code: " + str(ret_code))
|
||||||
|
|
||||||
|
|
||||||
def process_caption(caption, lecture_title, lecture_dir, keep_vtt, tries=0):
|
def process_caption(caption, lecture_title, lecture_dir, keep_vtt, tries=0):
|
||||||
filename = f"%s_%s.%s" % (sanitize(lecture_title), caption.get("language"),
|
filename = f"%s_%s.%s" % (sanitize(lecture_title), caption.get("language"),
|
||||||
caption.get("extension"))
|
caption.get("extension"))
|
||||||
@ -890,7 +904,7 @@ def process_caption(caption, lecture_title, lecture_dir, keep_vtt, tries=0):
|
|||||||
else:
|
else:
|
||||||
print(f"> Downloading caption: '%s'" % filename)
|
print(f"> Downloading caption: '%s'" % filename)
|
||||||
try:
|
try:
|
||||||
download(caption.get("download_url"), filepath, filename)
|
download_aria(caption.get("download_url"), lecture_dir, filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if tries >= 3:
|
if tries >= 3:
|
||||||
print(
|
print(
|
||||||
@ -914,19 +928,9 @@ def process_caption(caption, lecture_title, lecture_dir, keep_vtt, tries=0):
|
|||||||
print(f"> Error converting caption: {e}")
|
print(f"> Error converting caption: {e}")
|
||||||
|
|
||||||
|
|
||||||
def process_lecture(lecture, lecture_index, lecture_path, lecture_dir, quality,
|
def process_lecture(lecture, lecture_path, lecture_dir, quality, access_token):
|
||||||
access_token):
|
|
||||||
index = lecture.get("index")
|
|
||||||
lecture_index = lecture.get("lecture_index")
|
|
||||||
lecture_id = lecture.get("lecture_id")
|
|
||||||
lecture_title = lecture.get("lecture_title")
|
lecture_title = lecture.get("lecture_title")
|
||||||
extension = lecture.get("extension")
|
|
||||||
assets = lecture.get("assets")
|
|
||||||
assets_count = lecture.get("assets_count")
|
|
||||||
subtitle_count = lecture.get("subtitle_count")
|
|
||||||
sources_count = lecture.get("sources_count")
|
|
||||||
is_encrypted = lecture.get("is_encrypted")
|
is_encrypted = lecture.get("is_encrypted")
|
||||||
asset_id = lecture.get("asset_id")
|
|
||||||
lecture_video_sources = lecture.get("video_sources")
|
lecture_video_sources = lecture.get("video_sources")
|
||||||
lecture_audio_sources = lecture.get("audio_sources")
|
lecture_audio_sources = lecture.get("audio_sources")
|
||||||
|
|
||||||
@ -980,7 +984,7 @@ def process_lecture(lecture, lecture_index, lecture_path, lecture_dir, quality,
|
|||||||
os.rename(temp_filepath, lecture_path)
|
os.rename(temp_filepath, lecture_path)
|
||||||
print("> HLS Download success")
|
print("> HLS Download success")
|
||||||
else:
|
else:
|
||||||
download(url, lecture_path, lecture_title)
|
download_aria(url, lecture_dir, lecture_title)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"> Error downloading lecture: ", e)
|
print(f"> Error downloading lecture: ", e)
|
||||||
else:
|
else:
|
||||||
@ -1004,7 +1008,6 @@ def parse_new(_udemy, quality, skip_lectures, dl_assets, dl_captions,
|
|||||||
|
|
||||||
for chapter in _udemy.get("chapters"):
|
for chapter in _udemy.get("chapters"):
|
||||||
chapter_title = chapter.get("chapter_title")
|
chapter_title = chapter.get("chapter_title")
|
||||||
chapter_id = chapter.get("id")
|
|
||||||
chapter_index = chapter.get("chapter_index")
|
chapter_index = chapter.get("chapter_index")
|
||||||
chapter_dir = os.path.join(course_dir, chapter_title)
|
chapter_dir = os.path.join(course_dir, chapter_title)
|
||||||
if not os.path.exists(chapter_dir):
|
if not os.path.exists(chapter_dir):
|
||||||
@ -1015,7 +1018,7 @@ def parse_new(_udemy, quality, skip_lectures, dl_assets, dl_captions,
|
|||||||
|
|
||||||
for lecture in chapter.get("lectures"):
|
for lecture in chapter.get("lectures"):
|
||||||
lecture_title = lecture.get("lecture_title")
|
lecture_title = lecture.get("lecture_title")
|
||||||
lecture_index = lecture.get("index")
|
lecture_index = lecture.get("lecture_index")
|
||||||
|
|
||||||
extension = lecture.get("extension")
|
extension = lecture.get("extension")
|
||||||
print(f"> Processing lecture {lecture_index} of {total_lectures}")
|
print(f"> Processing lecture {lecture_index} of {total_lectures}")
|
||||||
@ -1035,12 +1038,11 @@ def parse_new(_udemy, quality, skip_lectures, dl_assets, dl_captions,
|
|||||||
else:
|
else:
|
||||||
lecture_path = os.path.join(
|
lecture_path = os.path.join(
|
||||||
chapter_dir, "{}.mp4".format(sanitize(lecture_title)))
|
chapter_dir, "{}.mp4".format(sanitize(lecture_title)))
|
||||||
process_lecture(lecture, lecture_index, lecture_path,
|
process_lecture(lecture, lecture_path, chapter_dir,
|
||||||
chapter_dir, quality, access_token)
|
quality, access_token)
|
||||||
|
|
||||||
if dl_assets:
|
if dl_assets:
|
||||||
assets = lecture.get("assets")
|
assets = lecture.get("assets")
|
||||||
asset_count = lecture.get("asset_count")
|
|
||||||
print("> Processing {} assets for lecture...".format(
|
print("> Processing {} assets for lecture...".format(
|
||||||
len(assets)))
|
len(assets)))
|
||||||
|
|
||||||
@ -1071,16 +1073,13 @@ def parse_new(_udemy, quality, skip_lectures, dl_assets, dl_captions,
|
|||||||
print("AssetType: Video; AssetData: ", asset)
|
print("AssetType: Video; AssetData: ", asset)
|
||||||
elif asset_type == "audio" or asset_type == "e-book" or asset_type == "file" or asset_type == "presentation":
|
elif asset_type == "audio" or asset_type == "e-book" or asset_type == "file" or asset_type == "presentation":
|
||||||
try:
|
try:
|
||||||
download(download_url,
|
download_aria(download_url, chapter_dir, filename)
|
||||||
os.path.join(chapter_dir, filename),
|
|
||||||
filename)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("> Error downloading asset: ", e)
|
print("> Error downloading asset: ", e)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
subtitles = lecture.get("subtitles")
|
subtitles = lecture.get("subtitles")
|
||||||
if dl_captions and subtitles:
|
if dl_captions and subtitles:
|
||||||
subtitle_count = lecture.get("subtitle_count")
|
|
||||||
print("Processing {} captions...".format(len(subtitles)))
|
print("Processing {} captions...".format(len(subtitles)))
|
||||||
for subtitle in subtitles:
|
for subtitle in subtitles:
|
||||||
lang = subtitle.get("language")
|
lang = subtitle.get("language")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user