From c0e5d0475bff1507c930d4ceefb5d66686caee5d Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Sat, 26 Mar 2022 17:03:57 +0100 Subject: [PATCH] StoryItem.from_mediaid() Addresses #1238. --- instaloader/structures.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/instaloader/structures.py b/instaloader/structures.py index eb638d0..8b5e986 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -1115,6 +1115,21 @@ class StoryItem: def __hash__(self) -> int: return hash(self.mediaid) + @classmethod + def from_mediaid(cls, context: InstaloaderContext, mediaid: int): + """Create a StoryItem object from a given mediaid. + + .. versionadded:: 4.9 + """ + pic_json = context.graphql_query( + '2b0673e0dc4580674a88d426fe00ea90', + {'shortcode': Post.mediaid_to_shortcode(mediaid)} + ) + shortcode_media = pic_json['data']['shortcode_media'] + if shortcode_media is None: + raise BadResponseException("Fetching StoryItem metadata failed.") + return cls(context, shortcode_media) + @property def _iphone_struct(self) -> Dict[str, Any]: if not self._context.iphone_support: