| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2021-2025 Mike Fährmann |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 2 as |
| 7 |
# published by the Free Software Foundation. |
| 8 |
|
| 9 |
"""Extractors for https://comicvine.gamespot.com/""" |
| 10 |
|
| 11 |
from .booru import BooruExtractor |
| 12 |
from .. import text |
| 13 |
import operator |
| 14 |
|
| 15 |
|
| 16 |
class ComicvineTagExtractor(BooruExtractor): |
| 17 |
"""Extractor for a gallery on comicvine.gamespot.com""" |
| 18 |
category = "comicvine" |
| 19 |
subcategory = "tag" |
| 20 |
basecategory = "" |
| 21 |
root = "https://comicvine.gamespot.com" |
| 22 |
per_page = 1000 |
| 23 |
directory_fmt = ("{category}", "{tag}") |
| 24 |
filename_fmt = "{filename}.{extension}" |
| 25 |
archive_fmt = "{id}" |
| 26 |
pattern = (r"(?:https?://)?comicvine\.gamespot\.com" |
| 27 |
r"(/([^/?#]+)/(\d+-\d+)/images/.*)") |
| 28 |
example = "https://comicvine.gamespot.com/TAG/123-45/images/" |
| 29 |
|
| 30 |
def __init__(self, match): |
| 31 |
BooruExtractor.__init__(self, match) |
| 32 |
self.path, self.object_name, self.object_id = match.groups() |
| 33 |
|
| 34 |
def metadata(self): |
| 35 |
return {"tag": text.unquote(self.object_name)} |
| 36 |
|
| 37 |
def posts(self): |
| 38 |
url = self.root + "/js/image-data.json" |
| 39 |
params = { |
| 40 |
"images": text.extract( |
| 41 |
self.request(self.root + self.path).text, |
| 42 |
'data-gallery-id="', '"')[0], |
| 43 |
"start" : self.page_start, |
| 44 |
"count" : self.per_page, |
| 45 |
"object": self.object_id, |
| 46 |
} |
| 47 |
|
| 48 |
while True: |
| 49 |
images = self.request_json(url, params=params)["images"] |
| 50 |
yield from images |
| 51 |
|
| 52 |
if len(images) < self.per_page: |
| 53 |
return |
| 54 |
params["start"] += self.per_page |
| 55 |
|
| 56 |
def skip_files(self, num): |
| 57 |
self.page_start = num |
| 58 |
return num |
| 59 |
|
| 60 |
_file_url = operator.itemgetter("original") |
| 61 |
|
| 62 |
def _prepare(self, post): |
| 63 |
post["date"] = self.parse_datetime( |
| 64 |
post["dateCreated"], "%a, %b %d %Y") |
| 65 |
post["tags"] = [tag["name"] for tag in post["tags"] if tag["name"]] |