From 54572fb1fcc2d022c5105b8eba0af69fc1a68651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Koch-Kramer?= Date: Thu, 23 Aug 2018 16:26:02 +0200 Subject: [PATCH] Make the Highlight stuff accept Profile objects download_highlights(), get_highlights() and the Highlight class now accept and use the owner's Profile rather than creating it themselves. --- instaloader/instaloader.py | 14 ++++++++------ instaloader/structures.py | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/instaloader/instaloader.py b/instaloader/instaloader.py index 9c7e976..87dab74 100644 --- a/instaloader/instaloader.py +++ b/instaloader/instaloader.py @@ -489,24 +489,26 @@ class Instaloader: return downloaded @_requires_login - def get_highlights(self, userid: int) -> Iterator[Highlight]: + def get_highlights(self, user: Union[int, Profile]) -> Iterator[Highlight]: """Get all highlights from a user. To use this, one needs to be logged in - :param userid: ID of the profile whose highlights should get fetched. + :param user: ID or Profile of the user whose highlights should get fetched. """ + userid = user if isinstance(user, int) else user.userid data = self.context.graphql_query("7c16654f22c819fb63d1183034a5162f", {"user_id": userid, "include_chaining": False, "include_reel": False, "include_suggested_users": False, "include_logged_out_extras": False, "include_highlight_reels": True})["data"]["user"]['edge_highlight_reels'] if data is None: raise BadResponseException('Bad highlights reel JSON.') - yield from (Highlight(self.context, edge['node']) for edge in data['edges']) + yield from (Highlight(self.context, edge['node'], user if isinstance(user, Profile) else None) + for edge in data['edges']) @_requires_login def download_highlights(self, - userid: int, + user: Union[int, Profile], fast_update: bool = False, filename_target: Optional[str] = None, storyitem_filter: Optional[Callable[[StoryItem], bool]] = None) -> None: @@ -514,13 +516,13 @@ class Instaloader: Download available highlights from a user whose ID is given. To use this, one needs to be logged in - :param userid: ID of the profile whose highlights should get downloaded. + :param user: ID or Profile of the user whose highlights should get downloaded. :param fast_update: If true, abort when first already-downloaded picture is encountered :param filename_target: Replacement for {target} in dirname_pattern and filename_pattern or None if profile name and the highlights' titles should be used instead :param storyitem_filter: function(storyitem), which returns True if given StoryItem should be downloaded """ - for user_highlight in self.get_highlights(userid): + for user_highlight in self.get_highlights(user): name = user_highlight.owner_username self.context.log("Retrieving highlights \"{}\" from profile {}".format(user_highlight.title, name)) totalcount = user_highlight.itemcount diff --git a/instaloader/structures.py b/instaloader/structures.py index eee5472..96de483 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -870,8 +870,9 @@ class Story: class Highlight(Story): - def __init__(self, context: InstaloaderContext, node: Dict[str, Any]): + def __init__(self, context: InstaloaderContext, node: Dict[str, Any], owner: Optional[Profile] = None): super().__init__(context, node) + self._owner_profile = owner self._items = None def __repr__(self):