from __future__ import unicode_literals import os from urllib.parse import urlparse from yt_dlp import YoutubeDL class VideoDownloader: SUPPORTING_WEBSITES = [ "ok.ru", "vk.com", "www.youtube.com", "livejournal.com" ] BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DOWNLOAD_DIR = os.path.join(BASE_DIR, "downloads") BASE_YOUTUBE_DIR = os.path.join(BASE_DOWNLOAD_DIR, "Youtube") def __init__(self, link: str, ydl_opts: dict = None, username: str = None, password: str = None): self.link = link self.ydl_opts = ydl_opts self.username = username self.password = password def get_info(self): with YoutubeDL(self.ydl_opts if self.ydl_opts else {}) as ydl: return ydl.extract_info(self.link, download=False) def download(self): domain = urlparse(self.link).netloc # if domain not in self.SUPPORTING_WEBSITES: # raise SiteNotImplementedException with YoutubeDL(self.ydl_opts if self.ydl_opts else {}) as ydl: ydl.download([self.link]) result = ydl.extract_info(self.link, download=False) return result