1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-09-11 16:22:24 +02:00

Do not require rhx_gix in metadata

Closes #297.
This commit is contained in:
André Koch-Kramer 2019-05-17 21:38:39 +02:00
parent 3528e8d19b
commit 749ff60639
3 changed files with 10 additions and 9 deletions

View File

@ -796,7 +796,7 @@ class Instaloader:
for node in self.context.graphql_node_list("df0dcc250c2b18d9fd27c5581ef33c7c",
{}, 'https://www.instagram.com/explore/',
lambda d: d['data']['user']['edge_web_discover_media'],
data['rhx_gis']))
data.get('rhx_gis')))
def get_hashtag_posts(self, hashtag: str) -> Iterator[Post]:
"""Get Posts associated with a #hashtag."""

View File

@ -530,6 +530,6 @@ class InstaloaderContext:
# At the moment, rhx_gis seems to be required for anonymous requests only. By returning None when logged
# in, we can save the root_rhx_gis lookup query.
return None
if not self._root_rhx_gis:
self._root_rhx_gis = self.get_json('', {})['rhx_gis']
return self._root_rhx_gis
if self._root_rhx_gis is None:
self._root_rhx_gis = self.get_json('', {}).get('rhx_gis', '')
return self._root_rhx_gis or None

View File

@ -132,7 +132,7 @@ class Post:
if not self._full_metadata_dict:
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['rhx_gis']
self._rhx_gis_str = pic_json.get('rhx_gis')
if self.shortcode != self._full_metadata_dict['shortcode']:
self._node.update(self._full_metadata_dict)
raise PostChangedException
@ -144,9 +144,8 @@ class Post:
return self._full_metadata_dict
@property
def _rhx_gis(self) -> str:
def _rhx_gis(self) -> Optional[str]:
self._obtain_metadata()
assert self._rhx_gis_str is not None
return self._rhx_gis_str
def _field(self, *keys) -> Any:
@ -454,6 +453,7 @@ class Profile:
self._context = context
self._has_public_story = None # type: Optional[bool]
self._node = node
self._has_full_metadata = False
self._rhx_gis = None
self._iphone_struct_ = None
if 'iphone_struct' in node:
@ -514,10 +514,11 @@ class Profile:
def _obtain_metadata(self):
try:
if not self._rhx_gis:
if not self._has_full_metadata:
metadata = self._context.get_json('{}/'.format(self.username), params={})
self._node = metadata['entry_data']['ProfilePage'][0]['graphql']['user']
self._rhx_gis = metadata['rhx_gis']
self._has_full_metadata = True
self._rhx_gis = metadata.get('rhx_gis')
except (QueryReturnedNotFoundException, KeyError) as err:
raise ProfileNotExistsException('Profile {} does not exist.'.format(self.username)) from err