Skip to content

Commit

Permalink
[instagram] fix highlights extraction (#2197)
Browse files Browse the repository at this point in the history
* [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)
  • Loading branch information
vsyx committed Jan 23, 2022
1 parent 5ed26e1 commit 3f2b633
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions gallery_dl/extractor/instagram.py
Expand Up @@ -748,13 +748,19 @@ def posts(self):

endpoint = "/v1/highlights/{}/highlights_tray/".format(user["id"])
tray = self._request_api(endpoint)["tray"]

reel_ids = [highlight["id"] for highlight in tray]

# 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/"
params = {"reel_ids": reel_ids}
reels = self._request_api(endpoint, params=params)["reels"]

return [reels[rid] for rid in reel_ids]
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):
Expand Down

0 comments on commit 3f2b633

Please sign in to comment.