1
0
Fork 0
mirror of synced 2024-06-29 03:21:19 +12:00

Refactor Youtube downloader

This commit is contained in:
Serene-Arc 2021-03-01 14:50:31 +10:00 committed by Ali Parlakci
parent 62d99a9cad
commit ad3aeece07
2 changed files with 12 additions and 10 deletions

View file

@ -20,19 +20,20 @@ class Youtube(BaseDownloader):
super().__init__(post)
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
return [self._download_video()]
ytdl_options = {
"format": "best",
"playlistend": 1,
"nooverwrites": True,
}
out = self._download_video(ytdl_options)
return [out]
def _download_video(self) -> Resource:
def _download_video(self, ytdl_options: dict) -> Resource:
ytdl_options['quiet'] = True
with tempfile.TemporaryDirectory() as temp_dir:
download_path = Path(temp_dir).resolve()
ydl_opts = {
"format": "best",
"outtmpl": str(download_path) + '/' + 'test.%(ext)s',
"playlistend": 1,
"nooverwrites": True,
"quiet": True
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ytdl_options['outtmpl'] = str(download_path) + '/' + 'test.%(ext)s'
with youtube_dl.YoutubeDL(ytdl_options) as ydl:
ydl.download([self.post.url])
downloaded_file = list(download_path.iterdir())[0]

View file

@ -10,6 +10,7 @@ from bulkredditdownloader.site_downloaders.youtube import Youtube
@pytest.mark.online
@pytest.mark.reddit
@pytest.mark.long
@pytest.mark.parametrize(('test_submission_id', 'expected_hash'), (
('ltnoqp', '468136300a106c67f1463a7011a6db4a'),
))