[instagram] support '/reels/SHORTCODE' URLs (#8318)
This commit is contained in:
@@ -449,6 +449,27 @@ class InstagramExtractor(Extractor):
|
|||||||
user[key] = 0
|
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):
|
class InstagramUserExtractor(Dispatch, InstagramExtractor):
|
||||||
"""Extractor for an Instagram user profile"""
|
"""Extractor for an Instagram user profile"""
|
||||||
pattern = USER_PATTERN + r"/?(?:$|[?#])"
|
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():
|
class InstagramRestAPI():
|
||||||
|
|
||||||
def __init__(self, extractor):
|
def __init__(self, extractor):
|
||||||
|
|||||||
@@ -282,6 +282,11 @@ __tests__ = (
|
|||||||
"#class" : instagram.InstagramPostExtractor,
|
"#class" : instagram.InstagramPostExtractor,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"#url" : "https://www.instagram.com/reels/CDg_6Y1pxWu/",
|
||||||
|
"#class" : instagram.InstagramPostExtractor,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"#url" : "https://www.instagram.com/share/p/BACiUUUYQV",
|
"#url" : "https://www.instagram.com/share/p/BACiUUUYQV",
|
||||||
"#category": ("", "instagram", "post"),
|
"#category": ("", "instagram", "post"),
|
||||||
|
|||||||
Reference in New Issue
Block a user