add 'continuous numbering' option

This commit is contained in:
Puyodead1 2023-10-27 09:35:55 -04:00
parent 935b2a41f3
commit 79ea132962
No known key found for this signature in database
GPG Key ID: BA5F91AAEF68E5CE
3 changed files with 29 additions and 14 deletions

View File

@ -84,9 +84,10 @@ You can now run the program, see the examples below. The course will download to
# Advanced Usage
```
usage: main.py [-h] -c COURSE_URL [-b BEARER_TOKEN] [-q QUALITY] [-l LANG] [-cd CONCURRENT_DOWNLOADS] [--disable-ipv6] [--skip-lectures] [--download-assets] [--download-captions] [--download-quizzes]
[--keep-vtt] [--skip-hls] [--info] [--id-as-course-name] [-sc] [--save-to-file] [--load-from-file] [--log-level LOG_LEVEL] [--browser {chrome,firefox,opera,edge,brave,chromium,vivaldi,safari}]
[--use-h265] [--h265-crf H265_CRF] [--h265-preset H265_PRESET] [--use-nvenc] [-v]
usage: main.py [-h] -c COURSE_URL [-b BEARER_TOKEN] [-q QUALITY] [-l LANG] [-cd CONCURRENT_DOWNLOADS] [--disable-ipv6] [--skip-lectures] [--download-assets]
[--download-captions] [--download-quizzes] [--keep-vtt] [--skip-hls] [--info] [--id-as-course-name] [-sc] [--save-to-file] [--load-from-file]
[--log-level LOG_LEVEL] [--browser {chrome,firefox,opera,edge,brave,chromium,vivaldi,safari}] [--use-h265] [--h265-crf H265_CRF] [--h265-preset H265_PRESET]
[--use-nvenc] [--out OUT] [--continue-lecture-numbers]
Udemy Downloader
@ -97,7 +98,8 @@ options:
-b BEARER_TOKEN, --bearer BEARER_TOKEN
The Bearer token to use
-q QUALITY, --quality QUALITY
Download specific video quality. If the requested quality isn't available, the closest quality will be used. If not specified, the best quality will be downloaded for each lecture
Download specific video quality. If the requested quality isn't available, the closest quality will be used. If not specified, the best quality will be
downloaded for each lecture
-l LANG, --lang LANG The language to download for captions, specify 'all' to download all captions (Default is 'en')
-cd CONCURRENT_DOWNLOADS, --concurrent-downloads CONCURRENT_DOWNLOADS
The number of maximum concurrent downloads for segments (HLS and DASH, must be a number 1-30)
@ -112,10 +114,10 @@ options:
--id-as-course-name If specified, the course id will be used in place of the course name for the output directory. This is a 'hack' to reduce the path length
-sc, --subscription-course
Mark the course as a subscription based course, use this if you are having problems with the program auto detecting it
--save-to-file If specified, course content will be saved to a file that can be loaded later with --load-from-file, this can reduce processing time (Note that asset links expire after a certain
amount of time)
--load-from-file If specified, course content will be loaded from a previously saved file with --save-to-file, this can reduce processing time (Note that asset links expire after a certain amount of
time)
--save-to-file If specified, course content will be saved to a file that can be loaded later with --load-from-file, this can reduce processing time (Note that asset
links expire after a certain amount of time)
--load-from-file If specified, course content will be loaded from a previously saved file with --save-to-file, this can reduce processing time (Note that asset links
expire after a certain amount of time)
--log-level LOG_LEVEL
Logging level: one of DEBUG, INFO, ERROR, WARNING, CRITICAL (Default is INFO)
--browser {chrome,firefox,opera,edge,brave,chromium,vivaldi,safari}
@ -125,7 +127,9 @@ options:
--h265-preset H265_PRESET
Set a custom preset value for H.265 encoding. FFMPEG default is medium
--use-nvenc Whether to use the NVIDIA hardware transcoding for H.265. Only works if you have a supported NVIDIA GPU and ffmpeg with nvenc support
-v, --version show program's version number and exit
--out OUT, -o OUT Set the path to the output directory
--continue-lecture-numbers, -n
Use continuous lecture numbering instead of per-chapter
```
- Passing a Bearer Token and Course ID as an argument
@ -177,6 +181,9 @@ options:
- `python main.py -c <Course URL> --use-h265 --h265-preset faster`
- Encode in H.265 using NVIDIA hardware transcoding:
- `python main.py -c <Course URL> --use-h265 --use-nvenc`
- Use continuous numbering (don't restart at 1 in every chapter):
- `python main.py -c <Course URL> --continue-lecture-numbers`
- `python main.py -c <Course URL> -n`
If you encounter errors while downloading such as

View File

@ -1 +0,0 @@
__version__ = "1.2.11"

17
main.py
View File

@ -23,7 +23,6 @@ from pathvalidate import sanitize_filename
from requests.exceptions import ConnectionError as conn_error
from tqdm import tqdm
from _version import __version__
from constants import *
from tls import SSLCiphers
from utils import extract_kid
@ -60,6 +59,7 @@ h265_preset = "medium"
use_nvenc = False
browser = None
cj = None
use_continuous_lecture_numbers = False
# from https://stackoverflow.com/a/21978778/9785713
@ -72,7 +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, is_subscription_course, 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, use_continuous_lecture_numbers
# make sure the logs directory exists
if not os.path.exists(LOG_DIR_PATH):
@ -225,7 +225,13 @@ def pre_run():
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(
"--continue-lecture-numbers", "-n",
dest="use_continuous_lecture_numbers",
action="store_true",
help="Use continuous lecture numbering instead of per-chapter",
)
# parser.add_argument("-v", "--version", action="version", version="You are running version {version}".format(version=__version__))
args = parser.parse_args()
if args.download_assets:
@ -295,6 +301,8 @@ def pre_run():
browser = args.browser
if args.out:
DOWNLOAD_DIR = os.path.abspath(args.out)
if args.use_continuous_lecture_numbers:
use_continuous_lecture_numbers = args.use_continuous_lecture_numbers
# setup a logger
logger = logging.getLogger(__name__)
@ -1980,7 +1988,8 @@ def main():
if clazz == "chapter":
# reset lecture tracking
lecture_counter = 0
if not use_continuous_lecture_numbers:
lecture_counter = 0
lectures = []
chapter_index = entry.get("object_index")