From c6a23c26d740e038b1c9dcfb6df6a094ec6e83a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 11 Dec 2021 21:34:25 +0100 Subject: [PATCH] [instagram] allow downloading specific stories (closes #2088) https://instagram.com/stories// now only downloads the one story specified by and not all stories from that user. --- gallery_dl/extractor/instagram.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gallery_dl/extractor/instagram.py b/gallery_dl/extractor/instagram.py index 2cb86087..e6b90d1c 100644 --- a/gallery_dl/extractor/instagram.py +++ b/gallery_dl/extractor/instagram.py @@ -689,14 +689,15 @@ class InstagramStoriesExtractor(InstagramExtractor): """Extractor for Instagram stories""" subcategory = "stories" pattern = (r"(?:https?://)?(?:www\.)?instagram\.com" - r"/stories/(?:highlights/(\d+)|([^/?#]+))") + r"/stories/(?:highlights/(\d+)|([^/?#]+)(?:/(\d+))?)") test = ( ("https://www.instagram.com/stories/instagram/"), ("https://www.instagram.com/stories/highlights/18042509488170095/"), + ("https://instagram.com/stories/geekmig/2724343156064789461"), ) def __init__(self, match): - self.highlight_id, self.user = match.groups() + self.highlight_id, self.user, self.media_id = match.groups() if self.highlight_id: self.subcategory = InstagramHighlightsExtractor.subcategory InstagramExtractor.__init__(self, match) @@ -715,7 +716,18 @@ class InstagramStoriesExtractor(InstagramExtractor): endpoint = "/v1/feed/reels_media/" params = {"reel_ids": reel_id} - return self._request_api(endpoint, params=params)["reels"].values() + reels = self._request_api(endpoint, params=params)["reels"] + + if self.media_id: + reel = reels[reel_id] + for item in reel["items"]: + if item["pk"] == self.media_id: + reel["items"] = (item,) + break + else: + raise exception.NotFoundError("story") + + return reels.values() class InstagramHighlightsExtractor(InstagramExtractor):