1
0
Fork 0
mirror of synced 2024-05-19 11:42:40 +12:00

Fix Redgifs module

This commit is contained in:
Serene-Arc 2022-09-01 11:19:07 +10:00
parent cd6bcd82ef
commit d60b4e7fdd
2 changed files with 21 additions and 10 deletions

View file

@ -2,6 +2,7 @@
import json
import re
import urllib.parse
from typing import Optional
from praw.models import Submission
@ -61,4 +62,14 @@ class Redgifs(BaseDownloader):
except (KeyError, AttributeError):
raise SiteDownloaderError('Failed to find JSON data in page')
# returned domain seems to be being phased out
out = {re.sub('thumbs2', 'thumbs3', link) for link in out}
out = {Redgifs._clean_thumbs4_link(link) for link in out}
return out
@staticmethod
def _clean_thumbs4_link(url: str) -> str:
split_url = urllib.parse.urlsplit(url)
out = split_url.scheme + '://' + split_url.netloc + split_url.path
out = re.sub('thumbs4', 'thumbs3', out)
return out

View file

@ -12,20 +12,20 @@ from bdfr.site_downloaders.redgifs import Redgifs
@pytest.mark.online
@pytest.mark.parametrize(('test_url', 'expected'), (
('https://redgifs.com/watch/frighteningvictorioussalamander',
{'https://thumbs2.redgifs.com/FrighteningVictoriousSalamander.mp4'}),
{'https://thumbs3.redgifs.com/FrighteningVictoriousSalamander.mp4'}),
('https://redgifs.com/watch/springgreendecisivetaruca',
{'https://thumbs2.redgifs.com/SpringgreenDecisiveTaruca.mp4'}),
{'https://thumbs3.redgifs.com/SpringgreenDecisiveTaruca.mp4'}),
('https://www.redgifs.com/watch/palegoldenrodrawhalibut',
{'https://thumbs2.redgifs.com/PalegoldenrodRawHalibut.mp4'}),
{'https://thumbs3.redgifs.com/PalegoldenrodRawHalibut.mp4'}),
('https://redgifs.com/watch/hollowintentsnowyowl',
{'https://thumbs2.redgifs.com/HollowIntentSnowyowl-large.jpg'}),
{'https://thumbs3.redgifs.com/HollowIntentSnowyowl-large.jpg'}),
('https://www.redgifs.com/watch/lustrousstickywaxwing',
{'https://thumbs2.redgifs.com/EntireEnchantingHypsilophodon-large.jpg',
'https://thumbs2.redgifs.com/FancyMagnificentAdamsstaghornedbeetle-large.jpg',
'https://thumbs2.redgifs.com/LustrousStickyWaxwing-large.jpg',
'https://thumbs2.redgifs.com/ParchedWindyArmyworm-large.jpg',
'https://thumbs2.redgifs.com/ThunderousColorlessErmine-large.jpg',
'https://thumbs2.redgifs.com/UnripeUnkemptWoodpecker-large.jpg'}),
{'https://thumbs3.redgifs.com/EntireEnchantingHypsilophodon-large.jpg',
'https://thumbs3.redgifs.com/FancyMagnificentAdamsstaghornedbeetle-large.jpg',
'https://thumbs3.redgifs.com/LustrousStickyWaxwing-large.jpg',
'https://thumbs3.redgifs.com/ParchedWindyArmyworm-large.jpg',
'https://thumbs3.redgifs.com/ThunderousColorlessErmine-large.jpg',
'https://thumbs3.redgifs.com/UnripeUnkemptWoodpecker-large.jpg'}),
))
def test_get_link(test_url: str, expected: set[str]):
result = Redgifs._get_link(test_url)