Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pixiv] Translated tags as a separate keyword? #5250

Closed
AyHa1810 opened this issue Feb 27, 2024 · 5 comments
Closed

[Pixiv] Translated tags as a separate keyword? #5250

AyHa1810 opened this issue Feb 27, 2024 · 5 comments

Comments

@AyHa1810
Copy link

I think there should be a separate keyword for array of translated tags, simply called translated-tags which can be used while also having the original japanese tags keyword available for use.
Maybe add extractors.pixiv.translated-tags as a boolean setting for enabling the keyword if disabled by default?

I can't use extractors.pixiv.tags = "original" because it doesn't seem like there is any way to separate out the jp and en tags within the config file. Also I don't think it is possible to use something like {tags[]['name']}.

@AyHa1810
Copy link
Author

AyHa1810 commented Feb 27, 2024

My use case: I'm trying out creating a custom SQLite database for saving Pixiv metadata using the following postprocessor:

"pixiv": {
    "postprocessors": [{
        "name": "exec",
        "command": [
            "sqlite3",
            "~/gallery-dl/pixiv/pixiv.sqlite3",
            "INSERT OR REPLACE INTO pixiv_gdl (filename, filepath, page_count, rating, tags, translated-tags, title, description, date) VALUES('{filename}.{extension}', '{user['id']} {user['account']}', '{page_count}', '{rating}', '[\"{tags:J\", \"/}\"]', '[\"{translated-tags:J\", \"/}\"]', '{title}', '{caption}', '{date}');"
        ]
    }]
}

@mikf
Copy link
Owner

mikf commented Feb 27, 2024

You could use a python postprocessor and handle/split "original" tags with your own Python function however you want.

translated-tags

Not a valid Python identifier. I'll probably call it tags_translated.

@AyHa1810
Copy link
Author

@mikf can you give me a basic example of how it can can be done?

@mikf
Copy link
Owner

mikf commented Feb 27, 2024

cfg.json

{
    "tags": "original",
    "postprocessors": [
        {
            "name": "python",
            "event": "prepare",
            "function": "~/gdl_utils.py:pixiv_tags"
        }
    ]
}

gdl_utils.py

def pixiv_tags(metadata):

    metadata["tags_translated"] = list(dict.fromkeys(
        tag["translated_name"] or tag["name"]
        for tag in metadata["tags"]
    ))

    metadata["tags_japanese"] =  [
        tag["name"]
        for tag in metadata["tags"]
    ]

This will add a tags_translated and tags_japanese field as available metadata.
The code is more or less just copied from here.

@AyHa1810
Copy link
Author

Hmm, that works. My issue has been solved then. Closing it now

Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants