diff --git a/docs/configuration.rst b/docs/configuration.rst index 1ce75cb7..4b156a1e 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1834,6 +1834,24 @@ Description To enumerate files in reverse order, use ``count - num + 1``. +extractor.instagram.order-posts +------------------------------- +Type + ``string`` +Default + ``"asc"`` +Description + Controls the order in which posts are returned. + + * ``"asc"``: Same order as displayed + * ``"desc"``: Reverse order as displayed + * ``"id"`` or ``"id_asc"``: Ascending order by ID + * ``"id_desc"``: Descending order by ID + * ``"reverse"``: Same as ``"desc"`` + + Note: This option only affects ``highlights``. + + extractor.instagram.previews ---------------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 92451fda..b47a02ff 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -166,6 +166,9 @@ "api": "rest", "cookies": null, "include": "posts", + "order-files": "asc", + "order-posts": "asc", + "previews": false, "sleep-request": [6.0, 12.0], "videos": true }, diff --git a/gallery_dl/extractor/instagram.py b/gallery_dl/extractor/instagram.py index 3f760ebb..1e1de944 100644 --- a/gallery_dl/extractor/instagram.py +++ b/gallery_dl/extractor/instagram.py @@ -761,10 +761,20 @@ class InstagramRestAPI(): endpoint = "/v1/guides/guide/{}/".format(guide_id) return self._pagination_guides(endpoint) - def highlights_media(self, user_id): - chunk_size = 5 + def highlights_media(self, user_id, chunk_size=5): reel_ids = [hl["id"] for hl in self.highlights_tray(user_id)] + order = self.extractor.config("order-posts") + if order: + if order in ("desc", "reverse"): + reel_ids.reverse() + elif order in ("id", "id_asc"): + reel_ids.sort(key=lambda r: int(r[10:])) + elif order == "id_desc": + reel_ids.sort(key=lambda r: int(r[10:]), reverse=True) + elif order != "asc": + self.extractor.log.warning("Unknown posts order '%s'", order) + for offset in range(0, len(reel_ids), chunk_size): yield from self.reels_media( reel_ids[offset : offset+chunk_size])