| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2026 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://myfigurecollection.net/""" |
| 10 |
|
| 11 |
from .common import Extractor, Message, Dispatch |
| 12 |
from .. import text, util |
| 13 |
|
| 14 |
BASE_PATTERN = r"(?:https?://)?(?:www\.)?myfigurecollection\.net" |
| 15 |
USER_PATTERN = BASE_PATTERN + r"/profile/([^/?#]+)" |
| 16 |
|
| 17 |
|
| 18 |
class MyfigurecollectionExtractor(Extractor): |
| 19 |
"""Base class for myfigurecollection extractors""" |
| 20 |
category = "myfigurecollection" |
| 21 |
root = "https://myfigurecollection.net" |
| 22 |
parent = True |
| 23 |
|
| 24 |
def _pagination(self, params): |
| 25 |
url = self.root + "/" |
| 26 |
params["page"] = text.parse_int(params.get("page"), 1) |
| 27 |
|
| 28 |
find_ids = text.re(r'<a href="/\w+/(\d+)').findall |
| 29 |
while True: |
| 30 |
page = self.request(url, params=params).text |
| 31 |
results, pos = text.extract( |
| 32 |
page, '<div class="results">', '<div class="results-count">') |
| 33 |
|
| 34 |
yield from find_ids(results) |
| 35 |
|
| 36 |
pos = page.find("nav-current", pos) |
| 37 |
if page.find('"nav-page', pos) < 0: |
| 38 |
break |
| 39 |
params["page"] += 1 |
| 40 |
|
| 41 |
|
| 42 |
class MyfigurecollectionItemExtractor(MyfigurecollectionExtractor): |
| 43 |
subcategory = "item" |
| 44 |
directory_fmt = ("{category}", "Items") |
| 45 |
filename_fmt = "{id}_{num:>02}_{filename}.{extension}" |
| 46 |
archive_fmt = "i{id}_{num}" |
| 47 |
pattern = BASE_PATTERN + r"/item/(\d+)" |
| 48 |
example = "https://myfigurecollection.net/item/12345" |
| 49 |
|
| 50 |
def items(self): |
| 51 |
item_id = self.groups[0] |
| 52 |
url = f"{self.root}/item/{item_id}" |
| 53 |
extr = text.extract_from(self.request(url).text) |
| 54 |
|
| 55 |
item = { |
| 56 |
"id" : item_id, |
| 57 |
"title_html": text.unescape(extr( |
| 58 |
'property="og:title" content="', '"')), |
| 59 |
"post_url" : text.unescape(extr( |
| 60 |
'property="og:url" content="', '"')), |
| 61 |
"pictures" : extr( |
| 62 |
'name="pictures" content="', '"'), |
| 63 |
"Category" : split(extr( |
| 64 |
'class="data-label">Categor', "</div></div>")), |
| 65 |
"classification": split_meta(extr( |
| 66 |
'class="data-label">Classificatio', "</div></div>")), |
| 67 |
"title" : rm(extr( |
| 68 |
'class="data-label">Title', "</div></div>")), |
| 69 |
"origin" : split(extr( |
| 70 |
'class="data-label">Origi', "</div></div>")), |
| 71 |
"character" : split(extr( |
| 72 |
'class="data-label">Characte', "</div></div>")), |
| 73 |
"company" : split_meta(extr( |
| 74 |
'class="data-label">Compan', "</div></div>")), |
| 75 |
"artist" : split_meta(extr( |
| 76 |
'class="data-label">Artis', "</div></div>")), |
| 77 |
"release" : self._parse_releases(extr( |
| 78 |
'class="data-label">Releas', |
| 79 |
'</div></div><div class="data-field"><div class="data-l')), |
| 80 |
"material" : rm(extr( |
| 81 |
'abel">Materia', "</div></div>")), |
| 82 |
"dimensions": rm(extr( |
| 83 |
'abel">Dimensio', "</div></div>")), |
| 84 |
"various" : rm(extr( |
| 85 |
'abel">Variou', "</div></div>")), |
| 86 |
"tags" : text.split_html(extr( |
| 87 |
'<div class="object-tags">', "</section>"))[::2], |
| 88 |
} |
| 89 |
|
| 90 |
item["material"] = m.split(" , ") if (m := item["material"]) else "" |
| 91 |
|
| 92 |
files = util.json_loads(text.unquote(item.pop("pictures"))) |
| 93 |
item["count"] = len(files) |
| 94 |
|
| 95 |
yield Message.Directory, "", item |
| 96 |
for item["num"], file in enumerate(files, 1): |
| 97 |
url = file["src"] |
| 98 |
item["width"] = file["w"] |
| 99 |
item["height"] = file["h"] |
| 100 |
yield Message.Url, url, text.nameext_from_url(url, item) |
| 101 |
|
| 102 |
def _parse_releases(self, html): |
| 103 |
items = html.split('<div class="data-value">') |
| 104 |
del items[0] |
| 105 |
|
| 106 |
results = [] |
| 107 |
for item in items: |
| 108 |
date, pos = text.extract(item, ">", "<") |
| 109 |
type, pos = text.extract(item, "<em>", "<", pos) |
| 110 |
price, pos = text.extract(item, "<br/>", "(", pos) |
| 111 |
|
| 112 |
parts = date.split("/") |
| 113 |
try: |
| 114 |
name = f"{parts[2]}-{parts[1]}-{parts[0]}" |
| 115 |
except Exception: |
| 116 |
if len(parts) < 2: |
| 117 |
results.append(text.remove_html(item)) |
| 118 |
continue |
| 119 |
name = f"{parts[1]}-{parts[0]}" |
| 120 |
if price: |
| 121 |
name = f"{name}: {price.replace('<small>', '').strip()}" |
| 122 |
if type: |
| 123 |
name = f"{name} ({type})" |
| 124 |
results.append(name) |
| 125 |
return results |
| 126 |
|
| 127 |
|
| 128 |
class MyfigurecollectionPictureExtractor(MyfigurecollectionExtractor): |
| 129 |
subcategory = "picture" |
| 130 |
directory_fmt = ("{category}", "{user}", "Photos") |
| 131 |
filename_fmt = "{id} {title}.{extension}" |
| 132 |
archive_fmt = "p{id}" |
| 133 |
pattern = BASE_PATTERN + r"/picture/(\d+)" |
| 134 |
example = "https://myfigurecollection.net/picture/12345" |
| 135 |
|
| 136 |
def items(self): |
| 137 |
item_id = self.groups[0] |
| 138 |
url = f"{self.root}/picture/{item_id}" |
| 139 |
extr = text.extract_from(self.request(url).text) |
| 140 |
|
| 141 |
item = { |
| 142 |
"id" : item_id, |
| 143 |
"title" : text.unescape(extr( |
| 144 |
'property="og:title" content="', '"')), |
| 145 |
"post_url": text.unescape(extr( |
| 146 |
'property="og:url" content="', '"')), |
| 147 |
"Category": text.split_html(extr( |
| 148 |
'class="categories">', "</div></div><")), |
| 149 |
"user" : text.remove_html(extr("<section>", "</a><span")), |
| 150 |
"date" : self.parse_datetime(extr( |
| 151 |
'<span title="', '"'), "%m/%d/%Y, %H:%M:%S"), |
| 152 |
"url" : extr('<a href="', '"'), |
| 153 |
"width" : text.parse_int(extr( |
| 154 |
'<a class="size', ">") and extr("", "×")), |
| 155 |
"height": text.parse_int(extr("", " ")), |
| 156 |
"size" : text.parse_bytes(extr("(", "iB")), |
| 157 |
"description": extr('<div class="bbcode">', "</div>"), |
| 158 |
"tags" : text.split_html(extr( |
| 159 |
'<div class="object-tags">', "</section>"))[::2], |
| 160 |
} |
| 161 |
|
| 162 |
url = item["url"] |
| 163 |
yield Message.Directory, "", item |
| 164 |
yield Message.Url, url, text.nameext_from_url(url, item) |
| 165 |
|
| 166 |
|
| 167 |
class MyfigurecollectionArticleExtractor(MyfigurecollectionExtractor): |
| 168 |
subcategory = "article" |
| 169 |
directory_fmt = ("{category}", "{user}", "Articles", |
| 170 |
"{date:%Y-%m-%d} {id} {title}") |
| 171 |
filename_fmt = "{num:>02}.{extension}" |
| 172 |
archive_fmt = "a{id}_{num}" |
| 173 |
pattern = BASE_PATTERN + r"/blogpost/(\d+)" |
| 174 |
example = "https://myfigurecollection.net/blogpost/12345" |
| 175 |
|
| 176 |
def items(self): |
| 177 |
item_id = self.groups[0] |
| 178 |
url = f"{self.root}/blogpost/{item_id}" |
| 179 |
extr = text.extract_from(self.request(url).text) |
| 180 |
|
| 181 |
item = { |
| 182 |
"id" : item_id, |
| 183 |
"title" : text.unescape(extr( |
| 184 |
'property="og:title" content="', '"')), |
| 185 |
"post_url": text.unescape(extr( |
| 186 |
'property="og:url" content="', '"')), |
| 187 |
"Category": text.split_html(extr( |
| 188 |
'class="categories">', "</div></div><")), |
| 189 |
"user" : text.remove_html(extr("<section>", "</a><span")), |
| 190 |
"date" : self.parse_datetime(extr( |
| 191 |
'<span title="', '"'), "%m/%d/%Y, %H:%M:%S"), |
| 192 |
"body" : extr( |
| 193 |
'eBody"><div class="bbcode">', '</div></div></div></div><div'), |
| 194 |
"views" : extr(">", " ").replace(",", ""), |
| 195 |
"likes" : extr(">", " ").replace(",", ""), |
| 196 |
"comments": extr('/comments/">', " ").replace(",", ""), |
| 197 |
"tags" : text.split_html(extr( |
| 198 |
'<div class="object-tags">', "</section>"))[::2], |
| 199 |
} |
| 200 |
|
| 201 |
files = text.re(r'<img[^>]*? alt="([^"]+)').findall( |
| 202 |
item["body"]) |
| 203 |
item["count"] = len(files) |
| 204 |
|
| 205 |
yield Message.Directory, "", item |
| 206 |
for item["num"], url in enumerate(files, 1): |
| 207 |
yield Message.Url, url, text.nameext_from_url(url, item) |
| 208 |
|
| 209 |
|
| 210 |
class MyfigurecollectionUserExtractor(Dispatch, MyfigurecollectionExtractor): |
| 211 |
pattern = USER_PATTERN + r"/?(?:$|\?|#)" |
| 212 |
example = "https://myfigurecollection.net/profile/USER" |
| 213 |
|
| 214 |
def items(self): |
| 215 |
base = f"{self.root}/profile/{self.groups[0]}/" |
| 216 |
return self._dispatch_extractors(( |
| 217 |
(MyfigurecollectionUserCollectionExtractor, base + "collection/"), |
| 218 |
(MyfigurecollectionUserPicturesExtractor , base + "pictures/"), |
| 219 |
(MyfigurecollectionUserArticlesExtractor , base + "blogposts/"), |
| 220 |
), ("user-pictures",)) |
| 221 |
|
| 222 |
|
| 223 |
class MyfigurecollectionUserCollectionExtractor(MyfigurecollectionExtractor): |
| 224 |
subcategory = "user-collection" |
| 225 |
pattern = (BASE_PATTERN + r"/(?:profile/([^/?#]+)/collection" |
| 226 |
r"|\?(mode=view&username=[^&#]+&tab=collection[^#]*))") |
| 227 |
example = "https://myfigurecollection.net/profile/USER/collection/" |
| 228 |
|
| 229 |
def items(self): |
| 230 |
username, query = self.groups |
| 231 |
if username: |
| 232 |
params = { |
| 233 |
"mode" : "view", |
| 234 |
"username" : username, |
| 235 |
"tab" : "collection", |
| 236 |
"status" : "2", |
| 237 |
"current" : "keywords", |
| 238 |
"rootId" : "-1", |
| 239 |
"categoryId": "-1", |
| 240 |
"output" : "2", |
| 241 |
"sort" : "category", |
| 242 |
"order" : "asc", |
| 243 |
"_tb" : "user", |
| 244 |
"page" : 1, |
| 245 |
|
| 246 |
} |
| 247 |
else: |
| 248 |
params = text.parse_query(query) |
| 249 |
|
| 250 |
data = {"_extractor": MyfigurecollectionItemExtractor} |
| 251 |
base = self.root + "/item/" |
| 252 |
for item_id in self._pagination(params): |
| 253 |
yield Message.Queue, base + item_id, data |
| 254 |
|
| 255 |
|
| 256 |
class MyfigurecollectionUserPicturesExtractor(MyfigurecollectionExtractor): |
| 257 |
subcategory = "user-pictures" |
| 258 |
pattern = (BASE_PATTERN + r"/(?:profile/([^/?#]+)/pictures" |
| 259 |
r"|\?(mode=view&username=[^&#]+&tab=pictures[^#]*))") |
| 260 |
example = "https://myfigurecollection.net/profile/USER/pictures/" |
| 261 |
|
| 262 |
def items(self): |
| 263 |
username, query = self.groups |
| 264 |
if username: |
| 265 |
params = { |
| 266 |
"mode" : "view", |
| 267 |
"username" : username, |
| 268 |
"tab" : "pictures", |
| 269 |
"current" : "tags", |
| 270 |
"categoryId": "0", |
| 271 |
"albumId" : "-1", |
| 272 |
"sort" : "date", |
| 273 |
"order" : "desc", |
| 274 |
"_tb" : "user", |
| 275 |
"page" : 1, |
| 276 |
} |
| 277 |
else: |
| 278 |
params = text.parse_query(query) |
| 279 |
|
| 280 |
data = {"_extractor": MyfigurecollectionPictureExtractor} |
| 281 |
base = self.root + "/picture/" |
| 282 |
for item_id in self._pagination(params): |
| 283 |
yield Message.Queue, base + item_id, data |
| 284 |
|
| 285 |
|
| 286 |
class MyfigurecollectionUserArticlesExtractor(MyfigurecollectionExtractor): |
| 287 |
subcategory = "user-articles" |
| 288 |
pattern = (BASE_PATTERN + r"/(?:profile/([^/?#]+)/blogposts" |
| 289 |
r"|\?(mode=view&username=[^&#]+&tab=blogposts[^#]*))") |
| 290 |
example = "https://myfigurecollection.net/profile/USER/blogposts/" |
| 291 |
|
| 292 |
def items(self): |
| 293 |
username, query = self.groups |
| 294 |
|
| 295 |
if username: |
| 296 |
params = { |
| 297 |
"mode" : "view", |
| 298 |
"username" : username, |
| 299 |
"tab" : "blogposts", |
| 300 |
"current" : "keywords", |
| 301 |
"sort" : "date", |
| 302 |
"order" : "desc", |
| 303 |
"categoryId": "-1", |
| 304 |
"isSelected": "0", |
| 305 |
"_tb" : "user", |
| 306 |
"page" : "1", |
| 307 |
} |
| 308 |
else: |
| 309 |
params = text.parse_query(query) |
| 310 |
|
| 311 |
data = {"_extractor": MyfigurecollectionArticleExtractor} |
| 312 |
base = self.root + "/blogpost/" |
| 313 |
for item_id in util.unique_sequence(self._pagination(params)): |
| 314 |
yield Message.Queue, base + item_id, data |
| 315 |
|
| 316 |
|
| 317 |
def split(html): |
| 318 |
if not html: |
| 319 |
return () |
| 320 |
results = text.split_html(html) |
| 321 |
del results[0] |
| 322 |
return results |
| 323 |
|
| 324 |
|
| 325 |
def split_meta(html): |
| 326 |
items = html.split("<meta ") |
| 327 |
del items[0] |
| 328 |
|
| 329 |
results = [] |
| 330 |
for item in items: |
| 331 |
pos = item.find("</span>") |
| 332 |
name = text.unescape(item[item.rfind(">", 0, pos)+1:pos]) |
| 333 |
if role := text.extr(item, "<em>", "<"): |
| 334 |
name = f"{name} ({text.unescape(role)})" |
| 335 |
results.append(name) |
| 336 |
return results |
| 337 |
|
| 338 |
|
| 339 |
def rm(html): |
| 340 |
return (text.unescape(text.remove_html(html[html.find(">")+1:])) |
| 341 |
if html else "") |