1
0
Fork 0
mirror of synced 2024-06-02 18:34:37 +12:00

Fix GifDeliveryNetwork link algorithm (#298)

* Catch additional error when parsing site

* Fix GifDeliveryNetwork link algorithm

Co-authored-by: Serene-Arc <serenical@gmail.com>
This commit is contained in:
Ali Parlakçı 2021-04-22 10:07:05 +03:00 committed by GitHub
parent 1c4cfbb580
commit 2eab4052c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3
from typing import Optional
import json
from bs4 import BeautifulSoup
from praw.models import Submission
@ -24,13 +25,12 @@ class GifDeliveryNetwork(BaseDownloader):
page = GifDeliveryNetwork.retrieve_url(url)
soup = BeautifulSoup(page.text, 'html.parser')
content = soup.find('source', attrs={'id': 'mp4Source', 'type': 'video/mp4'})
content = soup.find('script', attrs={'data-react-helmet': 'true', 'type': 'application/ld+json'})
try:
out = content['src']
if not out:
raise KeyError
except KeyError:
content = json.loads(content.string)
out = content['video']['contentUrl']
except (json.JSONDecodeError, KeyError, TypeError):
raise SiteDownloaderError('Could not find source link')
return out