From 8c7561c5d79f1fb5ad6b3461a775238cae398565 Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Sat, 4 Apr 2020 10:51:55 +0200 Subject: [PATCH 1/7] Fix Downloading of Videos within a Sidecar Post Fixes #558. --- instaloader/structures.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/instaloader/structures.py b/instaloader/structures.py index 8160751..3b5ecd1 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -224,7 +224,11 @@ class Post: def get_sidecar_nodes(self) -> Iterator[PostSidecarNode]: """Sidecar nodes of a Post with typename==GraphSidecar.""" if self.typename == 'GraphSidecar': - for edge in self._field('edge_sidecar_to_children', 'edges'): + edges = self._field('edge_sidecar_to_children', 'edges') + if any(edge['node']['is_video'] for edge in edges): + # video_url is only present in full metadata, issue #558. + edges = self._full_metadata['edge_sidecar_to_children']['edges'] + for edge in edges: node = edge['node'] is_video = node['is_video'] yield PostSidecarNode(is_video=is_video, display_url=node['display_url'], From c56657855d24fbbc57e09cf0c848d0eb8e396f27 Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Sat, 4 Apr 2020 10:54:04 +0200 Subject: [PATCH 2/7] Release of Version 4.3.1 --- instaloader/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instaloader/__init__.py b/instaloader/__init__.py index 29daa8d..78a998d 100644 --- a/instaloader/__init__.py +++ b/instaloader/__init__.py @@ -1,7 +1,7 @@ """Download pictures (or videos) along with their captions and other metadata from Instagram.""" -__version__ = '4.3' +__version__ = '4.3.1' try: From 57d2ce95381cd713745b1557973ab61f63d03e4f Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Fri, 10 Apr 2020 11:57:36 +0200 Subject: [PATCH 3/7] Alleviate #449 by catching bad metadata response Instead of ungracefully failing with a TypeError, the Post is now skipped with an error message containing the invalid JSON. --- instaloader/structures.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/instaloader/structures.py b/instaloader/structures.py index 3b5ecd1..29a5b2e 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -134,6 +134,12 @@ class Post: pic_json = self._context.get_json("p/{0}/".format(self.shortcode), params={}) self._full_metadata_dict = pic_json['entry_data']['PostPage'][0]['graphql']['shortcode_media'] self._rhx_gis_str = pic_json.get('rhx_gis') + if self._full_metadata_dict is None: + # issue #449 + self._context.error("Fetching Post metadata failed (issue #449). " + "The following data has been returned:\n" + + json.dumps(pic_json['entry_data'], indent=2)) + raise BadResponseException("Fetching Post metadata failed.") if self.shortcode != self._full_metadata_dict['shortcode']: self._node.update(self._full_metadata_dict) raise PostChangedException From 7329ee10d8c84d191ef6ef9025ca8b692d9b733b Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Wed, 25 Mar 2020 18:17:02 +0100 Subject: [PATCH 4/7] Catch KeyError: 'authenticated' when Logging In Fixes #472. --- instaloader/instaloadercontext.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/instaloader/instaloadercontext.py b/instaloader/instaloadercontext.py index c327286..24305b0 100644 --- a/instaloader/instaloadercontext.py +++ b/instaloader/instaloadercontext.py @@ -239,6 +239,12 @@ class InstaloaderContext: resp_json['message'])) else: raise ConnectionException("Login error: \"{}\" status.".format(resp_json['status'])) + if 'authenticated' not in resp_json: + # Issue #472 + if 'message' in resp_json: + raise ConnectionException("Login error: Unexpected response, \"{}\".".format(resp_json['message'])) + else: + raise ConnectionException("Login error: Unexpected response, this might indicate a blocked IP.") if not resp_json['authenticated']: if resp_json['user']: # '{"authenticated": false, "user": true, "status": "ok"}' From 793b7e82baeaa3512688fdd44a15998aaf3f27bd Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Fri, 10 Apr 2020 11:13:07 +0200 Subject: [PATCH 5/7] Limit feed node processing to Post nodes Fixes #478. --- instaloader/instaloader.py | 6 ++++-- instaloader/structures.py | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/instaloader/instaloader.py b/instaloader/instaloader.py index a7d399d..05f3d3d 100644 --- a/instaloader/instaloader.py +++ b/instaloader/instaloader.py @@ -703,8 +703,10 @@ class Instaloader: while True: feed = data["user"]["edge_web_feed_timeline"] - yield from (Post(self.context, edge["node"]) for edge in feed["edges"] - if not edge["node"]["__typename"] == "GraphSuggestedUserFeedUnit") + for edge in feed["edges"]: + node = edge["node"] + if node.get("__typename") in Post.supported_graphql_types() and node.get("shortcode") is not None: + yield Post(self.context, node) if not feed["page_info"]["has_next_page"]: break data = self.context.graphql_query("d6f4427fbe92d846298cf93df0b937d3", diff --git a/instaloader/structures.py b/instaloader/structures.py index 29a5b2e..127dac6 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -98,6 +98,11 @@ class Post: raise InvalidArgumentException("Wrong mediaid {0}, unable to convert to shortcode".format(str(mediaid))) return b64encode(mediaid.to_bytes(9, 'big'), b'-_').decode().replace('A', ' ').lstrip().replace(' ', 'A') + @staticmethod + def supported_graphql_types() -> List[str]: + """The values of __typename fields that the :class:`Post` class can handle.""" + return ["GraphImage", "GraphVideo", "GraphSidecar"] + def _asdict(self): node = self._node if self._full_metadata_dict: From e268f9e625e627265cacd04bc71228b80bc9eb14 Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Fri, 10 Apr 2020 12:08:24 +0200 Subject: [PATCH 6/7] Release of Version 4.3.2 --- instaloader/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instaloader/__init__.py b/instaloader/__init__.py index 78a998d..5bc37d4 100644 --- a/instaloader/__init__.py +++ b/instaloader/__init__.py @@ -1,7 +1,7 @@ """Download pictures (or videos) along with their captions and other metadata from Instagram.""" -__version__ = '4.3.1' +__version__ = '4.3.2' try: From 1338cf0fcd1a9e8c8abfa71aded152d9b777304b Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Sat, 18 Apr 2020 11:16:55 +0200 Subject: [PATCH 7/7] Fix 'occured' typo in error messages Mentioned in #573 - thanks! --- instaloader/instaloadercontext.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instaloader/instaloadercontext.py b/instaloader/instaloadercontext.py index 24305b0..b1458ff 100644 --- a/instaloader/instaloadercontext.py +++ b/instaloader/instaloadercontext.py @@ -113,7 +113,7 @@ class InstaloaderContext: def close(self): """Print error log and close session""" if self.error_log and not self.quiet: - print("\nErrors occured:", file=sys.stderr) + print("\nErrors occurred:", file=sys.stderr) for err in self.error_log: print(err, file=sys.stderr) self._session.close() @@ -349,7 +349,7 @@ class InstaloaderContext: else: self._graphql_query_timestamps[query_hash].append(time.monotonic()) else: - text_for_429 = ("HTTP error code 429 was returned because too many queries occured in the last time. " + text_for_429 = ("HTTP error code 429 was returned because too many queries occurred in the last time. " "Please do not use Instagram in your browser or run multiple instances of Instaloader " "in parallel.") print(textwrap.fill(text_for_429), file=sys.stderr)