Skip to content

Commit

Permalink
[imgur] fix extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
soimort committed May 20, 2024
1 parent 7f8ebe1 commit 0b9fec5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/you_get/extractors/imgur.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0b9fec5

Please sign in to comment.