2021-05-02 21:48:25 +12:00
|
|
|
#!/usr/bin/env python3
|
2022-12-20 12:32:37 +13:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-05-02 21:48:25 +12:00
|
|
|
|
|
|
|
import logging
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from praw.models import Submission
|
|
|
|
|
2021-11-21 14:48:29 +13:00
|
|
|
from bdfr.exceptions import NotADownloadableLinkError
|
2021-05-02 21:48:25 +12:00
|
|
|
from bdfr.resource import Resource
|
|
|
|
from bdfr.site_authenticator import SiteAuthenticator
|
2022-12-03 18:20:32 +13:00
|
|
|
from bdfr.site_downloaders.fallback_downloaders.fallback_downloader import BaseFallbackDownloader
|
2021-05-02 21:48:25 +12:00
|
|
|
from bdfr.site_downloaders.youtube import Youtube
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2021-11-24 13:40:18 +13:00
|
|
|
class YtdlpFallback(BaseFallbackDownloader, Youtube):
|
2021-05-02 21:48:25 +12:00
|
|
|
def __init__(self, post: Submission):
|
2021-11-24 13:40:18 +13:00
|
|
|
super(YtdlpFallback, self).__init__(post)
|
2021-05-02 21:48:25 +12:00
|
|
|
|
|
|
|
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
2021-07-27 15:39:49 +12:00
|
|
|
out = Resource(
|
|
|
|
self.post,
|
|
|
|
self.post.url,
|
|
|
|
super()._download_video({}),
|
2022-12-03 18:11:17 +13:00
|
|
|
super().get_video_attributes(self.post.url)["ext"],
|
2021-07-27 15:39:49 +12:00
|
|
|
)
|
2021-05-02 21:48:25 +12:00
|
|
|
return [out]
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def can_handle_link(url: str) -> bool:
|
2021-11-21 14:48:29 +13:00
|
|
|
try:
|
2021-11-24 13:40:18 +13:00
|
|
|
attributes = YtdlpFallback.get_video_attributes(url)
|
2021-11-21 14:48:29 +13:00
|
|
|
except NotADownloadableLinkError:
|
|
|
|
return False
|
2021-07-27 15:39:49 +12:00
|
|
|
if attributes:
|
|
|
|
return True
|