From f3d03731200b0375b9d34a129ca9abf339471d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 29 Jun 2017 17:39:22 +0200 Subject: [PATCH] [reddit] add ability to filter by submission id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'extractor.reddit.id-min' and '….id-max' specify the lowest and highest submission-/post-id to consider, similar to 'date-min' and 'date-max' --- gallery_dl/extractor/reddit.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/gallery_dl/extractor/reddit.py b/gallery_dl/extractor/reddit.py index 589c4a46..ff1f57ef 100644 --- a/gallery_dl/extractor/reddit.py +++ b/gallery_dl/extractor/reddit.py @@ -189,15 +189,16 @@ class RedditAPI(): return data def _pagination(self, endpoint, params, _empty=()): - date_min = int(self.extractor.config("date-min", 0)) - date_max = int(self.extractor.config("date-max", 253402210800)) + ts_min, ts_max = self._parse_timestamps() + id_min, id_max = self._parse_ids() while True: data = self._call(endpoint, params)["data"] for submission in data["children"]: submission = submission["data"] - if date_min <= submission["created_utc"] <= date_max: + if (ts_min <= submission["created_utc"] <= ts_max and + id_min <= self._decode(submission["id"]) <= id_max): if submission["num_comments"] and self.comments: try: yield self.submission(submission["id"]) @@ -225,3 +226,21 @@ class RedditAPI(): queue += comment["replies"]["data"]["children"] if link_id and extra: yield from self.morechildren(link_id, extra) + + def _parse_timestamps(self): + return ( + int(self.extractor.config("date-min", 0)), + int(self.extractor.config("date-max", 253402210800)), + ) + + def _parse_ids(self): + id_min = self.extractor.config("id-min") + id_max = self.extractor.config("id-max") + return ( + self._decode(id_min.rpartition("_")[2]) if id_min else 0, + self._decode(id_max.rpartition("_")[2]) if id_max else 2147483647, + ) + + @staticmethod + def _decode(sid): + return util.bdecode(sid, "0123456789abcdefghijklmnopqrstuvwxyz")