initial commit

This commit is contained in:
2023-08-12 13:06:41 +03:00
committed by nikili0n
commit 9fa692d9ad
10 changed files with 631 additions and 0 deletions

29
src/core/ydl.py Normal file
View File

@ -0,0 +1,29 @@
from __future__ import unicode_literals
from urllib.parse import urlparse
import youtube_dl
from src.exceptions.download_exceptions import SiteNotImplementedException
class VideoDownloader:
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
self.SUPPORTING_WEBSITES = [
"ok.ru", "vk.com", "www.youtube.com"
]
def download(self):
domain = urlparse(self.link).netloc
if domain not in self.SUPPORTING_WEBSITES:
raise SiteNotImplementedException
with youtube_dl.YoutubeDL(self.ydl_opts if self.ydl_opts else {}) as ydl:
ydl.download([self.link])
result = ydl.extract_info(self.link, download=False)
url = result['formats'][-1]
return url