From 2eab4052c58110417dbcfd5972c4ec52da21dd61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=20Parlak=C3=A7=C4=B1?= Date: Thu, 22 Apr 2021 10:07:05 +0300 Subject: [PATCH] Fix GifDeliveryNetwork link algorithm (#298) * Catch additional error when parsing site * Fix GifDeliveryNetwork link algorithm Co-authored-by: Serene-Arc --- bdfr/site_downloaders/gif_delivery_network.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bdfr/site_downloaders/gif_delivery_network.py b/bdfr/site_downloaders/gif_delivery_network.py index 2a7f726..dbe2cf5 100644 --- a/bdfr/site_downloaders/gif_delivery_network.py +++ b/bdfr/site_downloaders/gif_delivery_network.py @@ -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