mirror of
https://github.com/instaloader/instaloader.git
synced 2024-11-04 09:22:29 +01:00
Get stories per user
This commit is contained in:
parent
1699954761
commit
b85e8fd793
@ -627,10 +627,12 @@ class Instaloader:
|
|||||||
return downloaded
|
return downloaded
|
||||||
|
|
||||||
def download_stories(self,
|
def download_stories(self,
|
||||||
|
userids: List[int] = [],
|
||||||
download_videos: bool = True,
|
download_videos: bool = True,
|
||||||
fast_update: bool = False) -> None:
|
fast_update: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
Download 'unseen' stories from user followees. Does not mark stories as seen.
|
Download 'unseen' stories from user followees. Or all stories of users whose ID are give.
|
||||||
|
Does not mark stories as seen.
|
||||||
|
|
||||||
:param fast_update: If true, abort when first already-downloaded picture is encountered
|
:param fast_update: If true, abort when first already-downloaded picture is encountered
|
||||||
:param download_videos: True, if videos should be downloaded
|
:param download_videos: True, if videos should be downloaded
|
||||||
@ -648,24 +650,32 @@ class Instaloader:
|
|||||||
del header['X-Instagram-AJAX']
|
del header['X-Instagram-AJAX']
|
||||||
del header['X-Requested-With']
|
del header['X-Requested-With']
|
||||||
|
|
||||||
self._sleep()
|
def _user_stories():
|
||||||
url = 'https://i.instagram.com/api/v1/feed/reels_tray/'
|
def _get(url):
|
||||||
resp = tempsession.get(url)
|
self._sleep()
|
||||||
|
resp = tempsession.get(url)
|
||||||
|
if resp.status_code != 200:
|
||||||
|
raise ConnectionException('Failed to fetch stories.')
|
||||||
|
print(resp.text)
|
||||||
|
return json.loads(resp.text)
|
||||||
|
if userids:
|
||||||
|
for id in userids:
|
||||||
|
url = 'https://i.instagram.com/api/v1/feed/user/{0}/reel_media/'.format(id)
|
||||||
|
yield _get(url)
|
||||||
|
else:
|
||||||
|
url = 'https://i.instagram.com/api/v1/feed/reels_tray/'
|
||||||
|
data = _get(url)
|
||||||
|
if not 'tray' in data:
|
||||||
|
raise BadResponseException('Bad story reel JSON.')
|
||||||
|
for user in data["tray"]:
|
||||||
|
yield user
|
||||||
|
|
||||||
if resp.status_code != 200:
|
for user_stories in _user_stories():
|
||||||
raise ConnectionException('Failed to fetch stories.')
|
|
||||||
|
|
||||||
data = json.loads(resp.text)
|
|
||||||
|
|
||||||
if not 'tray' in data:
|
|
||||||
raise BadResponseException('Bad story reel JSON.')
|
|
||||||
|
|
||||||
totalcount = sum([len(us["items"]) if "items" in us else 0 for us in data["tray"]])
|
|
||||||
count = 1
|
|
||||||
for user_stories in data["tray"]:
|
|
||||||
if "items" not in user_stories:
|
if "items" not in user_stories:
|
||||||
continue
|
continue
|
||||||
name = user_stories["user"]["username"].lower()
|
name = user_stories["user"]["username"].lower()
|
||||||
|
totalcount = len(user_stories["items"]) if "items" in user_stories else 0
|
||||||
|
count = 1
|
||||||
for item in user_stories["items"]:
|
for item in user_stories["items"]:
|
||||||
self._log("[%3i/%3i] " % (count, totalcount), end="", flush=True)
|
self._log("[%3i/%3i] " % (count, totalcount), end="", flush=True)
|
||||||
count += 1
|
count += 1
|
||||||
@ -695,14 +705,17 @@ class Instaloader:
|
|||||||
self._log("Warning: Unable to find story image.")
|
self._log("Warning: Unable to find story image.")
|
||||||
downloaded = False
|
downloaded = False
|
||||||
if "caption" in item and item["caption"] is not None:
|
if "caption" in item and item["caption"] is not None:
|
||||||
self.save_caption(filename, date, item["caption"])
|
caption = item["caption"]
|
||||||
|
if isinstance(caption, dict) and "text" in caption:
|
||||||
|
caption = caption["text"]
|
||||||
|
self.save_caption(filename, date, caption)
|
||||||
else:
|
else:
|
||||||
self._log("<no caption>", end=' ', flush=True)
|
self._log("<no caption>", end=' ', flush=True)
|
||||||
if "video_versions" in item and download_videos:
|
if "video_versions" in item and download_videos:
|
||||||
self.download_pic(filename=filename,
|
downloaded = self.download_pic(filename=filename,
|
||||||
url=item["video_versions"][0]["url"],
|
url=item["video_versions"][0]["url"],
|
||||||
date_epoch=date)
|
date_epoch=date)
|
||||||
if "video_duration" in item and self.sleep:
|
if "video_duration" in item and self.sleep and downloaded:
|
||||||
time.sleep(item["video_duration"])
|
time.sleep(item["video_duration"])
|
||||||
if item["story_locations"]:
|
if item["story_locations"]:
|
||||||
location = item["story_locations"][0]["location"]
|
location = item["story_locations"][0]["location"]
|
||||||
|
Loading…
Reference in New Issue
Block a user