[instagram] support '/reels/SHORTCODE' URLs (#8318)

This commit is contained in:
Mike Fährmann
2025-10-01 08:14:49 +02:00
parent 602c84e1fa
commit 329ac4099d
2 changed files with 26 additions and 21 deletions

View File

@@ -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):