mirror of
https://cdm-project.com/Download-Tools/udemy-downloader.git
synced 2025-05-05 17:04:33 +02:00
parent
f9acb2918a
commit
4568de9c43
44
main.py
44
main.py
@ -231,24 +231,8 @@ def download(url, path, filename):
|
|||||||
pbar.close()
|
pbar.close()
|
||||||
return file_size
|
return file_size
|
||||||
|
|
||||||
def parse(data):
|
def process_lecture(lecture, lecture_path):
|
||||||
chapters = []
|
|
||||||
|
|
||||||
for obj in data:
|
|
||||||
if obj["_class"] == "chapter":
|
|
||||||
obj["lectures"] = []
|
|
||||||
chapters.append(obj)
|
|
||||||
elif obj["_class"] == "lecture" and obj["asset"]["asset_type"] == "Video":
|
|
||||||
chapters[-1]["lectures"].append(obj)
|
|
||||||
|
|
||||||
for chapter in chapters:
|
|
||||||
chapter_dir = f"%s\\%s. %s" % (download_dir,chapters.index(chapter) + 1,sanitize(chapter["title"]))
|
|
||||||
if not os.path.exists(chapter_dir):
|
|
||||||
os.mkdir(chapter_dir)
|
|
||||||
|
|
||||||
for lecture in chapter["lectures"]:
|
|
||||||
lecture_title = lecture["title"]
|
lecture_title = lecture["title"]
|
||||||
lecture_path = f"%s\\%s. %s.mp4" % (chapter_dir, chapter["lectures"].index(lecture) + 1,sanitize(lecture_title))
|
|
||||||
lecture_asset = lecture["asset"]
|
lecture_asset = lecture["asset"]
|
||||||
if lecture_asset["media_license_token"] == None:
|
if lecture_asset["media_license_token"] == None:
|
||||||
# not encrypted
|
# not encrypted
|
||||||
@ -272,6 +256,32 @@ def parse(data):
|
|||||||
else:
|
else:
|
||||||
print("> Lecture '%s' is already downloaded, skipping..." % lecture_title)
|
print("> Lecture '%s' is already downloaded, skipping..." % lecture_title)
|
||||||
|
|
||||||
|
def parse(data):
|
||||||
|
chapters = []
|
||||||
|
lectures = []
|
||||||
|
|
||||||
|
for obj in data:
|
||||||
|
if obj["_class"] == "chapter":
|
||||||
|
obj["lectures"] = []
|
||||||
|
chapters.append(obj)
|
||||||
|
elif obj["_class"] == "lecture" and obj["asset"]["asset_type"] == "Video":
|
||||||
|
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:
|
||||||
|
chapter_dir = f"%s\\%s. %s" % (download_dir,chapters.index(chapter) + 1,sanitize(chapter["title"]))
|
||||||
|
if not os.path.exists(chapter_dir):
|
||||||
|
os.mkdir(chapter_dir)
|
||||||
|
|
||||||
|
for lecture in chapter["lectures"]:
|
||||||
|
lecture_path = f"%s\\%s. %s.mp4" % (chapter_dir, chapter["lectures"].index(lecture) + 1,sanitize(lecture["title"]))
|
||||||
|
process_lecture(lecture, lecture_path)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if debug:
|
if debug:
|
||||||
# this is for development purposes so we dont need to make tons of requests when testing
|
# this is for development purposes so we dont need to make tons of requests when testing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user