1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-08-17 12:19:38 +02:00

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.
This commit is contained in:
André Koch-Kramer 2017-07-29 04:12:26 +02:00
parent 3e0b81ad56
commit 82ae31cea5

View File

@ -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: