From 188824c47981cc17939228ab647a9fbc4cc302ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 28 Aug 2025 10:51:33 +0200 Subject: [PATCH] [instagram] add 'stories-tray' extractor (#6582) https://github.com/mikf/gallery-dl/issues/6582#issuecomment-3230919124 --- docs/supportedsites.md | 2 +- gallery_dl/extractor/instagram.py | 20 +++++++++++++++++++- scripts/supportedsites.py | 1 + test/results/instagram.py | 5 +++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/supportedsites.md b/docs/supportedsites.md index 6b368034..e511993f 100644 --- a/docs/supportedsites.md +++ b/docs/supportedsites.md @@ -460,7 +460,7 @@ Consider all listed sites to potentially be NSFW. Instagram https://www.instagram.com/ - Avatars, Collections, Followers, Followed Users, Guides, Highlights, User Profile Information, Posts, Reels, Saved Posts, Stories, Tag Searches, Tagged Posts, User Profiles + Avatars, Collections, Followers, Followed Users, Guides, Highlights, User Profile Information, Posts, Reels, Saved Posts, Stories, Stories Home Tray, Tag Searches, Tagged Posts, User Profiles Cookies diff --git a/gallery_dl/extractor/instagram.py b/gallery_dl/extractor/instagram.py index fa60f910..b19d8bc7 100644 --- a/gallery_dl/extractor/instagram.py +++ b/gallery_dl/extractor/instagram.py @@ -568,6 +568,20 @@ class InstagramCollectionExtractor(InstagramExtractor): return self.api.user_collection(self.collection_id) +class InstagramStoriesTrayExtractor(InstagramExtractor): + """Extractor for your Instagram account's stories tray""" + subcategory = "stories-tray" + pattern = rf"{BASE_PATTERN}/stories/me/?$()" + example = "https://www.instagram.com/stories/me/" + + def items(self): + base = f"{self.root}/stories/id:" + for story in self.api.reels_tray(): + story["date"] = text.parse_timestamp(story["latest_reel_media"]) + story["_extractor"] = InstagramStoriesExtractor + yield Message.Queue, f"{base}{story['id']}/", story + + class InstagramStoriesExtractor(InstagramExtractor): """Extractor for Instagram stories""" subcategory = "stories" @@ -793,7 +807,11 @@ class InstagramRestAPI(): try: return self._call(endpoint, params=params)["reels_media"] except KeyError: - raise exception.AuthorizationError("Login required") + raise exception.AuthRequired("authenticated cookies") + + def reels_tray(self): + endpoint = "/v1/feed/reels_tray/" + return self._call(endpoint)["tray"] def tags_media(self, tag): for section in self.tags_sections(tag): diff --git a/scripts/supportedsites.py b/scripts/supportedsites.py index fb09d58e..3f426dcd 100755 --- a/scripts/supportedsites.py +++ b/scripts/supportedsites.py @@ -310,6 +310,7 @@ SUBCATEGORY_MAP = { "posts": "", "saved": "Saved Posts", "tagged": "Tagged Posts", + "stories-tray": "Stories Home Tray", }, "itaku": { "posts": "", diff --git a/test/results/instagram.py b/test/results/instagram.py index 107e25ab..bf4eb2c9 100644 --- a/test/results/instagram.py +++ b/test/results/instagram.py @@ -109,6 +109,11 @@ __tests__ = ( "#class" : instagram.InstagramStoriesExtractor, }, +{ + "#url" : "https://www.instagram.com/stories/me/", + "#class" : instagram.InstagramStoriesTrayExtractor, +}, + { "#url" : "https://www.instagram.com/s/aGlnaGxpZ2h0OjE4MDQyNTA5NDg4MTcwMDk1", "#category": ("", "instagram", "highlights"),