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

Commit e151330

Browse files
committed
Add support concurrent fragment video downloading
1 parent f947f47 commit e151330

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

twitter_video_tools/platform_video_downloader.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Optional
1+
from multiprocessing import cpu_count as get_cpu_count
2+
from typing import Optional, Union
23

34
from playwright.sync_api import sync_playwright
45
from yt_dlp.utils import YoutubeDLError
@@ -41,12 +42,16 @@ def download_twitter_video(
4142
youtube_dl_option = self._make_youtube_dl_option(video_filename)
4243
youtube_dl_wrapper.download([video_link], youtube_dl_option)
4344

44-
def _make_youtube_dl_option(self, video_filename: Optional[str] = None) -> dict[str, str]:
45+
def _make_youtube_dl_option(self, video_filename: Optional[str] = None) -> dict[str, Union[str, int]]:
4546
youtube_dl_output_template = \
4647
f'{self.video_output_path}/{video_filename}' \
4748
if video_filename else \
4849
f'{self.video_output_path}/%(title)s.%(ext)s'
49-
return {'format': 'bestvideo/best', 'outtmpl': youtube_dl_output_template}
50+
return {
51+
'format': 'bestvideo/best',
52+
'outtmpl': youtube_dl_output_template,
53+
'concurrent_fragment_downloads': get_cpu_count(),
54+
}
5055

5156
def _get_twitter_private_videos_info(
5257
self,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import multiprocessing
21
import multiprocessing.dummy
2+
from multiprocessing import cpu_count as get_cpu_count
33
from typing import Any, Callable
44

55

66
def execute_parallel(func: Callable[[str], None], *args: Any, **kwargs: Any) -> None:
7-
pool = multiprocessing.dummy.Pool(multiprocessing.cpu_count())
7+
pool = multiprocessing.dummy.Pool(get_cpu_count())
88
pool.starmap(func, *args, **kwargs)

twitter_video_tools/utils/youtube_dl_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import Optional, Union
22

33
import yt_dlp
44

@@ -13,7 +13,7 @@ def _youtube_dl_download_video(self, link: str, youtube_dl_option: Optional[dict
1313
youtube_dl_downloader: yt_dlp.YoutubeDL
1414
youtube_dl_downloader.download([link])
1515

16-
def download(self, links: list[str], youtube_dl_option: Optional[dict[str, str]] = None) -> None:
16+
def download(self, links: list[str], youtube_dl_option: Optional[dict[str, Union[str, int]]] = None) -> None:
1717
arguments = [(link, youtube_dl_option) for link in links]
1818
execute_parallel(self._youtube_dl_download_video, arguments)
1919

0 commit comments

Comments
 (0)