merge #7241: [instagram] handle '/share/' URLs

generated by the mobile app
This commit is contained in:
Mike Fährmann
2025-04-19 18:22:02 +02:00
2 changed files with 26 additions and 2 deletions

View File

@@ -707,11 +707,21 @@ class InstagramPostExtractor(InstagramExtractor):
"""Extractor for an Instagram post"""
subcategory = "post"
pattern = (r"(?:https?://)?(?:www\.)?instagram\.com"
r"/(?:[^/?#]+/)?(?:p|tv|reel)/([^/?#]+)")
r"/(?:share/()|[^/?#]+/)?(?:p|tv|reel)/([^/?#]+)")
example = "https://www.instagram.com/p/abcdefg/"
def posts(self):
return self.api.media(self.item)
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():

View File

@@ -277,4 +277,18 @@ __tests__ = (
"#class" : instagram.InstagramPostExtractor,
},
{
"#url" : "https://www.instagram.com/share/p/BACiUUUYQV",
"#category": ("", "instagram", "post"),
"#class" : instagram.InstagramPostExtractor,
"shortcode" : "C6q-XdvsU5v",
},
{
"#url" : "https://www.instagram.com/share/reel/BARSSL4rTu",
"#category": ("", "instagram", "post"),
"#class" : instagram.InstagramPostExtractor,
"shortcode" : "DHbVbT4Jx0c",
}
)