LANraragi icon indicating copy to clipboard operation
LANraragi copied to clipboard

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

Open BlackJocker1995 opened this issue 1 year ago • 2 comments

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;
}

BlackJocker1995 avatar Aug 29 '24 03:08 BlackJocker1995

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.

Difegue avatar Aug 29 '24 13:08 Difegue

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.

AkiZZZZZ avatar Sep 15 '24 03:09 AkiZZZZZ

Admin Settings -> Tag Rules: Implementing automatic replacement when adding files

see: https://github.com/chu-shen/LANraragi-scripts?tab=readme-ov-file#%E6%A0%87%E7%AD%BE%E4%B8%AD%E6%96%87%E5%8C%96%E8%84%9A%E6%9C%AC

Translation data is automatically updated every week, but I am not sure how to automatically update Tag Rules

image


another solution: https://github.com/zhy201810576/ETagConverter

You need manually triger this script, only applicable to existing files

chu-shen avatar Dec 30 '24 06:12 chu-shen

Modified based on ChineseTagTranslator and EHentai

  1. It is recommended to check the first 6 options and run automatically
  2. Only applicable to ZH_CN
  3. MetaData can be captured normally after the folder downloaded by H@H is compressed, other methods have not been tested
  4. Old tags are directly cleared by operating the database; currently the return value of the Meta plugin can only add new tags

Reference: https://github.com/AkiZZZZZ/LANraragi/blob/dev/lib/LANraragi/Plugin/Metadata/ChineseTagTranslator.pm https://github.com/Difegue/LANraragi/blob/dev/lib/LANraragi/Plugin/Metadata/EHentai.pm

ZhEHentai.pm.txt

o-TwT-o avatar May 28 '25 15:05 o-TwT-o

Thank you all for the proposals.

BlackJocker1995 avatar May 29 '25 03:05 BlackJocker1995