bug(youtube.dl): Fix crash on zero downloads #375

This commit is contained in:
Ali Parlakci authored and Serene committed 2021-05-16 11:06:13 +10:00
1 parent aea30d2b44
commit c7a5ec4376
2 files changed
+22 -3

No files matched your search

+7 -2
View File
@@ -8,7 +8,7 @@ from typing import Optional
import youtube_dl
from praw.models import Submission
from bdfr.exceptions import SiteDownloaderError
from bdfr.exceptions import (NotADownloadableLinkError, SiteDownloaderError)
from bdfr.resource import Resource
from bdfr.site_authenticator import SiteAuthenticator
from bdfr.site_downloaders.base_downloader import BaseDownloader
@@ -43,7 +43,12 @@ class Youtube(BaseDownloader):
except youtube_dl.DownloadError as e:
raise SiteDownloaderError(f'Youtube download failed: {e}')
downloaded_file = list(download_path.iterdir())[0]
downloaded_file = None
downloaded_files = list(download_path.iterdir())
if len(downloaded_files) > 0:
downloaded_file = downloaded_files[0]
else:
raise NotADownloadableLinkError(f"No media exists in the URL {self.post.url}")
extension = downloaded_file.suffix
with open(downloaded_file, 'rb') as file:
content = file.read()