Refactor method to base class
This commit is contained in:
@@ -4,7 +4,6 @@ import json
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from praw.models import Submission
|
||||
|
||||
@@ -22,19 +21,14 @@ class Gfycat(GifDeliveryNetwork):
|
||||
|
||||
@staticmethod
|
||||
def _get_link(url: str) -> str:
|
||||
if re.match(r'\.(webm|mp4|gif)$', url):
|
||||
return url
|
||||
|
||||
gfycat_id = re.match(r'.*/(.*?)/?$', url).group(1)
|
||||
url = 'https://gfycat.com/' + gfycat_id
|
||||
|
||||
response = requests.get(url)
|
||||
page_source = response.text
|
||||
|
||||
response = Gfycat.get_link(url)
|
||||
if 'gifdeliverynetwork' in response.url:
|
||||
return GifDeliveryNetwork._get_link(url)
|
||||
|
||||
soup = BeautifulSoup(page_source, 'html.parser')
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
content = soup.find('script', attrs={'data-react-helmet': 'true', 'type': 'application/ld+json'})
|
||||
|
||||
out = json.loads(content.contents[0]).get('video').get('contentUrl')
|
||||
|
||||
Reference in New Issue
Block a user