Skip to content

Commit

Permalink
Add Title parsing and updating to ComicInfo (#1098)
Browse files Browse the repository at this point in the history
Enables the ability to push the title found in ComicInfo files to LRR and update it accordingly.  I think this should be controlled via the global toggle for if plugins should update the title.

Check for title in tags on unit tests
  • Loading branch information
shinji257 authored Oct 24, 2024
1 parent edacd1e commit ee5c12a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
9 changes: 7 additions & 2 deletions lib/LANraragi/Plugin/Metadata/ComicInfo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ sub get_tags {
my $url;
my $artist;
my $lang;
my $title;
my $result = Mojo::DOM->new->xml(1)->parse($stringxml)->at('Genre');

if ( defined $result ) {
Expand All @@ -85,6 +86,10 @@ sub get_tags {
if ( defined $result ) {
$lang = $result->text;
}
$result = Mojo::DOM->new->xml(1)->parse($stringxml)->at('Title');
if ( defined $result ) {
$title = $result->text;
}

#Delete local file
unlink $filepath;
Expand All @@ -105,7 +110,7 @@ sub get_tags {
my $tags = join( ", ", @found_tags );

$logger->info("Sending the following tags to LRR: $tags");
return ( tags => $tags );
return ( tags => $tags, title => $title );
}

sub try_add_tags {
Expand All @@ -121,4 +126,4 @@ sub try_add_tags {
return @found_tags;
}

1;
1;
26 changes: 17 additions & 9 deletions tests/LANraragi/Plugin/Metadata/ComicInfo.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ note("00 - [れむ] 夜伽妻 [DL版]");

# Since this is calling the sub directly and not in an object context,
# we pass a dummy string as first parameter to replace the object.
my $returned_tags = LANraragi::Plugin::Metadata::ComicInfo::get_tags( "", \%dummyhash);
my %returned_tags = trap { LANraragi::Plugin::Metadata::ComicInfo::get_tags( "", \%dummyhash); };

my $expected_title = "COMIC Anthurium 2021-09 [Digital]";
my $expected_group_tag = "group:Achumuchi, group:Ashita, group:Cool Kyou Shinja, group:Danimaru, group:Eba, group:Emuo, group:Fushoku, group:Inukami Inoji, group:Itaba Hiroshi, group:Kaiduka, group:Ken Sogen, group:Kosuke Haruhito, group:Maeda Momo, group:Miyano Kintarou, group:Rei, group:Sasahiro, group:Sekine Hajime, group:Ushinomiya, group:Yamamoto Ahiru, group:Yamamoto Zenzen";
my $expected_artist_tag = "artist:Achumuchi, artist:Ashita, artist:Cool Kyou Shinja, artist:Danimaru, artist:Eba, artist:Emuo, artist:Fushoku, artist:Inukami Inoji, artist:Itaba Hiroshi, artist:Kaiduka, artist:Ken Sogen, artist:Kosuke Haruhito, artist:Maeda Momo, artist:Miyano Kintarou, artist:Rei, artist:Sasahiro, artist:Sekine Hajime, artist:Ushinomiya, artist:Yamamoto Ahiru, artist:Yamamoto Zenzen";
my $expected_source_tag = "source:https://nhentai.net/g/369909/";
my $expected_lang_tag = "language:ja";
my $expected_genre_tags = "Anal, Anthology, Beauty Mark, Big Breasts, Collar, Defloration, Eye-Covering Bang, Glasses, Gyaru, Huge Breasts, Incest, Inverted Nipples, Leotard, Long Tongue, Maid, Netorare, Pantyhose, Piercing, Ponytail, Robot, Schoolboy Uniform, Schoolgirl Uniform, Sister, Stockings, Sweating, Tomboy";
my @tag_array = ($expected_group_tag, $expected_artist_tag, $expected_source_tag, $expected_lang_tag, $expected_genre_tags);
my $expected_tags = join( ", ", @tag_array );
is( $returned_tags, $expected_tags, "correct tags" );
is( $returned_tags{tags}, $expected_tags, "correct tags" );
is( $returned_tags{title}, $expected_title, "correct title" );
}

note("01 - 夜伽妻");
Expand All @@ -58,16 +60,18 @@ note("01 - 夜伽妻");

# Since this is calling the sub directly and not in an object context,
# we pass a dummy string as first parameter to replace the object.
my $returned_tags = LANraragi::Plugin::Metadata::ComicInfo::get_tags( "", \%dummyhash);
my %returned_tags = trap { LANraragi::Plugin::Metadata::ComicInfo::get_tags( "", \%dummyhash); };

my $expected_title = "[れむ] 夜伽妻 [DL版]";
my $expected_group_tag = "group:Remu";
my $expected_artist_tag = "artist:Remu";
my $expected_source_tag = "source:https://e-hentai.org/g/2470908/3dd0f5801e/";
my $expected_lang_tag = "language:ja";
my $expected_genre_tags = "Ahegao, Bbw, Big Areolae, Big Ass, Big Breasts, Big Nipples, Big Penis, Blowjob, Bondage, Cheating, Crotch Tattoo, Dark Skin, Facial Hair, Filming, Glasses, Glasses, Gyaru, Hairy, Huge Breasts, Impregnation, Maid, Milf, Nakadashi, Netorare, Oil, Paizuri, Pregnant, Prostitution, Schoolgirl Uniform, Swinging, Tall Girl, Tankoubon, Very Long Hair, Voyeurism, Widow, X-Ray";
my @tag_array = ($expected_group_tag, $expected_artist_tag, $expected_source_tag, $expected_lang_tag, $expected_genre_tags);
my $expected_tags = join( ", ", @tag_array );
is( $returned_tags, $expected_tags, "correct tags" );
is( $returned_tags{tags}, $expected_tags, "correct tags" );
is( $returned_tags{title}, $expected_title, "correct title" );
}

note("02 - よつばと! 第01巻");
Expand All @@ -84,15 +88,17 @@ note("02 - よつばと! 第01巻");

# Since this is calling the sub directly and not in an object context,
# we pass a dummy string as first parameter to replace the object.
my $returned_tags = LANraragi::Plugin::Metadata::ComicInfo::get_tags( "", \%dummyhash);
my %returned_tags = trap { LANraragi::Plugin::Metadata::ComicInfo::get_tags( "", \%dummyhash); };

my $expected_title = "よつばと! 第01巻";
my $expected_group_tag = "group:あずまきよひこ";
my $expected_artist_tag = "artist:あずまきよひこ";
my $expected_lang_tag = "language:ja";
my $expected_genre_tags = "Comedy, Shounen, Slice of Life";
my @tag_array = ($expected_group_tag, $expected_artist_tag, $expected_lang_tag, $expected_genre_tags);
my $expected_tags = join( ", ", @tag_array );
is( $returned_tags, $expected_tags, "correct tags" );
is( $returned_tags{tags}, $expected_tags, "correct tags" );
is( $returned_tags{title}, $expected_title, "correct title" );
}

note("03 - 異種姦オーガズム");
Expand All @@ -109,15 +115,17 @@ note("03 - 異種姦オーガズム");

# Since this is calling the sub directly and not in an object context,
# we pass a dummy string as first parameter to replace the object.
my $returned_tags = LANraragi::Plugin::Metadata::ComicInfo::get_tags( "", \%dummyhash);
my %returned_tags = trap { LANraragi::Plugin::Metadata::ComicInfo::get_tags( "", \%dummyhash); };

my $expected_title = "異種姦オーガズム";
my $expected_group_tag = "group:7zu7";
my $expected_lang_tag = "language:zh";
my $expected_genre_tags = "translated, artist:7zu7, male:monster, Manga, Uploaded";
my @tag_array = ($expected_group_tag, $expected_lang_tag, $expected_genre_tags);
my $expected_tags = join( ", ", @tag_array );
is( $returned_tags, $expected_tags, "correct tags" );
is( $returned_tags{tags}, $expected_tags, "correct tags" );
is( $returned_tags{title}, $expected_title, "correct title" );
}


done_testing();
done_testing();

0 comments on commit ee5c12a

Please sign in to comment.