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

This commit is contained in:
Ali Parlakci
2021-05-15 14:35:16 +03:00
committed by Serene
parent aea30d2b44
commit c7a5ec4376
2 changed files with 22 additions and 3 deletions

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()