From 0ab9bb1721fb83c38123b483e1d45ca8e56eea7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 9 Dec 2019 20:36:05 +0100 Subject: [PATCH] [4chan] add extractor for entire boards (closes #510) --- gallery_dl/extractor/4chan.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/gallery_dl/extractor/4chan.py b/gallery_dl/extractor/4chan.py index 36a0573e..980dc20c 100644 --- a/gallery_dl/extractor/4chan.py +++ b/gallery_dl/extractor/4chan.py @@ -59,3 +59,30 @@ class _4chanThreadExtractor(Extractor): url = "https://i.4cdn.org/{}/{}{}".format( post["board"], post["tim"], post["ext"]) yield Message.Url, url, post + + +class _4chanBoardExtractor(Extractor): + """Extractor for 4chan boards""" + category = "4chan" + subcategory = "board" + pattern = r"(?:https?://)?boards\.4chan(?:nel)?\.org/([^/?&#]+)/\d*$" + test = ("https://boards.4channel.org/po/", { + "pattern": _4chanThreadExtractor.pattern, + "count": ">= 100", + }) + + def __init__(self, match): + Extractor.__init__(self, match) + self.board = match.group(1) + + def items(self): + url = "https://a.4cdn.org/{}/threads.json".format(self.board) + threads = self.request(url).json() + + for page in threads: + for thread in page["threads"]: + url = "https://boards.4chan.org/{}/thread/{}/".format( + self.board, thread["no"]) + thread["page"] = page["page"] + thread["_extractor"] = _4chanThreadExtractor + yield Message.Queue, url, thread