# -*- coding: utf-8 -*- # Copyright 2021-2023 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 https://tapas.io/""" from .common import Extractor, Message from .. import text, exception from ..cache import cache BASE_PATTERN = r"(?:https?://)?tapas\.io" class TapasExtractor(Extractor): """Base class for tapas.io extractors""" category = "tapas" root = "https://tapas.io" directory_fmt = ("{category}", "{series[title]}", "{id} {title}") filename_fmt = "{num:>02}.{extension}" archive_fmt = "{id}_{num}" cookies_domain = ".tapas.io" cookies_names = ("_cpc_",) _cache = None def _init(self): if self._cache is None: TapasExtractor._cache = {} def items(self): self.login() headers = {"Accept": "application/json, text/javascript, */*;"} for episode_id in self.episode_ids(): url = "{}/episode/{}".format(self.root, episode_id) data = self.request(url, headers=headers).json()["data"] episode = data["episode"] if not episode.get("free") and not episode.get("unlocked"): raise exception.StopExtraction( "Episode '%s' not unlocked (ID %s) ", episode["title"], episode_id) html = data["html"] series_id = text.rextract(html, 'data-series-id="', '"')[0] try: episode["series"] = self._cache[series_id] except KeyError: url = "{}/series/{}".format(self.root, series_id) episode["series"] = self._cache[series_id] = self.request( url, headers=headers).json()["data"] episode["date"] = text.parse_datetime(episode["publish_date"]) yield Message.Directory, episode if episode["book"]: content, _ = text.extract( html, '