Skip to content

Commit 4b11c72

Browse files
committed
merge #7241: [instagram] handle '/share/' URLs
generated by the mobile app
2 parents 2798fb8 + e6f4dcf commit 4b11c72

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

gallery_dl/extractor/instagram.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,21 @@ class InstagramPostExtractor(InstagramExtractor):
707707
"""Extractor for an Instagram post"""
708708
subcategory = "post"
709709
pattern = (r"(?:https?://)?(?:www\.)?instagram\.com"
710-
r"/(?:[^/?#]+/)?(?:p|tv|reel)/([^/?#]+)")
710+
r"/(?:share/()|[^/?#]+/)?(?:p|tv|reel)/([^/?#]+)")
711711
example = "https://www.instagram.com/p/abcdefg/"
712712

713713
def posts(self):
714-
return self.api.media(self.item)
714+
share, shortcode = self.groups
715+
if share is not None:
716+
url = text.ensure_http_scheme(self.url)
717+
headers = {
718+
"Sec-Fetch-Dest": "empty",
719+
"Sec-Fetch-Mode": "navigate",
720+
"Sec-Fetch-Site": "same-origin",
721+
}
722+
location = self.request_location(url, headers=headers)
723+
shortcode = location.split("/")[-2]
724+
return self.api.media(shortcode)
715725

716726

717727
class InstagramRestAPI():

test/results/instagram.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,18 @@
277277
"#class" : instagram.InstagramPostExtractor,
278278
},
279279

280+
{
281+
"#url" : "https://www.instagram.com/share/p/BACiUUUYQV",
282+
"#category": ("", "instagram", "post"),
283+
"#class" : instagram.InstagramPostExtractor,
284+
"shortcode" : "C6q-XdvsU5v",
285+
},
286+
287+
{
288+
"#url" : "https://www.instagram.com/share/reel/BARSSL4rTu",
289+
"#category": ("", "instagram", "post"),
290+
"#class" : instagram.InstagramPostExtractor,
291+
"shortcode" : "DHbVbT4Jx0c",
292+
}
293+
280294
)

0 commit comments

Comments
 (0)