Invert inheritance direction
This commit is contained in:
parent
3c6e9f6ccf
commit
760e59e1f7
3 changed files with 12 additions and 26 deletions
|
@ -10,10 +10,10 @@ from praw.models import Submission
|
||||||
from bdfr.exceptions import SiteDownloaderError
|
from bdfr.exceptions import SiteDownloaderError
|
||||||
from bdfr.resource import Resource
|
from bdfr.resource import Resource
|
||||||
from bdfr.site_authenticator import SiteAuthenticator
|
from bdfr.site_authenticator import SiteAuthenticator
|
||||||
from bdfr.site_downloaders.gif_delivery_network import GifDeliveryNetwork
|
from bdfr.site_downloaders.redgifs import Redgifs
|
||||||
|
|
||||||
|
|
||||||
class Gfycat(GifDeliveryNetwork):
|
class Gfycat(Redgifs):
|
||||||
def __init__(self, post: Submission):
|
def __init__(self, post: Submission):
|
||||||
super().__init__(post)
|
super().__init__(post)
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ class Gfycat(GifDeliveryNetwork):
|
||||||
url = 'https://gfycat.com/' + gfycat_id
|
url = 'https://gfycat.com/' + gfycat_id
|
||||||
|
|
||||||
response = Gfycat.retrieve_url(url)
|
response = Gfycat.retrieve_url(url)
|
||||||
if 'gifdeliverynetwork' in response.url:
|
if re.search(r'(redgifs|gifdeliverynetwork)', response.url):
|
||||||
return GifDeliveryNetwork._get_link(url)
|
return Redgifs._get_link(url)
|
||||||
|
|
||||||
soup = BeautifulSoup(response.text, 'html.parser')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
content = soup.find('script', attrs={'data-react-helmet': 'true', 'type': 'application/ld+json'})
|
content = soup.find('script', attrs={'data-react-helmet': 'true', 'type': 'application/ld+json'})
|
||||||
|
|
|
@ -1,36 +1,21 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import json
|
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from praw.models import Submission
|
from praw.models import Submission
|
||||||
|
|
||||||
from bdfr.exceptions import SiteDownloaderError
|
|
||||||
from bdfr.resource import Resource
|
from bdfr.resource import Resource
|
||||||
from bdfr.site_authenticator import SiteAuthenticator
|
from bdfr.site_authenticator import SiteAuthenticator
|
||||||
from bdfr.site_downloaders.base_downloader import BaseDownloader
|
from bdfr.site_downloaders.redgifs import Redgifs
|
||||||
|
|
||||||
|
|
||||||
class GifDeliveryNetwork(BaseDownloader):
|
class GifDeliveryNetwork(Redgifs):
|
||||||
def __init__(self, post: Submission):
|
def __init__(self, post: Submission):
|
||||||
super().__init__(post)
|
super().__init__(post)
|
||||||
|
|
||||||
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
||||||
media_url = self._get_link(self.post.url)
|
return super(GifDeliveryNetwork, self).find_resources(authenticator)
|
||||||
return [Resource(self.post, media_url, '.mp4')]
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_link(url: str) -> str:
|
def _get_link(url: str) -> str:
|
||||||
page = GifDeliveryNetwork.retrieve_url(url)
|
return super(GifDeliveryNetwork, GifDeliveryNetwork)._get_link(url)
|
||||||
|
|
||||||
soup = BeautifulSoup(page.text, 'html.parser')
|
|
||||||
content = soup.find('script', attrs={'data-react-helmet': 'true', 'type': 'application/ld+json'})
|
|
||||||
|
|
||||||
try:
|
|
||||||
content = json.loads(content.string)
|
|
||||||
out = content['video']['contentUrl']
|
|
||||||
except (json.JSONDecodeError, KeyError, TypeError, AttributeError):
|
|
||||||
raise SiteDownloaderError('Could not find source link')
|
|
||||||
|
|
||||||
return out
|
|
||||||
|
|
|
@ -10,15 +10,16 @@ from praw.models import Submission
|
||||||
from bdfr.exceptions import SiteDownloaderError
|
from bdfr.exceptions import SiteDownloaderError
|
||||||
from bdfr.resource import Resource
|
from bdfr.resource import Resource
|
||||||
from bdfr.site_authenticator import SiteAuthenticator
|
from bdfr.site_authenticator import SiteAuthenticator
|
||||||
from bdfr.site_downloaders.gif_delivery_network import GifDeliveryNetwork
|
from bdfr.site_downloaders.base_downloader import BaseDownloader
|
||||||
|
|
||||||
|
|
||||||
class Redgifs(GifDeliveryNetwork):
|
class Redgifs(BaseDownloader):
|
||||||
def __init__(self, post: Submission):
|
def __init__(self, post: Submission):
|
||||||
super().__init__(post)
|
super().__init__(post)
|
||||||
|
|
||||||
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
def find_resources(self, authenticator: Optional[SiteAuthenticator] = None) -> list[Resource]:
|
||||||
return super().find_resources(authenticator)
|
media_url = self._get_link(self.post.url)
|
||||||
|
return [Resource(self.post, media_url, '.mp4')]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_link(url: str) -> str:
|
def _get_link(url: str) -> str:
|
||||||
|
|
Loading…
Reference in a new issue