mirror of
https://cdm-project.com/Download-Tools/udemy-downloader.git
synced 2025-04-30 00:54:25 +02:00
feat: custom output path (Closes #168)
This commit is contained in:
parent
271a426a8c
commit
8ab48230ed
@ -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"
|
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()
|
HOME_DIR = os.getcwd()
|
||||||
DOWNLOAD_DIR = os.path.join(os.getcwd(), "out_dir")
|
|
||||||
SAVED_DIR = os.path.join(os.getcwd(), "saved")
|
SAVED_DIR = os.path.join(os.getcwd(), "saved")
|
||||||
KEY_FILE_PATH = os.path.join(os.getcwd(), "keyfile.json")
|
KEY_FILE_PATH = os.path.join(os.getcwd(), "keyfile.json")
|
||||||
COOKIE_FILE_PATH = os.path.join(os.getcwd(), "cookies.txt")
|
COOKIE_FILE_PATH = os.path.join(os.getcwd(), "cookies.txt")
|
||||||
|
29
main.py
29
main.py
@ -29,6 +29,8 @@ from tls import SSLCiphers
|
|||||||
from utils import extract_kid
|
from utils import extract_kid
|
||||||
from vtt_to_srt import convert
|
from vtt_to_srt import convert
|
||||||
|
|
||||||
|
DOWNLOAD_DIR = os.path.join(os.getcwd(), "out_dir")
|
||||||
|
|
||||||
retry = 3
|
retry = 3
|
||||||
downloader = None
|
downloader = None
|
||||||
logger: logging.Logger = 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
|
# this is the first function that is called, we parse the arguments, setup the logger, and ensure that required directories exist
|
||||||
def pre_run():
|
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
|
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 directory exists
|
|
||||||
if not os.path.exists(DOWNLOAD_DIR):
|
|
||||||
os.makedirs(DOWNLOAD_DIR)
|
|
||||||
|
|
||||||
# make sure the logs directory exists
|
# make sure the logs directory exists
|
||||||
if not os.path.exists(LOG_DIR_PATH):
|
if not os.path.exists(LOG_DIR_PATH):
|
||||||
@ -221,6 +219,12 @@ def pre_run():
|
|||||||
action="store_true",
|
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",
|
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__))
|
parser.add_argument("-v", "--version", action="version", version="You are running version {version}".format(version=__version__))
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@ -283,6 +287,14 @@ def pre_run():
|
|||||||
else:
|
else:
|
||||||
print(f"Invalid log level: {args.log_level}; Using INFO")
|
print(f"Invalid log level: {args.log_level}; Using INFO")
|
||||||
LOG_LEVEL = logging.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
|
# setup a logger
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -308,12 +320,7 @@ def pre_run():
|
|||||||
logger.addHandler(stream)
|
logger.addHandler(stream)
|
||||||
logger.addHandler(file_handler)
|
logger.addHandler(file_handler)
|
||||||
|
|
||||||
if args.id_as_course_name:
|
logger.info(f"Output directory set to {DOWNLOAD_DIR}")
|
||||||
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
|
|
||||||
|
|
||||||
Path(DOWNLOAD_DIR).mkdir(parents=True, exist_ok=True)
|
Path(DOWNLOAD_DIR).mkdir(parents=True, exist_ok=True)
|
||||||
Path(SAVED_DIR).mkdir(parents=True, exist_ok=True)
|
Path(SAVED_DIR).mkdir(parents=True, exist_ok=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user