Skip to content

Commit

Permalink
feat: add thread control to downloaders
Browse files Browse the repository at this point in the history
Improve download performance by introducing a configurable number of threads. Allows users to control the number of concurrent downloads from 1 to 16.
  • Loading branch information
ivansaul committed Nov 23, 2024
1 parent 6624bb2 commit 37d4fb1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/facilito/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def download(
show_default=True,
),
] = False,
threads: Annotated[
int,
typer.Option(
"--threads",
"-t",
min=1,
max=16,
help="Number of threads to use.",
show_default=True,
),
] = 10,
):
"""
Download a course | video | lecture from the given URL.
Expand All @@ -79,6 +90,7 @@ def download(
url,
quality=quality,
override=override,
threads=threads,
)
)

Expand Down
1 change: 1 addition & 0 deletions src/facilito/downloaders/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async def download_course(context: BrowserContext, course: Course, **kwargs):
:param Course course: Course model to download.
:param bool override: Override existing file if exists (default: False).
:param int threads: Number of threads to use (default: 10).
"""
COURSE_DIR_PATH = DIR_PATH / course.slug
COURSE_DIR_PATH.mkdir(parents=True, exist_ok=True)
Expand Down
1 change: 1 addition & 0 deletions src/facilito/downloaders/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async def download_unit(context: BrowserContext, unit: Unit, path: Path, **kwarg
:param Quality quality: Quality of the video (default: Quality.MAX).
:param bool override: Override existing file if exists (default: False).
:param int threads: Number of threads to use (default: 10).
"""

if unit.type == TypeUnit.VIDEO:
Expand Down
4 changes: 4 additions & 0 deletions src/facilito/downloaders/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ async def download_video(
:param list[dic] cookies: Cookies for authentication (default: None).
:param bool override: Override existing file if exists (default: False).
:param int threads: Number of threads to use (default: 10).
"""

import subprocess

cookies = kwargs.get("cookies", None)
override = kwargs.get("override", False)
threads = kwargs.get("threads", 10)

path.parent.mkdir(parents=True, exist_ok=True)

Expand All @@ -151,6 +153,8 @@ async def download_video(
"--quality",
quality.value,
"--skip-prompts",
"--threads",
str(threads),
]

# Download vsd binary if not exists
Expand Down

0 comments on commit 37d4fb1

Please # to comment.