[instagram] support '/share/SHORTCODE' URLs (#8340)

i.e. "bare" /share/ links
This commit is contained in:
Mike Fährmann
2025-10-03 22:26:45 +02:00
parent 4d9b30bcb0
commit c609a3181b
3 changed files with 15 additions and 5 deletions

View File

@@ -436,7 +436,8 @@ class InstagramExtractor(Extractor):
return cursor return cursor
def _update_cursor(self, cursor): def _update_cursor(self, cursor):
self.log.debug("Cursor: %s", cursor) if cursor:
self.log.debug("Cursor: %s", cursor)
self._cursor = cursor self._cursor = cursor
return cursor return cursor
@@ -461,16 +462,18 @@ class InstagramPostExtractor(InstagramExtractor):
"""Extractor for an Instagram post""" """Extractor for an Instagram post"""
subcategory = "post" subcategory = "post"
pattern = (r"(?:https?://)?(?:www\.)?instagram\.com" pattern = (r"(?:https?://)?(?:www\.)?instagram\.com"
r"/(?:share/()|[^/?#]+/)?(?:p|tv|reels?())/([^/?#]+)") r"/(?:share()(?:/(?:p|tv|reels?()))?"
r"|(?:[^/?#]+/)?(?:p|tv|reels?()))"
r"/([^/?#]+)")
example = "https://www.instagram.com/p/abcdefg/" example = "https://www.instagram.com/p/abcdefg/"
def __init__(self, match): def __init__(self, match):
if match[2] is not None: if match[2] is not None or match[3] is not None:
self.subcategory = "reel" self.subcategory = "reel"
InstagramExtractor.__init__(self, match) InstagramExtractor.__init__(self, match)
def posts(self): def posts(self):
share, reel, shortcode = self.groups share, _, _, shortcode = self.groups
if share is not None: if share is not None:
url = text.ensure_http_scheme(self.url) url = text.ensure_http_scheme(self.url)
headers = { headers = {

View File

@@ -6,5 +6,5 @@
# it under the terms of the GNU General Public License version 2 as # it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation. # published by the Free Software Foundation.
__version__ = "1.30.9" __version__ = "1.31.0-dev"
__variant__ = None __variant__ = None

View File

@@ -288,6 +288,13 @@ __tests__ = (
"#class" : instagram.InstagramPostExtractor, "#class" : instagram.InstagramPostExtractor,
}, },
{
"#url" : "https://www.instagram.com/share/BACiUUUYQV",
"#category": ("", "instagram", "post"),
"#class" : instagram.InstagramPostExtractor,
"shortcode" : "C6q-XdvsU5v",
},
{ {
"#url" : "https://www.instagram.com/share/p/BACiUUUYQV", "#url" : "https://www.instagram.com/share/p/BACiUUUYQV",
"#category": ("", "instagram", "post"), "#category": ("", "instagram", "post"),