Skip to content

Commit

Permalink
feat: add prefix_name argument to video.download() method
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansaul committed Feb 1, 2024
1 parent 771b62e commit 9964c65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def download(
for section in course_sections:
section_title = helpers.clean_string(section.title)
section_videos = section.videos_url
for video_url in section_videos:
for idx, video_url in enumerate(section_videos, start=1):
try:
video = client.video(video_url)
except VideoError as e:
Expand All @@ -130,7 +130,11 @@ def download(
dir_path = (
f"{consts.DOWNLOADS_DIR}/{course_title}/{section_title}"
)
video.download(quality=quality, dir_path=dir_path)
video.download(
quality=quality,
dir_path=dir_path,
prefix_name=f"{idx:02d}. ",
)
except DownloadError:
if attempt < max_retries:
tprint("⠹ An error occurred while downloading :(")
Expand Down
3 changes: 2 additions & 1 deletion src/facilito/models/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Video(BaseModel):

def download(
self,
prefix_name: str = "",
dir_path: str = consts.DOWNLOADS_DIR,
quality: Quality = Quality.BEST,
cookiefile: str = consts.COOKIES_FILE,
Expand All @@ -62,7 +63,7 @@ def download(
yt_dlp_params = {
"format": dlp_format,
"cookiefile": cookiefile,
"outtmpl": f"{dir_path}/{video_name}.%(ext)s",
"outtmpl": f"{dir_path}/{prefix_name}{video_name}.%(ext)s",
"logger": YoutubeDLLogger(),
"n_threads": 10,
"retries": 5,
Expand Down

0 comments on commit 9964c65

Please # to comment.