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

Add a plugin that can parse comics downloaded by h@h #1066

Open
BlackJocker1995 opened this issue Aug 29, 2024 · 2 comments
Open

Add a plugin that can parse comics downloaded by h@h #1066

BlackJocker1995 opened this issue Aug 29, 2024 · 2 comments

Comments

@BlackJocker1995
Copy link

BlackJocker1995 commented Aug 29, 2024

The document downloaded through h@h will contain a galleryinfo.txt file, which contains gallery-related tags.

Here is a project that maps original english to Chinese, which contains a json dataset : EhTagTranslation

Can an option or plugin be added to automate the translation?

I tried to write a function to achieve it.

sub translate_tag_to_cn {
    my $logger = get_plugin_logger();
    my ($list, $temp) = @_;
    my $filename = "/home/koyomi/lanraragi/database/db.text.json"; # json file path
    my $json_text = do {
        open(my $json_fh, "<", $filename)
            or $logger->debug("Can't open $filename: $!\n");
        local $/;
        <$json_fh>;
    };
    my $json = decode_json($json_text);
    my $target = $json->{'data'};
    for my $item (@$list) {
        my ($namespace, $key) = split(/:/, $item);
        $namespace =~ s/^\s+//;
        $key =~ s/\s+$//;
        $logger->debug("name is !$namespace! key is !$key! $item");
        for my $element (@$target) {
            # if $namespace is same with 'namespace',repleacement
            if ($element->{'namespace'} eq $namespace) {
                my $name = $element->{'frontMatters'}->{'name'};
                $item =~ s/$namespace/$name/;
                my $data = $element->{'data'};
                if (exists $data->{$key}) {
                    my $value = $data->{$key}->{'name'};
                    $item =~ s/$key/$value/;
                }
                last;
            }
        }
    }
    
    return $list;
}
@Difegue
Copy link
Owner

Difegue commented Aug 29, 2024

Tag rules in the intended method for auto-replacing incoming tags.
I'm aware it'd be annoying to cram an entire database of translated tags into tag rules, so maybe there's a potential feature in being able to set arbitrary jsons as "tag replacement sources" or something.

In the meantime, all I can recommend would be a script-type plugin that goes through the entire DB and replaces according to your translation DB.

@AkiZZZZZ
Copy link

AkiZZZZZ commented Sep 15, 2024

I wrote a plugin ChineseTagTranslator.pm using ChatGPT that translates the stored English tags into Chinese and adds them to the metadata. However, this plugin does not implement the feature to delete English tags because LRR does not currently support sorting for non-English tags (issue #946).

If you need to delete English tags, you can consider using the Tag Rule feature. The following rule can be used to remove all English tags except for Data_added:

-artist:*
-category:*
-character:*
-cosplayer:*
-female:*
-group:*
-language:*
-male:*
-mixed:*
-other:*
-parody:*
-reclass:*
-source:*

By the way, The reason for excluding the date_added tag is that after changing the namespace to Chinese, the timestamp is no longer able to display in the year/month/day format. I suspect this might be related to HTML, but unfortunately, I am not familiar with HTML. I hope someone can work on this adaptation.

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

No branches or pull requests

5 participants
@Difegue @BlackJocker1995 @AkiZZZZZ and others