1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[instagram] add 'order-posts' option (#4017, #3993)

This commit is contained in:
Mike Fährmann 2023-05-18 22:50:04 +02:00
parent d680623db3
commit a83983c651
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 33 additions and 2 deletions

View File

@ -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

View File

@ -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
},

View File

@ -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])