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:
parent
3e0b81ad56
commit
82ae31cea5
@ -631,8 +631,9 @@ class Instaloader:
|
|||||||
download_videos: bool = True,
|
download_videos: bool = True,
|
||||||
fast_update: bool = False) -> None:
|
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.
|
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 userids: List of user IDs to be processed in terms of downloading their stories
|
||||||
:param download_videos: True, if videos should be downloaded
|
:param download_videos: True, if videos should be downloaded
|
||||||
@ -658,17 +659,17 @@ class Instaloader:
|
|||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
raise ConnectionException('Failed to fetch stories.')
|
raise ConnectionException('Failed to fetch stories.')
|
||||||
return json.loads(resp.text)
|
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:
|
if userids is not None:
|
||||||
for userid in userids:
|
for userid in userids:
|
||||||
url = 'https://i.instagram.com/api/v1/feed/user/{0}/reel_media/'.format(userid)
|
yield _get(url_reel_media.format(userid))
|
||||||
yield _get(url)
|
|
||||||
else:
|
else:
|
||||||
url = 'https://i.instagram.com/api/v1/feed/reels_tray/'
|
data = _get(url_reels_tray)
|
||||||
data = _get(url)
|
|
||||||
if not 'tray' in data:
|
if not 'tray' in data:
|
||||||
raise BadResponseException('Bad story reel JSON.')
|
raise BadResponseException('Bad story reel JSON.')
|
||||||
for user in data["tray"]:
|
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():
|
for user_stories in _user_stories():
|
||||||
if "items" not in user_stories:
|
if "items" not in user_stories:
|
||||||
|
Loading…
Reference in New Issue
Block a user