From 82ae31cea58c7d1361a2e5e9eea8174881874b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Koch-Kramer?= Date: Sat, 29 Jul 2017 04:12:26 +0200 Subject: [PATCH] Fix download_stories() to get all available posts download_stories() did and does not check if a story is "unseen". The response to the query of the '/feed/reels_tray/' URL provides all available stories of the user's followees. Nevertheless, some of them do not contain an 'items' field which has no causal relationship with their status in terms of "seen" or "unseen". Therefore, to overcome this lack of 'items' the 'feed/user/TARGET_USERID/reel_media/' URL needs to be queried for each relevant followee whose 'items' were not provided in the first place. --- instaloader.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/instaloader.py b/instaloader.py index 6adcc3a..8ecdc82 100755 --- a/instaloader.py +++ b/instaloader.py @@ -631,8 +631,9 @@ class Instaloader: download_videos: bool = True, fast_update: bool = False) -> None: """ - Download 'unseen' stories from user followees or all stories of users whose ID are given. + Download available stories from user followees or all stories of users whose ID are given. Does not mark stories as seen. + To use this, one needs to be logged in :param userids: List of user IDs to be processed in terms of downloading their stories :param download_videos: True, if videos should be downloaded @@ -658,17 +659,17 @@ class Instaloader: if resp.status_code != 200: raise ConnectionException('Failed to fetch stories.') return json.loads(resp.text) + url_reel_media = 'https://i.instagram.com/api/v1/feed/user/{0}/reel_media/' + url_reels_tray = 'https://i.instagram.com/api/v1/feed/reels_tray/' if userids is not None: for userid in userids: - url = 'https://i.instagram.com/api/v1/feed/user/{0}/reel_media/'.format(userid) - yield _get(url) + yield _get(url_reel_media.format(userid)) else: - url = 'https://i.instagram.com/api/v1/feed/reels_tray/' - data = _get(url) + data = _get(url_reels_tray) if not 'tray' in data: raise BadResponseException('Bad story reel JSON.') for user in data["tray"]: - yield user + yield user if "items" in user else _get(url_reel_media.format(user['user']['pk'])) for user_stories in _user_stories(): if "items" not in user_stories: