From 0b9fec525152ef1c705864245970925c64a65872 Mon Sep 17 00:00:00 2001 From: Mort Yao Date: Mon, 20 May 2024 04:56:36 +0200 Subject: [PATCH] [imgur] fix extraction --- src/you_get/extractors/imgur.py | 8 +++++--- tests/test.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/you_get/extractors/imgur.py b/src/you_get/extractors/imgur.py index 09395202ae..2726c97439 100644 --- a/src/you_get/extractors/imgur.py +++ b/src/you_get/extractors/imgur.py @@ -13,9 +13,11 @@ class Imgur(VideoExtractor): ] 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): # album - content = get_content(self.url) + content = get_content(self.url, headers=fake_headers) album = match1(content, r'album\s*:\s*({.*}),') or \ match1(content, r'image\s*:\s*({.*}),') album = json.loads(album) @@ -51,10 +53,10 @@ def prepare(self, **kwargs): else: # 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 \ 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 = { 'original': { 'src': [url], diff --git a/tests/test.py b/tests/test.py index a8c7023d0f..d3cd099d4b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -19,6 +19,7 @@ class YouGetTests(unittest.TestCase): def test_imgur(self): 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): magisto.download(