Refactor method to base class

This commit is contained in:
Serene-Arc
2021-04-05 17:21:04 +10:00
committed by Ali Parlakci
parent 500cee4bae
commit 2384c03170
7 changed files with 28 additions and 40 deletions

View File

@@ -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')