Fix Redgifs module
This commit is contained in:
parent
cd6bcd82ef
commit
d60b4e7fdd
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
import urllib.parse
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from praw.models import Submission
|
from praw.models import Submission
|
||||||
|
@ -61,4 +62,14 @@ class Redgifs(BaseDownloader):
|
||||||
except (KeyError, AttributeError):
|
except (KeyError, AttributeError):
|
||||||
raise SiteDownloaderError('Failed to find JSON data in page')
|
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
|
return out
|
||||||
|
|
|
@ -12,20 +12,20 @@ from bdfr.site_downloaders.redgifs import Redgifs
|
||||||
@pytest.mark.online
|
@pytest.mark.online
|
||||||
@pytest.mark.parametrize(('test_url', 'expected'), (
|
@pytest.mark.parametrize(('test_url', 'expected'), (
|
||||||
('https://redgifs.com/watch/frighteningvictorioussalamander',
|
('https://redgifs.com/watch/frighteningvictorioussalamander',
|
||||||
{'https://thumbs2.redgifs.com/FrighteningVictoriousSalamander.mp4'}),
|
{'https://thumbs3.redgifs.com/FrighteningVictoriousSalamander.mp4'}),
|
||||||
('https://redgifs.com/watch/springgreendecisivetaruca',
|
('https://redgifs.com/watch/springgreendecisivetaruca',
|
||||||
{'https://thumbs2.redgifs.com/SpringgreenDecisiveTaruca.mp4'}),
|
{'https://thumbs3.redgifs.com/SpringgreenDecisiveTaruca.mp4'}),
|
||||||
('https://www.redgifs.com/watch/palegoldenrodrawhalibut',
|
('https://www.redgifs.com/watch/palegoldenrodrawhalibut',
|
||||||
{'https://thumbs2.redgifs.com/PalegoldenrodRawHalibut.mp4'}),
|
{'https://thumbs3.redgifs.com/PalegoldenrodRawHalibut.mp4'}),
|
||||||
('https://redgifs.com/watch/hollowintentsnowyowl',
|
('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://www.redgifs.com/watch/lustrousstickywaxwing',
|
||||||
{'https://thumbs2.redgifs.com/EntireEnchantingHypsilophodon-large.jpg',
|
{'https://thumbs3.redgifs.com/EntireEnchantingHypsilophodon-large.jpg',
|
||||||
'https://thumbs2.redgifs.com/FancyMagnificentAdamsstaghornedbeetle-large.jpg',
|
'https://thumbs3.redgifs.com/FancyMagnificentAdamsstaghornedbeetle-large.jpg',
|
||||||
'https://thumbs2.redgifs.com/LustrousStickyWaxwing-large.jpg',
|
'https://thumbs3.redgifs.com/LustrousStickyWaxwing-large.jpg',
|
||||||
'https://thumbs2.redgifs.com/ParchedWindyArmyworm-large.jpg',
|
'https://thumbs3.redgifs.com/ParchedWindyArmyworm-large.jpg',
|
||||||
'https://thumbs2.redgifs.com/ThunderousColorlessErmine-large.jpg',
|
'https://thumbs3.redgifs.com/ThunderousColorlessErmine-large.jpg',
|
||||||
'https://thumbs2.redgifs.com/UnripeUnkemptWoodpecker-large.jpg'}),
|
'https://thumbs3.redgifs.com/UnripeUnkemptWoodpecker-large.jpg'}),
|
||||||
))
|
))
|
||||||
def test_get_link(test_url: str, expected: set[str]):
|
def test_get_link(test_url: str, expected: set[str]):
|
||||||
result = Redgifs._get_link(test_url)
|
result = Redgifs._get_link(test_url)
|
||||||
|
|
Loading…
Reference in a new issue