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 support for yet another version of info.yaml #1023

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/LANraragi/Plugin/Metadata/Ksk.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ sub tags_from_ksk_yaml {
handle_tag_yaml( "series:", $parody, \@found_tags );
handle_tag_yaml( "magazine:", $magazine, \@found_tags );

# Koharu-version tags. Uses namespaces, and keys are lowercase
if (!defined($title)) {
$title = $hash->{"title"};
}
handle_tag_yaml( "", $hash->{"general"}, \@found_tags );
handle_tag_yaml( "male:", $hash->{"male"}, \@found_tags );
handle_tag_yaml( "female:", $hash->{"female"}, \@found_tags );
handle_tag_yaml( "mixed:", $hash->{"mixed"}, \@found_tags );
handle_tag_yaml( "other:", $hash->{"other"}, \@found_tags );
handle_tag_yaml( "artist:", $hash->{"artist"}, \@found_tags );
handle_tag_yaml( "language:", $hash->{"language"}, \@found_tags );
handle_tag_yaml( "source:", $hash->{"source"}, \@found_tags );

if ($assume_english) {
push( @found_tags, "language:english" );
}
Expand All @@ -104,7 +117,7 @@ sub handle_tag_yaml {
foreach my $tag (@$yamldata) {
push( @{ $_[2] }, "$namespace$tag" );
}
} else {
} elsif ( defined($yamldata) ) {
push( @{ $_[2] }, "$namespace$yamldata" );
}

Expand Down
20 changes: 20 additions & 0 deletions tests/LANraragi/Plugin/Metadata/Ksk.t
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,24 @@ note("test support for info.yaml");
is( $ko_tags{title}, "My Immortal", "Loads data from info.yaml" );
}

note("test support for koharu info.yaml");
{
my ( $fh, $filename ) = tempfile();
cp( $SAMPLES . "/ksk/fake_koharu.yaml", $fh );

no warnings 'once', 'redefine';
local *LANraragi::Plugin::Metadata::Ksk::get_plugin_logger = sub { return get_logger_mock(); };
local *LANraragi::Plugin::Metadata::Ksk::extract_file_from_archive = sub { $filename };
local *LANraragi::Plugin::Metadata::Ksk::is_file_in_archive = sub { my $fn = $_[1]; return $fn eq "info.yaml"; };

my %dummyhash = ( file_path => "test" );

my %ko_tags = LANraragi::Plugin::Metadata::Ksk::get_tags( "", \%dummyhash, 0 );
is( $ko_tags{title}, "[Marcus Aurelius] Meditations", "Didn't handle title" );

my $expected_tags =
"first, second, third, male:emperor, male:philosopher, male:stoic, female:ass, female:titties, mixed:group, other:philosophy, artist:marcus aurelius, language:greek, source:SchaleNetwork:/g/1337/b00b1e5";
is( $ko_tags{tags}, $expected_tags, "Didn't handle tags" );
}

done_testing();
21 changes: 21 additions & 0 deletions tests/samples/ksk/fake_koharu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
source: SchaleNetwork:/g/1337/b00b1e5
title: '[Marcus Aurelius] Meditations'
general:
- first
- second
- third
artist:
- marcus aurelius
male:
- emperor
- philosopher
- stoic
female:
- ass
- titties
mixed:
- group
language:
- greek
other:
- philosophy