yt-dlp base class

This commit is contained in:
simon 2022-05-24 08:53:05 +07:00
parent 1fd9981273
commit 37e6f8656a
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
"""
functionality:
- base class to make all calls to yt-dlp
- handle yt-dlp errors
"""
from time import sleep
import yt_dlp
class YtWrap:
"""wrap calls to yt"""
def __init__(self, obs):
self.obs = obs
def download(self, url):
"""make download request"""
with yt_dlp.YoutubeDL(self.obs) as ydl:
try:
ydl.download([url])
except yt_dlp.utils.DownloadError:
print(f"{url}: failed to download, retry...")
sleep(3)
ydl.download([url])
def extract(self, url):
"""make extract request"""
response = yt_dlp.YoutubeDL(self.obs).extract_info(url)
return response