Add error catch for youtube and site downloaders

This commit is contained in:
Serene-Arc
2021-03-13 12:01:30 +10:00
committed by Ali Parlakci
parent 9417e0cc04
commit d977595bde
2 changed files with 12 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ from typing import Optional
import youtube_dl
from praw.models import Submission
from bulkredditdownloader.exceptions import SiteDownloaderError
from bulkredditdownloader.resource import Resource
from bulkredditdownloader.site_authenticator import SiteAuthenticator
from bulkredditdownloader.site_downloaders.base_downloader import BaseDownloader
@@ -33,8 +34,11 @@ class Youtube(BaseDownloader):
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])
try:
with youtube_dl.YoutubeDL(ytdl_options) as ydl:
ydl.download([self.post.url])
except youtube_dl.DownloadError as e:
raise SiteDownloaderError(f'Youtube download failed: {e}')
downloaded_file = list(download_path.iterdir())[0]
extension = downloaded_file.suffix