mirror of
https://cdm-project.com/Download-Tools/udemy-downloader.git
synced 2025-04-30 22:04:27 +02:00
update: error handling for download function
+ raise exception if return code is non-0 + version bump
This commit is contained in:
parent
4bdbf68f58
commit
f3b1c74f13
@ -1 +1 @@
|
|||||||
__version__ = "1.1.5"
|
__version__ = "1.1.6"
|
||||||
|
17
main.py
17
main.py
@ -1225,7 +1225,6 @@ def download_aria(url, file_dir, filename):
|
|||||||
"""
|
"""
|
||||||
@author Puyodead1
|
@author Puyodead1
|
||||||
"""
|
"""
|
||||||
logger.info(" > Downloading File...")
|
|
||||||
args = [
|
args = [
|
||||||
"aria2c", url, "-o", filename, "-d", file_dir, "-j16", "-s20", "-x16",
|
"aria2c", url, "-o", filename, "-d", file_dir, "-j16", "-s20", "-x16",
|
||||||
"-c", "--auto-file-renaming=false", "--summary-interval=0"
|
"-c", "--auto-file-renaming=false", "--summary-interval=0"
|
||||||
@ -1234,9 +1233,9 @@ def download_aria(url, file_dir, filename):
|
|||||||
args.append("--disable-ipv6")
|
args.append("--disable-ipv6")
|
||||||
ret_code = subprocess.Popen(
|
ret_code = subprocess.Popen(
|
||||||
args, stderr=subprocess.PIPE, stdout=subprocess.PIPE).wait()
|
args, stderr=subprocess.PIPE, stdout=subprocess.PIPE).wait()
|
||||||
logger.info(" > File Downloaded")
|
if ret_code != 0:
|
||||||
|
raise Exception("Return code from the downloader was non-0 (error)")
|
||||||
logger.debug("Return code: " + str(ret_code))
|
return ret_code
|
||||||
|
|
||||||
|
|
||||||
def process_caption(caption, lecture_title, lecture_dir, tries=0):
|
def process_caption(caption, lecture_title, lecture_dir, tries=0):
|
||||||
@ -1251,7 +1250,8 @@ def process_caption(caption, lecture_title, lecture_dir, tries=0):
|
|||||||
else:
|
else:
|
||||||
logger.info(f" > Downloading caption: '%s'" % filename)
|
logger.info(f" > Downloading caption: '%s'" % filename)
|
||||||
try:
|
try:
|
||||||
download_aria(caption.get("download_url"), lecture_dir, filename)
|
download_aria(caption.get(
|
||||||
|
"download_url"), lecture_dir, filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if tries >= 3:
|
if tries >= 3:
|
||||||
logger.error(
|
logger.error(
|
||||||
@ -1335,13 +1335,12 @@ def process_lecture(lecture, lecture_path, lecture_file_name, chapter_dir):
|
|||||||
else:
|
else:
|
||||||
download_aria(url, chapter_dir,
|
download_aria(url, chapter_dir,
|
||||||
lecture_title + ".mp4")
|
lecture_title + ".mp4")
|
||||||
except EnvironmentError as e:
|
except Exception as e:
|
||||||
logger.error("> Error downloading lecture")
|
logger.error(f"> Error downloading lecture: {e}")
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(
|
||||||
" > Lecture '%s' is already downloaded, skipping..." %
|
f" > Lecture '{lecture_title}' is already downloaded, skipping...")
|
||||||
lecture_title)
|
|
||||||
else:
|
else:
|
||||||
logger.error(" > Missing sources for lecture", lecture)
|
logger.error(" > Missing sources for lecture", lecture)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user