[instagram] fix highlights extraction (#2197)
* [instagram] fix highlights extraction * [instagram] improve highlights extraction - 'yield' individual reels instead of collecting them in a list and returning them all at once - reduce 'chunk_size' to an even saver value (instagram.com also uses 5)
This commit is contained in:
@@ -748,13 +748,19 @@ class InstagramHighlightsExtractor(InstagramExtractor):
|
||||
|
||||
endpoint = "/v1/highlights/{}/highlights_tray/".format(user["id"])
|
||||
tray = self._request_api(endpoint)["tray"]
|
||||
|
||||
reel_ids = [highlight["id"] for highlight in tray]
|
||||
endpoint = "/v1/feed/reels_media/"
|
||||
params = {"reel_ids": reel_ids}
|
||||
reels = self._request_api(endpoint, params=params)["reels"]
|
||||
|
||||
return [reels[rid] for rid in reel_ids]
|
||||
# Anything above 30 responds with statuscode 400.
|
||||
# 30 can work, however, sometimes the API will respond with 560 or 500.
|
||||
chunk_size = 5
|
||||
endpoint = "/v1/feed/reels_media/"
|
||||
|
||||
for offset in range(0, len(reel_ids), chunk_size):
|
||||
chunk_ids = reel_ids[offset : offset+chunk_size]
|
||||
params = {"reel_ids": chunk_ids}
|
||||
reels = self._request_api(endpoint, params=params)["reels"]
|
||||
for reel_id in chunk_ids:
|
||||
yield reels[reel_id]
|
||||
|
||||
|
||||
class InstagramReelsExtractor(InstagramExtractor):
|
||||
|
||||
Reference in New Issue
Block a user