# -*- coding: utf-8 -*- # Copyright 2022-2025 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. """Extractors for 2chen boards""" from .common import BaseExtractor, Message from .. import text class _2chenExtractor(BaseExtractor): basecategory = "2chen" BASE_PATTERN = _2chenExtractor.update({ "sturdychan": { "root": "https://sturdychan.help", "pattern": r"(?:sturdychan\.help|2chen\.(?:moe|club))", }, "schan": { "root": "https://schan.help/", "pattern": r"schan\.help", }, }) class _2chenThreadExtractor(_2chenExtractor): """Extractor for 2chen threads""" subcategory = "thread" directory_fmt = ("{category}", "{board}", "{thread} {title}") filename_fmt = "{time} {filename}.{extension}" archive_fmt = "{board}_{thread}_{no}_{time}" pattern = BASE_PATTERN + r"/([^/?#]+)/(\d+)" example = "https://sturdychan.help/a/12345/" def items(self): board = self.groups[-2] thread = self.kwdict["thread"] = self.groups[-1] url = f"{self.root}/{board}/{thread}" page = self.request(url, encoding="utf-8", notfound="thread").text self.kwdict["board"], pos = text.extract( page, 'class="board">/', '/<') self.kwdict["title"] = text.unescape(text.extract( page, "