diff --git a/bdfr/site_downloaders/redgifs.py b/bdfr/site_downloaders/redgifs.py index f7ea56a..26b9dfc 100644 --- a/bdfr/site_downloaders/redgifs.py +++ b/bdfr/site_downloaders/redgifs.py @@ -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 diff --git a/tests/site_downloaders/test_redgifs.py b/tests/site_downloaders/test_redgifs.py index a1f571e..b7ae3b3 100644 --- a/tests/site_downloaders/test_redgifs.py +++ b/tests/site_downloaders/test_redgifs.py @@ -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)