diff options
| author | 2025-09-23 07:44:37 -0400 | |
|---|---|---|
| committer | 2025-09-23 07:44:37 -0400 | |
| commit | 42b62671fabfdcf983a9575221420d85f7fbcac1 (patch) | |
| tree | fa6b2af249a7216aae5c70a926c6d08be1ac55a6 /gallery_dl/extractor/2ch.py | |
| parent | 3b7f8716690b7aa1994a9cb387bbc7215e01a4ed (diff) | |
New upstream version 1.30.8.upstream/1.30.8
Diffstat (limited to 'gallery_dl/extractor/2ch.py')
| -rw-r--r-- | gallery_dl/extractor/2ch.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/gallery_dl/extractor/2ch.py b/gallery_dl/extractor/2ch.py index f5bb7b7..912a251 100644 --- a/gallery_dl/extractor/2ch.py +++ b/gallery_dl/extractor/2ch.py @@ -4,37 +4,41 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. -"""Extractors for https://2ch.hk/""" +"""Extractors for https://2ch.su/""" from .common import Extractor, Message from .. import text, util +BASE_PATTERN = r"(?:https?://)?2ch\.(su|life|hk)" + class _2chThreadExtractor(Extractor): """Extractor for 2ch threads""" category = "2ch" subcategory = "thread" - root = "https://2ch.hk" + root = "https://2ch.su" directory_fmt = ("{category}", "{board}", "{thread} {title}") filename_fmt = "{tim}{filename:? //}.{extension}" archive_fmt = "{board}_{thread}_{tim}" - pattern = r"(?:https?://)?2ch\.hk/([^/?#]+)/res/(\d+)" - example = "https://2ch.hk/a/res/12345.html" + pattern = rf"{BASE_PATTERN}/([^/?#]+)/res/(\d+)" + example = "https://2ch.su/a/res/12345.html" def __init__(self, match): + tld = match[1] + self.root = f"https://2ch.{'su' if tld == 'hk' else tld}" Extractor.__init__(self, match) - self.board, self.thread = match.groups() def items(self): - url = f"{self.root}/{self.board}/res/{self.thread}.json" + _, board, thread = self.groups + url = f"{self.root}/{board}/res/{thread}.json" posts = self.request_json(url)["threads"][0]["posts"] op = posts[0] title = op.get("subject") or text.remove_html(op["comment"]) thread = { - "board" : self.board, - "thread": self.thread, + "board" : board, + "thread": thread, "title" : text.unescape(title)[:50], } @@ -61,16 +65,17 @@ class _2chBoardExtractor(Extractor): """Extractor for 2ch boards""" category = "2ch" subcategory = "board" - root = "https://2ch.hk" - pattern = r"(?:https?://)?2ch\.hk/([^/?#]+)/?$" - example = "https://2ch.hk/a/" + root = "https://2ch.su" + pattern = rf"{BASE_PATTERN}/([^/?#]+)/?$" + example = "https://2ch.su/a/" def __init__(self, match): + tld = match[1] + self.root = f"https://2ch.{'su' if tld == 'hk' else tld}" Extractor.__init__(self, match) - self.board = match[1] def items(self): - base = f"{self.root}/{self.board}" + base = f"{self.root}/{self.groups[1]}" # index page url = f"{base}/index.json" |
