added link
This commit is contained in:
		@@ -1,4 +1,8 @@
 | 
			
		||||
from __future__ import unicode_literals
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
import uuid
 | 
			
		||||
from datetime import datetime
 | 
			
		||||
from urllib.parse import urlparse
 | 
			
		||||
 | 
			
		||||
import youtube_dl
 | 
			
		||||
@@ -7,15 +11,25 @@ from src.exceptions.download_exceptions import SiteNotImplementedException
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class VideoDownloader:
 | 
			
		||||
    SUPPORTING_WEBSITES = [
 | 
			
		||||
        "ok.ru", "vk.com", "www.youtube.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
 | 
			
		||||
 | 
			
		||||
        self.SUPPORTING_WEBSITES = [
 | 
			
		||||
            "ok.ru", "vk.com", "www.youtube.com"
 | 
			
		||||
        ]
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def get_unique_video_filename():
 | 
			
		||||
        prefix = f'vid_{datetime.now().strftime("%Y%m%d%H%M%S")}'
 | 
			
		||||
        random_uuid4 = uuid.uuid4().hex[:8]
 | 
			
		||||
        filename = f"{prefix}_{random_uuid4}"
 | 
			
		||||
        return filename
 | 
			
		||||
 | 
			
		||||
    def download(self):
 | 
			
		||||
        domain = urlparse(self.link).netloc
 | 
			
		||||
@@ -25,5 +39,4 @@ class VideoDownloader:
 | 
			
		||||
        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
 | 
			
		||||
            return result
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user