Refactor Youtube downloader
This commit is contained in:
parent
62d99a9cad
commit
ad3aeece07
2 changed files with 12 additions and 10 deletions
|
@ -20,19 +20,20 @@ class Youtube(BaseDownloader):
|
|||
super().__init__(post)
|
||||
|
||||
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
||||
return [self._download_video()]
|
||||
|
||||
def _download_video(self) -> Resource:
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
download_path = Path(temp_dir).resolve()
|
||||
ydl_opts = {
|
||||
ytdl_options = {
|
||||
"format": "best",
|
||||
"outtmpl": str(download_path) + '/' + 'test.%(ext)s',
|
||||
"playlistend": 1,
|
||||
"nooverwrites": True,
|
||||
"quiet": True
|
||||
}
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
out = self._download_video(ytdl_options)
|
||||
return [out]
|
||||
|
||||
def _download_video(self, ytdl_options: dict) -> Resource:
|
||||
ytdl_options['quiet'] = True
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
download_path = Path(temp_dir).resolve()
|
||||
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]
|
||||
|
|
|
@ -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'),
|
||||
))
|
||||
|
|
Loading…
Reference in a new issue