mirror of
https://cdm-project.com/Download-Tools/udemy-downloader.git
synced 2025-05-02 21:34:24 +02:00
better debug exceptions
This commit is contained in:
parent
52e3cd5b36
commit
e20699549e
58
main.py
58
main.py
@ -27,7 +27,7 @@ from pathvalidate import sanitize_filename
|
|||||||
retry = 3
|
retry = 3
|
||||||
cookies = ""
|
cookies = ""
|
||||||
downloader = None
|
downloader = None
|
||||||
logger = None
|
logger: logging.Logger = None
|
||||||
dl_assets = False
|
dl_assets = False
|
||||||
skip_lectures = False
|
skip_lectures = False
|
||||||
dl_captions = False
|
dl_captions = False
|
||||||
@ -559,8 +559,8 @@ class Udemy:
|
|||||||
# unknown format type
|
# unknown format type
|
||||||
logger.debug(f"Unknown format type : {f}")
|
logger.debug(f"Unknown format type : {f}")
|
||||||
continue
|
continue
|
||||||
except Exception as error:
|
except Exception:
|
||||||
logger.error(f"Error fetching MPD streams: '{error}'")
|
logger.exception(f"Error fetching MPD streams")
|
||||||
return _temp
|
return _temp
|
||||||
|
|
||||||
def extract_course_name(self, url):
|
def extract_course_name(self, url):
|
||||||
@ -1049,7 +1049,7 @@ def cleanup(path):
|
|||||||
try:
|
try:
|
||||||
os.remove(file_list)
|
os.remove(file_list)
|
||||||
except OSError:
|
except OSError:
|
||||||
logger.error(f"Error deleting file: {file_list}")
|
logger.exception(f"Error deleting file: {file_list}")
|
||||||
os.removedirs(path)
|
os.removedirs(path)
|
||||||
|
|
||||||
|
|
||||||
@ -1113,15 +1113,15 @@ def handle_segments(url, format_id, video_title,
|
|||||||
try:
|
try:
|
||||||
video_kid = extract_kid(video_filepath_enc)
|
video_kid = extract_kid(video_filepath_enc)
|
||||||
logger.info("KID for video file is: " + video_kid)
|
logger.info("KID for video file is: " + video_kid)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error(f"Error extracting video kid: {e}")
|
logger.exception(f"Error extracting video kid")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
audio_kid = extract_kid(audio_filepath_enc)
|
audio_kid = extract_kid(audio_filepath_enc)
|
||||||
logger.info("KID for audio file is: " + audio_kid)
|
logger.info("KID for audio file is: " + audio_kid)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error(f"Error extracting audio kid: {e}")
|
logger.exception(f"Error extracting audio kid")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1152,8 +1152,8 @@ def handle_segments(url, format_id, video_title,
|
|||||||
os.remove(video_filepath_dec)
|
os.remove(video_filepath_dec)
|
||||||
os.remove(audio_filepath_dec)
|
os.remove(audio_filepath_dec)
|
||||||
os.chdir(HOME_DIR)
|
os.chdir(HOME_DIR)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error(f"Error: ", e)
|
logger.exception(f"Error: ")
|
||||||
|
|
||||||
|
|
||||||
def check_for_aria():
|
def check_for_aria():
|
||||||
@ -1164,10 +1164,9 @@ def check_for_aria():
|
|||||||
return True
|
return True
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error(
|
logger.exception(
|
||||||
"> Unexpected exception while checking for Aria2c, please tell the program author about this! ",
|
"> Unexpected exception while checking for Aria2c, please tell the program author about this! ")
|
||||||
e)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -1179,10 +1178,9 @@ def check_for_ffmpeg():
|
|||||||
return True
|
return True
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error(
|
logger.exception(
|
||||||
"> Unexpected exception while checking for FFMPEG, please tell the program author about this! ",
|
"> Unexpected exception while checking for FFMPEG, please tell the program author about this! ")
|
||||||
e)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -1195,9 +1193,8 @@ def check_for_mp4decrypt():
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.exception(
|
||||||
"> Unexpected exception while checking for MP4Decrypt, please tell the program author about this! ",
|
"> Unexpected exception while checking for MP4Decrypt, please tell the program author about this! ")
|
||||||
e)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -1278,8 +1275,8 @@ def process_caption(caption, lecture_title, lecture_dir, tries=0):
|
|||||||
logger.info(" > Caption conversion complete.")
|
logger.info(" > Caption conversion complete.")
|
||||||
if not keep_vtt:
|
if not keep_vtt:
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error(f" > Error converting caption: {e}")
|
logger.exception(f" > Error converting caption")
|
||||||
|
|
||||||
|
|
||||||
def process_lecture(lecture, lecture_path, lecture_file_name, chapter_dir):
|
def process_lecture(lecture, lecture_path, lecture_file_name, chapter_dir):
|
||||||
@ -1344,9 +1341,8 @@ def process_lecture(lecture, lecture_path, lecture_file_name, chapter_dir):
|
|||||||
lecture_title + ".mp4")
|
lecture_title + ".mp4")
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f" > Download return code: {ret_code}")
|
f" > Download return code: {ret_code}")
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error(f"> Error downloading lecture: {e}")
|
logger.exception(f"> Error downloading lecture")
|
||||||
raise e
|
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(
|
||||||
f" > Lecture '{lecture_title}' is already downloaded, skipping...")
|
f" > Lecture '{lecture_title}' is already downloaded, skipping...")
|
||||||
@ -1411,9 +1407,9 @@ def parse_new(_udemy):
|
|||||||
with open(lecture_path, encoding="utf8", mode='w') as f:
|
with open(lecture_path, encoding="utf8", mode='w') as f:
|
||||||
f.write(html_content)
|
f.write(html_content)
|
||||||
f.close()
|
f.close()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error(
|
logger.exception(
|
||||||
" > Failed to write html file: ", e)
|
" > Failed to write html file")
|
||||||
else:
|
else:
|
||||||
process_lecture(lecture, lecture_path,
|
process_lecture(lecture, lecture_path,
|
||||||
lecture_file_name, chapter_dir)
|
lecture_file_name, chapter_dir)
|
||||||
@ -1466,8 +1462,8 @@ def parse_new(_udemy):
|
|||||||
filename)
|
filename)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f" > Download return code: {ret_code}")
|
f" > Download return code: {ret_code}")
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.error("> Error downloading asset: ", e)
|
logger.exception("> Error downloading asset")
|
||||||
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(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user