mirror of
https://cdm-project.com/Download-Tools/udemy-downloader.git
synced 2025-05-29 05:20:12 +02:00
fix: empty html files being generated
This commit is contained in:
parent
68f5172e30
commit
bc9f6ecb1a
31
main.py
31
main.py
@ -1369,22 +1369,22 @@ def parse_new(_udemy):
|
|||||||
logger.info(
|
logger.info(
|
||||||
" > Lecture '%s' is already downloaded, skipping..." %
|
" > Lecture '%s' is already downloaded, skipping..." %
|
||||||
lecture_title)
|
lecture_title)
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
# Check if the file is an html file
|
# Check if the file is an html file
|
||||||
if extension == "html":
|
if extension == "html":
|
||||||
html_content = lecture.get("html_content").encode(
|
# if the html content is None or an empty string, skip it so we dont save empty html files
|
||||||
"ascii", "ignore").decode("utf8")
|
if lecture.get("html_content") != None and lecture.get("html_content") != "":
|
||||||
lecture_path = os.path.join(
|
html_content = lecture.get("html_content").encode(
|
||||||
chapter_dir, "{}.html".format(sanitize_filename(lecture_title)))
|
"ascii", "ignore").decode("utf8")
|
||||||
try:
|
lecture_path = os.path.join(
|
||||||
with open(lecture_path, encoding="utf8", mode='w') as f:
|
chapter_dir, "{}.html".format(sanitize_filename(lecture_title)))
|
||||||
f.write(html_content)
|
try:
|
||||||
f.close()
|
with open(lecture_path, encoding="utf8", mode='w') as f:
|
||||||
except Exception as e:
|
f.write(html_content)
|
||||||
logger.error(
|
f.close()
|
||||||
" > Failed to write html file: ", e)
|
except Exception as e:
|
||||||
continue
|
logger.error(
|
||||||
|
" > Failed to write html file: ", e)
|
||||||
else:
|
else:
|
||||||
process_lecture(lecture, lecture_path,
|
process_lecture(lecture, lecture_path,
|
||||||
lecture_file_name, chapter_dir)
|
lecture_file_name, chapter_dir)
|
||||||
@ -1426,7 +1426,6 @@ def parse_new(_udemy):
|
|||||||
filename)
|
filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("> Error downloading asset: ", e)
|
logger.error("> Error downloading asset: ", e)
|
||||||
continue
|
|
||||||
elif asset_type == "external_link":
|
elif asset_type == "external_link":
|
||||||
# write the external link to a shortcut file
|
# write the external link to a shortcut file
|
||||||
file_path = os.path.join(
|
file_path = os.path.join(
|
||||||
@ -1729,8 +1728,6 @@ def main():
|
|||||||
"asset_id": asset.get("id")
|
"asset_id": asset.get("id")
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
logger.debug(
|
|
||||||
f"Reached an area with no media sources: {asset}")
|
|
||||||
lectures.append({
|
lectures.append({
|
||||||
"index":
|
"index":
|
||||||
lecture_counter,
|
lecture_counter,
|
||||||
@ -1783,8 +1780,6 @@ def main():
|
|||||||
"asset_id": asset.get("id")
|
"asset_id": asset.get("id")
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
logger.debug(
|
|
||||||
f"Reached an area with no media sources: {asset}")
|
|
||||||
lectures.append({
|
lectures.append({
|
||||||
"index":
|
"index":
|
||||||
lecture_counter,
|
lecture_counter,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user