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:
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
import json
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from praw.models import Submission
|
from praw.models import Submission
|
||||||
@@ -24,13 +25,12 @@ class GifDeliveryNetwork(BaseDownloader):
|
|||||||
page = GifDeliveryNetwork.retrieve_url(url)
|
page = GifDeliveryNetwork.retrieve_url(url)
|
||||||
|
|
||||||
soup = BeautifulSoup(page.text, 'html.parser')
|
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:
|
try:
|
||||||
out = content['src']
|
content = json.loads(content.string)
|
||||||
if not out:
|
out = content['video']['contentUrl']
|
||||||
raise KeyError
|
except (json.JSONDecodeError, KeyError, TypeError):
|
||||||
except KeyError:
|
|
||||||
raise SiteDownloaderError('Could not find source link')
|
raise SiteDownloaderError('Could not find source link')
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|||||||
Reference in New Issue
Block a user