Add error catch for youtube and site downloaders
This commit is contained in:
parent
9417e0cc04
commit
d977595bde
|
@ -314,15 +314,18 @@ class RedditDownloader:
|
|||
logger.error(f'Could not download submission {submission.name}: {e}')
|
||||
return
|
||||
|
||||
content = downloader.find_resources(self.authenticator)
|
||||
try:
|
||||
content = downloader.find_resources(self.authenticator)
|
||||
except errors.SiteDownloaderError:
|
||||
logger.error(f'Site {downloader_class.__name__} failed to download submission {submission.id}')
|
||||
return
|
||||
for destination, res in self.file_name_formatter.format_resource_paths(content, self.download_directory):
|
||||
if destination.exists():
|
||||
logger.warning(f'File already exists: {destination}')
|
||||
else:
|
||||
res.download()
|
||||
if res.hash.hexdigest() in self.master_hash_list and self.args.no_dupes:
|
||||
logger.warning(
|
||||
f'Resource from "{res.url}" and hash "{res.hash.hexdigest()}" downloaded elsewhere')
|
||||
logger.warning(f'Resource from "{res.url}" and hash "{res.hash.hexdigest()}" downloaded elsewhere')
|
||||
else:
|
||||
# TODO: consider making a hard link/symlink here
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue