diff --git a/constants.py b/constants.py index 952ad0f..7898381 100644 --- a/constants.py +++ b/constants.py @@ -20,7 +20,6 @@ COLLECTION_URL = "https://{portal_name}.udemy.com/api-2.0/users/me/subscribed-co QUIZ_URL = "https://{portal_name}.udemy.com/api-2.0/quizzes/{quiz_id}/assessments/?version=1&page_size=250&fields[assessment]=id,assessment_type,prompt,correct_response,section,question_plain,related_lectures" HOME_DIR = os.getcwd() -DOWNLOAD_DIR = os.path.join(os.getcwd(), "out_dir") SAVED_DIR = os.path.join(os.getcwd(), "saved") KEY_FILE_PATH = os.path.join(os.getcwd(), "keyfile.json") COOKIE_FILE_PATH = os.path.join(os.getcwd(), "cookies.txt") diff --git a/main.py b/main.py index a324cc8..680dd0f 100644 --- a/main.py +++ b/main.py @@ -29,6 +29,8 @@ from tls import SSLCiphers from utils import extract_kid from vtt_to_srt import convert +DOWNLOAD_DIR = os.path.join(os.getcwd(), "out_dir") + retry = 3 downloader = None logger: logging.Logger = None @@ -70,11 +72,7 @@ def log_subprocess_output(prefix: str, pipe: IO[bytes]): # this is the first function that is called, we parse the arguments, setup the logger, and ensure that required directories exist def pre_run(): - global dl_assets, dl_captions, dl_quizzes, skip_lectures, caption_locale, quality, bearer_token, course_name, keep_vtt, skip_hls, concurrent_downloads, disable_ipv6, load_from_file, save_to_file, bearer_token, course_url, info, logger, keys, id_as_course_name, LOG_LEVEL, use_h265, h265_crf, h265_preset, use_nvenc, browser - - # make sure the directory exists - if not os.path.exists(DOWNLOAD_DIR): - os.makedirs(DOWNLOAD_DIR) + global dl_assets, dl_captions, dl_quizzes, skip_lectures, caption_locale, quality, bearer_token, course_name, keep_vtt, skip_hls, concurrent_downloads, disable_ipv6, load_from_file, save_to_file, bearer_token, course_url, info, logger, keys, id_as_course_name, LOG_LEVEL, use_h265, h265_crf, h265_preset, use_nvenc, browser, is_subscription_course, DOWNLOAD_DIR # make sure the logs directory exists if not os.path.exists(LOG_DIR_PATH): @@ -221,6 +219,12 @@ def pre_run(): action="store_true", help="Whether to use the NVIDIA hardware transcoding for H.265. Only works if you have a supported NVIDIA GPU and ffmpeg with nvenc support", ) + parser.add_argument( + "--out", "-o", + dest="out", + type=str, + help="Set the path to the output directory", + ) parser.add_argument("-v", "--version", action="version", version="You are running version {version}".format(version=__version__)) args = parser.parse_args() @@ -283,6 +287,14 @@ def pre_run(): else: print(f"Invalid log level: {args.log_level}; Using INFO") LOG_LEVEL = logging.INFO + if args.id_as_course_name: + id_as_course_name = args.id_as_course_name + if args.is_subscription_course: + is_subscription_course = args.is_subscription_course + if args.browser: + browser = args.browser + if args.out: + DOWNLOAD_DIR = os.path.abspath(args.out) # setup a logger logger = logging.getLogger(__name__) @@ -308,12 +320,7 @@ def pre_run(): logger.addHandler(stream) logger.addHandler(file_handler) - if args.id_as_course_name: - id_as_course_name = args.id_as_course_name - if args.is_subscription_course: - is_subscription_course = args.is_subscription_course - if args.browser: - browser = args.browser + logger.info(f"Output directory set to {DOWNLOAD_DIR}") Path(DOWNLOAD_DIR).mkdir(parents=True, exist_ok=True) Path(SAVED_DIR).mkdir(parents=True, exist_ok=True)