diff --git a/gallery_dl/extractor/instagram.py b/gallery_dl/extractor/instagram.py index 24d12cb7..8c2a3e6b 100644 --- a/gallery_dl/extractor/instagram.py +++ b/gallery_dl/extractor/instagram.py @@ -449,6 +449,27 @@ class InstagramExtractor(Extractor): user[key] = 0 +class InstagramPostExtractor(InstagramExtractor): + """Extractor for an Instagram post""" + subcategory = "post" + pattern = (r"(?:https?://)?(?:www\.)?instagram\.com" + r"/(?:share/()|[^/?#]+/)?(?:p|tv|reels?)/([^/?#]+)") + example = "https://www.instagram.com/p/abcdefg/" + + def posts(self): + share, shortcode = self.groups + if share is not None: + url = text.ensure_http_scheme(self.url) + headers = { + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "navigate", + "Sec-Fetch-Site": "same-origin", + } + location = self.request_location(url, headers=headers) + shortcode = location.split("/")[-2] + return self.api.media(shortcode) + + class InstagramUserExtractor(Dispatch, InstagramExtractor): """Extractor for an Instagram user profile""" pattern = USER_PATTERN + r"/?(?:$|[?#])" @@ -746,27 +767,6 @@ class InstagramAvatarExtractor(InstagramExtractor): },) -class InstagramPostExtractor(InstagramExtractor): - """Extractor for an Instagram post""" - subcategory = "post" - pattern = (r"(?:https?://)?(?:www\.)?instagram\.com" - r"/(?:share/()|[^/?#]+/)?(?:p|tv|reel)/([^/?#]+)") - example = "https://www.instagram.com/p/abcdefg/" - - def posts(self): - share, shortcode = self.groups - if share is not None: - url = text.ensure_http_scheme(self.url) - headers = { - "Sec-Fetch-Dest": "empty", - "Sec-Fetch-Mode": "navigate", - "Sec-Fetch-Site": "same-origin", - } - location = self.request_location(url, headers=headers) - shortcode = location.split("/")[-2] - return self.api.media(shortcode) - - class InstagramRestAPI(): def __init__(self, extractor): diff --git a/test/results/instagram.py b/test/results/instagram.py index bf4eb2c9..300d6039 100644 --- a/test/results/instagram.py +++ b/test/results/instagram.py @@ -282,6 +282,11 @@ __tests__ = ( "#class" : instagram.InstagramPostExtractor, }, +{ + "#url" : "https://www.instagram.com/reels/CDg_6Y1pxWu/", + "#class" : instagram.InstagramPostExtractor, +}, + { "#url" : "https://www.instagram.com/share/p/BACiUUUYQV", "#category": ("", "instagram", "post"),