2bafb1b99b
Consolidates sane flake8 settings to pyproject with the Flake8-pyproject plugin. Does not change logic of test workflow but allows base settings to live in pyproject for anyone using flake8 as an external linter (e.g. vscode) Also fixes some flake8 errors that were not being picked up by current testing, mostly unused imports.
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import logging
|
|
from typing import Optional
|
|
|
|
from praw.models import Submission
|
|
|
|
from bdfr.exceptions import NotADownloadableLinkError
|
|
from bdfr.resource import Resource
|
|
from bdfr.site_authenticator import SiteAuthenticator
|
|
from bdfr.site_downloaders.youtube import Youtube
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class VReddit(Youtube):
|
|
def __init__(self, post: Submission):
|
|
super().__init__(post)
|
|
|
|
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
|
ytdl_options = {
|
|
"playlistend": 1,
|
|
"nooverwrites": True,
|
|
}
|
|
download_function = self._download_video(ytdl_options)
|
|
extension = self.get_video_attributes(self.post.url)["ext"]
|
|
res = Resource(self.post, self.post.url, download_function, extension)
|
|
return [res]
|
|
|
|
@staticmethod
|
|
def get_video_attributes(url: str) -> dict:
|
|
result = VReddit.get_video_data(url)
|
|
if "ext" in result:
|
|
return result
|
|
else:
|
|
try:
|
|
result = result["entries"][0]
|
|
return result
|
|
except Exception as e:
|
|
logger.exception(e)
|
|
raise NotADownloadableLinkError(f"Video info extraction failed for {url}")
|