handle download error

This commit is contained in:
simon 2022-05-24 10:18:33 +07:00
parent a7d9b4584b
commit 33f27f018f
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 4 additions and 6 deletions

View File

@ -4,8 +4,6 @@ functionality:
- handle yt-dlp errors - handle yt-dlp errors
""" """
from time import sleep
import yt_dlp import yt_dlp
@ -30,14 +28,14 @@ class YtWrap:
def download(self, url): def download(self, url):
"""make download request""" """make download request"""
with yt_dlp.YoutubeDL(self.obs) as ydl: with yt_dlp.YoutubeDL(self.obs) as ydl:
try: try:
ydl.download([url]) ydl.download([url])
except yt_dlp.utils.DownloadError: except yt_dlp.utils.DownloadError:
print(f"{url}: failed to download, retry...") print(f"{url}: failed to download.")
sleep(3) return False
ydl.download([url])
return True
def extract(self, url): def extract(self, url):
"""make extract request""" """make extract request"""