From 6d90783a2c85a14a250f427519dd76bd13eef5f9 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 4 Dec 2022 18:15:32 +0900 Subject: [PATCH] Update `VideoDownloader` download logic This commit changes download logic. Parallel downloading is enabled only when given link is multiple. --- twitter_video_tools/video_downloader.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/twitter_video_tools/video_downloader.py b/twitter_video_tools/video_downloader.py index c3967a1..3a45238 100644 --- a/twitter_video_tools/video_downloader.py +++ b/twitter_video_tools/video_downloader.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Optional +from typing import Optional, Union from twitter_video_tools.platform_video_downloader import \ PlatformVideoDownloader @@ -25,9 +25,14 @@ def __init__( self.password = password self.platform_video_downloader = platform_video_downloader - def download_videos(self, links: list[str]) -> None: - arguments = [(link, ) for link in links] - execute_parallel(self.download_video, arguments) + def download_videos(self, links: Union[str, list[str]]) -> None: + is_parallel_downloadable = isinstance(links, list) and len(links) > 1 + if is_parallel_downloadable: + arguments = [(link, ) for link in links] + execute_parallel(self.download_video, arguments) + return + link = links if isinstance(links, str) else links[0] + self.download_video(link) def download_video(self, link: str) -> None: if 'monsnode.com' in link: