[imgur] fix extraction

This commit is contained in:
Mort Yao 2024-05-20 04:56:36 +02:00
parent 7f8ebe1c93
commit 0b9fec5251
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251
2 changed files with 6 additions and 3 deletions

View File

@ -13,9 +13,11 @@ class Imgur(VideoExtractor):
] ]
def prepare(self, **kwargs): def prepare(self, **kwargs):
self.ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/123.0.2420.97'
if re.search(r'imgur\.com/a/', self.url): if re.search(r'imgur\.com/a/', self.url):
# album # album
content = get_content(self.url) content = get_content(self.url, headers=fake_headers)
album = match1(content, r'album\s*:\s*({.*}),') or \ album = match1(content, r'album\s*:\s*({.*}),') or \
match1(content, r'image\s*:\s*({.*}),') match1(content, r'image\s*:\s*({.*}),')
album = json.loads(album) album = json.loads(album)
@ -51,10 +53,10 @@ class Imgur(VideoExtractor):
else: else:
# gallery image # gallery image
content = get_content(self.url) content = get_content(self.url, headers=fake_headers)
url = match1(content, r'meta property="og:video"[^>]+(https?://i.imgur.com/[^"?]+)') or \ url = match1(content, r'meta property="og:video"[^>]+(https?://i.imgur.com/[^"?]+)') or \
match1(content, r'meta property="og:image"[^>]+(https?://i.imgur.com/[^"?]+)') match1(content, r'meta property="og:image"[^>]+(https?://i.imgur.com/[^"?]+)')
_, container, size = url_info(url, faker=True) _, container, size = url_info(url, headers={'User-Agent': fake_headers['User-Agent']})
self.streams = { self.streams = {
'original': { 'original': {
'src': [url], 'src': [url],

View File

@ -19,6 +19,7 @@ from you_get.extractors import (
class YouGetTests(unittest.TestCase): class YouGetTests(unittest.TestCase):
def test_imgur(self): def test_imgur(self):
imgur.download('http://imgur.com/WVLk5nD', info_only=True) imgur.download('http://imgur.com/WVLk5nD', info_only=True)
imgur.download('https://imgur.com/we-should-have-listened-WVLk5nD', info_only=True)
def test_magisto(self): def test_magisto(self):
magisto.download( magisto.download(