diff --git a/docs/configuration.rst b/docs/configuration.rst index 5bca679f..a8f42576 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -4252,6 +4252,21 @@ Note It is possible to use ``"all"`` instead of listing all values separately. +extractor.[misskey].order-posts +------------------------------- +Type + ``string`` +Default + ``"desc"`` +Description + Controls the order in which posts are processed. + + ``"asc"`` | ``"reverse"`` + Ascending order (oldest first) + ``"desc"`` + Descending order (newest first) + + extractor.[misskey].renotes --------------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 877a90cd..dee9190c 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -1094,6 +1094,7 @@ "date-min" : null, "date-max" : null, "include" : ["notes"], + "order-posts" : "desc", "renotes" : false, "replies" : true, "text-posts" : false diff --git a/gallery_dl/extractor/misskey.py b/gallery_dl/extractor/misskey.py index 66dcba65..ca3ae185 100644 --- a/gallery_dl/extractor/misskey.py +++ b/gallery_dl/extractor/misskey.py @@ -254,18 +254,33 @@ class MisskeyAPI(): data["withFiles"] = False if extr.config("text-posts") else True date_min, date_max = extr._get_date_min_max() - if date_min is not None: - data["sinceDate"] = date_min * 1000 - if date_max is None: - # ensure notes are returned in descending order - # TODO: implement 'order-posts' option - data["untilDate"] = (int(dt.to_ts(dt.now())) + 1000) * 1000 - if date_max is not None: - data["untilDate"] = date_max * 1000 + if (order := extr.config("order-posts")) and \ + order[0] in ("a", "r"): + key = "sinceId" + data["sinceDate"] = 1 if date_min is None else date_min * 1000 + date_stop = None if date_max is None else date_max + else: + key = "untilId" + date_stop = None + if date_min is not None: + data["sinceDate"] = date_min * 1000 + if date_max is None: + # ensure notes are returned in descending order + data["untilDate"] = (int(dt.time.time()) + 1000) * 1000 + if date_max is not None: + data["untilDate"] = date_max * 1000 while True: notes = self._call(endpoint, data) if not notes: return - yield from notes - data["untilId"] = notes[-1]["id"] + elif date_stop is not None and dt.to_ts(dt.parse_iso( + notes[-1]["createdAt"])) > date_stop: + for idx, note in enumerate(notes): + if dt.to_ts(dt.parse_iso(note["createdAt"])) > date_stop: + yield from notes[:idx] + return + else: + yield from notes + + data[key] = notes[-1]["id"]