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

This commit is contained in:
Mike Fährmann
2023-05-18 22:34:33 +02:00
parent 82a12d6126
commit d680623db3
2 changed files with 22 additions and 0 deletions

View File

@@ -1817,6 +1817,23 @@ Description
It is possible to use ``"all"`` instead of listing all values separately. It is possible to use ``"all"`` instead of listing all values separately.
extractor.instagram.order-files
-------------------------------
Type
``string``
Default
``"asc"``
Description
Controls the order in which files of each post are returned.
* ``"asc"``: Same order as displayed in a post
* ``"desc"``: Reverse order as displayed in a post
* ``"reverse"``: Same as ``"desc"``
Note: This option does *not* affect ``{num}``.
To enumerate files in reverse order, use ``count - num + 1``.
extractor.instagram.previews extractor.instagram.previews
---------------------------- ----------------------------
Type Type

View File

@@ -55,6 +55,9 @@ class InstagramExtractor(Extractor):
previews = self.config("previews", False) previews = self.config("previews", False)
video_headers = {"User-Agent": "Mozilla/5.0"} video_headers = {"User-Agent": "Mozilla/5.0"}
order = self.config("order-files")
reverse = order[0] in ("r", "d") if order else False
for post in self.posts(): for post in self.posts():
if "__typename" in post: if "__typename" in post:
@@ -71,6 +74,8 @@ class InstagramExtractor(Extractor):
if "date" in post: if "date" in post:
del post["date"] del post["date"]
if reverse:
files.reverse()
for file in files: for file in files:
file.update(post) file.update(post)