[zerochan] implement 'tags' option (#5874)
allow splitting tags into separate lists by category
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
from .booru import BooruExtractor
|
from .booru import BooruExtractor
|
||||||
from ..cache import cache
|
from ..cache import cache
|
||||||
from .. import text, util, exception
|
from .. import text, util, exception
|
||||||
|
import collections
|
||||||
|
|
||||||
BASE_PATTERN = r"(?:https?://)?(?:www\.)?zerochan\.net"
|
BASE_PATTERN = r"(?:https?://)?(?:www\.)?zerochan\.net"
|
||||||
|
|
||||||
@@ -109,6 +110,14 @@ class ZerochanExtractor(BooruExtractor):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def _tags(self, post, page):
|
||||||
|
tags = collections.defaultdict(list)
|
||||||
|
for tag in post["tags"]:
|
||||||
|
category, _, name = tag.partition(":")
|
||||||
|
tags[category].append(name)
|
||||||
|
for key, value in tags.items():
|
||||||
|
post["tags_" + key.lower()] = value
|
||||||
|
|
||||||
|
|
||||||
class ZerochanTagExtractor(ZerochanExtractor):
|
class ZerochanTagExtractor(ZerochanExtractor):
|
||||||
subcategory = "tag"
|
subcategory = "tag"
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ __tests__ = (
|
|||||||
"#category": ("booru", "zerochan", "image"),
|
"#category": ("booru", "zerochan", "image"),
|
||||||
"#class" : zerochan.ZerochanImageExtractor,
|
"#class" : zerochan.ZerochanImageExtractor,
|
||||||
"#urls" : "https://static.zerochan.net/DRAGON.BALL.full.4233756.jpg",
|
"#urls" : "https://static.zerochan.net/DRAGON.BALL.full.4233756.jpg",
|
||||||
|
"#options" : {"tags": True},
|
||||||
|
|
||||||
"author" : "Raydash",
|
"author" : "Raydash",
|
||||||
"date" : "dt:2024-07-23 00:10:51",
|
"date" : "dt:2024-07-23 00:10:51",
|
||||||
@@ -149,9 +150,31 @@ __tests__ = (
|
|||||||
"Source:Fanart from X (Twitter)",
|
"Source:Fanart from X (Twitter)",
|
||||||
"Source:X (Twitter)",
|
"Source:X (Twitter)",
|
||||||
],
|
],
|
||||||
|
"tags_character": [
|
||||||
|
"Piccolo",
|
||||||
|
"Son Gohan",
|
||||||
|
],
|
||||||
|
"tags_mangaka" : [
|
||||||
|
"Raydash",
|
||||||
|
],
|
||||||
|
"tags_series" : [
|
||||||
|
"DRAGON BALL",
|
||||||
|
"DRAGON BALL Z",
|
||||||
|
],
|
||||||
|
"tags_source" : [
|
||||||
|
"Fanart",
|
||||||
|
"Fanart from X (Twitter)",
|
||||||
|
"X (Twitter)",
|
||||||
|
],
|
||||||
|
"tags_theme" : [
|
||||||
|
"Duo",
|
||||||
|
"Green Skin",
|
||||||
|
"Male",
|
||||||
|
"Male Focus",
|
||||||
|
"Two Males",
|
||||||
|
],
|
||||||
"uploader" : "menotbug",
|
"uploader" : "menotbug",
|
||||||
"width" : 750,
|
"width" : 750,
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user