Skip to content

Commit

Permalink
[pixiv] change 'translated-tags' option (#1507)
Browse files Browse the repository at this point in the history
- rename to 'tags'
- use string-values: "japanese", "translated", "noop"
- remove duplicate entries for "translated" tags
  • Loading branch information
mikf committed Apr 29, 2021
1 parent 5b4da4b commit fa519f9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
14 changes: 9 additions & 5 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1332,14 +1332,18 @@ Description
Also download related artworks.


extractor.pixiv.translated-tags
-------------------------------
extractor.pixiv.tags
--------------------
Type
``bool``
``string``
Default
``false``
``"japanese"``
Description
Provide translated ´`tags``.
Controls how ``tags`` metadata is transformed.

* `"japanese"`: List of original Japanese tags
* `"translated"`: List of translated tags
* `"noop"`: Unmodified list of both Japanese and translated tags


extractor.pixiv.ugoira
Expand Down
2 changes: 1 addition & 1 deletion docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"pixiv":
{
"avatar": false,
"translated-tags": false,
"tags": "japanese",
"ugoira": true
},
"reactor":
Expand Down
22 changes: 15 additions & 7 deletions gallery_dl/extractor/pixiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ def __init__(self, match):
Extractor.__init__(self, match)
self.api = PixivAppAPI(self)
self.load_ugoira = self.config("ugoira", True)
self.translated_tags = self.config("translated-tags", False)

def items(self):
tkey = "translated_name" if self.translated_tags else "name"
tags = self.config("tags", "japanese")
if tags == "noop":
transform_tags = None
elif tags == "translated":
def transform_tags(work):
work["tags"] = list(set(
tag["translated_name"] or tag["name"]
for tag in work["tags"]))
else:
def transform_tags(work):
work["tags"] = [tag["name"] for tag in work["tags"]]

ratings = {0: "General", 1: "R-18", 2: "R-18G"}
metadata = self.metadata()

Expand All @@ -45,12 +55,10 @@ def items(self):
del work["meta_single_page"]
del work["image_urls"]
del work["meta_pages"]

if transform_tags:
transform_tags(work)
work["num"] = 0
if self.translated_tags:
work["untranslated_tags"] = [
tag["name"] for tag in work["tags"]
]
work["tags"] = [tag[tkey] or tag["name"] for tag in work["tags"]]
work["date"] = text.parse_datetime(work["create_date"])
work["rating"] = ratings.get(work["x_restrict"])
work["suffix"] = ""
Expand Down

0 comments on commit fa519f9

Please sign in to comment.