1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-23 03:02:50 +01:00

[reddit] add ability to filter by submission id

'extractor.reddit.id-min' and '….id-max' specify the lowest and
highest submission-/post-id to consider, similar to 'date-min' and
'date-max'
This commit is contained in:
Mike Fährmann 2017-06-29 17:39:22 +02:00
parent 06c4cae05b
commit f3d0373120
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

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