mirror of
https://cdm-project.com/Download-Tools/udemy-downloader.git
synced 2025-05-05 09:44:24 +02:00
parent
f9acb2918a
commit
4568de9c43
60
main.py
60
main.py
@ -231,15 +231,47 @@ def download(url, path, filename):
|
|||||||
pbar.close()
|
pbar.close()
|
||||||
return file_size
|
return file_size
|
||||||
|
|
||||||
|
def process_lecture(lecture, lecture_path):
|
||||||
|
lecture_title = lecture["title"]
|
||||||
|
lecture_asset = lecture["asset"]
|
||||||
|
if lecture_asset["media_license_token"] == None:
|
||||||
|
# not encrypted
|
||||||
|
lecture_url = lecture_asset["media_sources"][0]["src"] # best quality is the first index
|
||||||
|
if not os.path.isfile(lecture_path):
|
||||||
|
download(lecture_url, lecture_path, lecture_title)
|
||||||
|
else:
|
||||||
|
print(f"> Lecture '%s' is already downloaded, skipping..." % lecture_title)
|
||||||
|
else:
|
||||||
|
# encrypted
|
||||||
|
print(f"> Lecture '%s' has DRM, attempting to download" % lecture_title)
|
||||||
|
lecture_working_dir = "%s\%s" % (working_dir, lecture_asset["id"]) # set the folder to download ephemeral files
|
||||||
|
if not os.path.exists(lecture_working_dir):
|
||||||
|
os.mkdir(lecture_working_dir)
|
||||||
|
if not os.path.isfile(lecture_path):
|
||||||
|
mpd_url = lecture_asset["media_sources"][1]["src"] # index 1 is the dash
|
||||||
|
base_url = mpd_url.split("index.mpd")[0]
|
||||||
|
media_info = manifest_parser(mpd_url)
|
||||||
|
handle_irregular_segments(media_info,lecture_title,lecture_working_dir,lecture_path)
|
||||||
|
cleanup(lecture_working_dir)
|
||||||
|
else:
|
||||||
|
print("> Lecture '%s' is already downloaded, skipping..." % lecture_title)
|
||||||
|
|
||||||
def parse(data):
|
def parse(data):
|
||||||
chapters = []
|
chapters = []
|
||||||
|
lectures = []
|
||||||
|
|
||||||
for obj in data:
|
for obj in data:
|
||||||
if obj["_class"] == "chapter":
|
if obj["_class"] == "chapter":
|
||||||
obj["lectures"] = []
|
obj["lectures"] = []
|
||||||
chapters.append(obj)
|
chapters.append(obj)
|
||||||
elif obj["_class"] == "lecture" and obj["asset"]["asset_type"] == "Video":
|
elif obj["_class"] == "lecture" and obj["asset"]["asset_type"] == "Video":
|
||||||
chapters[-1]["lectures"].append(obj)
|
try:
|
||||||
|
chapters[-1]["lectures"].append(obj)
|
||||||
|
except IndexError:
|
||||||
|
# This is caused by there not being a starting chapter
|
||||||
|
lectures.append(obj)
|
||||||
|
lecture_path = f"%s\\%s. %s.mp4" % (download_dir, lectures.index(obj) + 1, sanitize(obj["title"]))
|
||||||
|
process_lecture(obj, lecture_path)
|
||||||
|
|
||||||
for chapter in chapters:
|
for chapter in chapters:
|
||||||
chapter_dir = f"%s\\%s. %s" % (download_dir,chapters.index(chapter) + 1,sanitize(chapter["title"]))
|
chapter_dir = f"%s\\%s. %s" % (download_dir,chapters.index(chapter) + 1,sanitize(chapter["title"]))
|
||||||
@ -247,30 +279,8 @@ def parse(data):
|
|||||||
os.mkdir(chapter_dir)
|
os.mkdir(chapter_dir)
|
||||||
|
|
||||||
for lecture in chapter["lectures"]:
|
for lecture in chapter["lectures"]:
|
||||||
lecture_title = lecture["title"]
|
lecture_path = f"%s\\%s. %s.mp4" % (chapter_dir, chapter["lectures"].index(lecture) + 1,sanitize(lecture["title"]))
|
||||||
lecture_path = f"%s\\%s. %s.mp4" % (chapter_dir, chapter["lectures"].index(lecture) + 1,sanitize(lecture_title))
|
process_lecture(lecture, lecture_path)
|
||||||
lecture_asset = lecture["asset"]
|
|
||||||
if lecture_asset["media_license_token"] == None:
|
|
||||||
# not encrypted
|
|
||||||
lecture_url = lecture_asset["media_sources"][0]["src"] # best quality is the first index
|
|
||||||
if not os.path.isfile(lecture_path):
|
|
||||||
download(lecture_url, lecture_path, lecture_title)
|
|
||||||
else:
|
|
||||||
print(f"> Lecture '%s' is already downloaded, skipping..." % lecture_title)
|
|
||||||
else:
|
|
||||||
# encrypted
|
|
||||||
print(f"> Lecture '%s' has DRM, attempting to download" % lecture_title)
|
|
||||||
lecture_working_dir = "%s\%s" % (working_dir, lecture_asset["id"]) # set the folder to download ephemeral files
|
|
||||||
if not os.path.exists(lecture_working_dir):
|
|
||||||
os.mkdir(lecture_working_dir)
|
|
||||||
if not os.path.isfile(lecture_path):
|
|
||||||
mpd_url = lecture_asset["media_sources"][1]["src"] # index 1 is the dash
|
|
||||||
base_url = mpd_url.split("index.mpd")[0]
|
|
||||||
media_info = manifest_parser(mpd_url)
|
|
||||||
handle_irregular_segments(media_info,lecture_title,lecture_working_dir,lecture_path)
|
|
||||||
cleanup(lecture_working_dir)
|
|
||||||
else:
|
|
||||||
print("> Lecture '%s' is already downloaded, skipping..." % lecture_title)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if debug:
|
if debug:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user