# -*- coding: utf-8 -*- # Copyright 2023-2026 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 Chevereto galleries""" from .common import BaseExtractor, Message from .. import text, util class CheveretoExtractor(BaseExtractor): """Base class for chevereto extractors""" basecategory = "chevereto" directory_fmt = ("{category}", "{user}", "{album}") archive_fmt = "{id}" parent = True def _init(self): self.path = self.groups[-1] def _pagination(self, url, callback=None): page = self.request(url).text if len(page) < 45_000 and "assword required" in page and ( form := text.extr(page, "
', "—"), "album" : extr( "Added to "), "date" : self.parse_datetime_iso(extr( '") file["album"] = text.remove_html(album_name) file["album_slug"], _, file["album_id"] = text.rextr( album_url, "/", '"').rpartition(".") try: min, _, sec = file["duration"].partition(":") file["duration"] = int(min) * 60 + int(sec) except Exception: pass else: url = (extr('").rpartition(">") file = { "id" : self.path.rpartition("/")[2].rpartition(".")[2], "url" : url, "type" : type, "title": text.unescape(title), "album": text.remove_html(album_name), "date" : self.parse_datetime_iso(extr('', "<", pos)[0]) class CheveretoCategoryExtractor(CheveretoExtractor): """Extractor for chevereto galleries""" subcategory = "category" pattern = BASE_PATTERN + r"(/category/[^/?#]+)" example = "https://imglike.com/category/TITLE" def items(self): data = {"_extractor": CheveretoFileExtractor} for image in self._pagination(self.root + self.path): yield Message.Queue, image, data class CheveretoUserExtractor(CheveretoExtractor): """Extractor for chevereto users""" subcategory = "user" pattern = BASE_PATTERN + r"(/[^/?#]+(?:/albums)?)" example = "https://jpg7.cr/USER" def items(self): data_file = {"_extractor": CheveretoFileExtractor} data_album = {"_extractor": CheveretoAlbumExtractor} for url in self._pagination(self.root + self.path): data = (data_album if "/album/" in url or "/a/" in url else data_file) yield Message.Queue, url, data