Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit c0f9876

Browse files
committed
Add YoutubeDLWrapper
1 parent 51c06f5 commit c0f9876

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

utils/youtube_dl_wrapper.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import Optional
2+
3+
import youtube_dl
4+
5+
from .execute_parallel import execute_parallel
6+
7+
8+
class YoutubeDLWrapper:
9+
"""A YoutubeDL wrapper class for supporting python embedded multi-processing"""
10+
11+
def _youtube_dl_download_video(self, link: str, youtube_dl_option: Optional[dict[str, str]] = None) -> None:
12+
with youtube_dl.YoutubeDL(youtube_dl_option) as youtube_dl_downloader:
13+
youtube_dl_downloader.download([link])
14+
15+
def download(self, links: list[str], youtube_dl_option: Optional[dict[str, str]] = None) -> None:
16+
arguments = [(link, youtube_dl_option) for link in links]
17+
execute_parallel(self._youtube_dl_download_video, arguments)
18+
19+
20+
youtube_dl_wrapper = YoutubeDLWrapper() # singleton

0 commit comments

Comments
 (0)