diff --git a/lib/LANraragi/Plugin/Metadata/HatH.pm b/lib/LANraragi/Plugin/Metadata/HatH.pm index 5c0c2478e..0132dabef 100644 --- a/lib/LANraragi/Plugin/Metadata/HatH.pm +++ b/lib/LANraragi/Plugin/Metadata/HatH.pm @@ -6,7 +6,6 @@ use warnings; #Plugins can freely use all Perl packages already installed on the system #Try however to restrain yourself to the ones already installed for LRR (see tools/cpanfile) to avoid extra installations by the end-user. - #You can also use the LRR Internal API when fitting. use LANraragi::Model::Plugins; use LANraragi::Utils::Logging qw(get_plugin_logger); @@ -17,13 +16,13 @@ sub plugin_info { return ( #Standard metadata - name => "HentaiAtHome plugin", - type => "metadata", - namespace => "hentaiathome", - author => "lily", - version => "0.1", - description => "Collects metadata embedded into your archives by HentaiAtHome Downloader's galleryinfo txt files.", - icon => + name => "HentaiAtHome plugin", + type => "metadata", + namespace => "hentaiathome", + author => "lily", + version => "0.1", + description => "Collects metadata embedded into your archives by HentaiAtHome Downloader's galleryinfo txt files.", + icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wYDFB0m9797jwAAAB1pVFh0Q29tbWVudAAAAAAAQ3Jl\nYXRlZCB3aXRoIEdJTVBkLmUHAAAEbklEQVQ4y1WUPW/TUBSGn3uvHdv5cBqSOrQJgQ4ghqhCAgQM\nIIRAjF2Y2JhA/Q0g8R9YmJAqNoZKTAwMSAwdQEQUypeQEBEkTdtUbdzYiW1sM1RY4m5Hunp1znmf\n94jnz5+nAGmakiQJu7u7KKWwbRspJWma0m63+fHjB9PpFM/z6Ha7FAoFDMNga2uLx48fkyQJ29vb\nyCRJSNMUz/PY2dnBtm0qlQpKKZIkIQgCer0eW1tbDIdDJpMJc3NzuK5Lt9tF13WWl5dJkoRyuYyU\nUrK3t0ccx9TrdQzD4F/HSilM08Q0TWzbplqtUqvVKBaLKKV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mJZFv1+n8FgwJ07d7hy5Qrj8ZiP\nHz/S7/c5ffo0CwsL9Ho9ZmZmEI8ePUoNwyBJEs6cOcPCwgLfvn3j/fv35PN5bNtGKZUdjp8/f3Lr\n1q3svLVaLTzPI4oiLMviL7opJdyaltNwAAAAAElFTkSuQmCC", parameters => [] ); @@ -47,30 +46,34 @@ sub get_tags { # Open it open( my $fh, '<:encoding(UTF-8)', $filepath ) - or return ( error => "Could not open $filepath!" ); - - my $tag = ""; - my $title = ""; - while ( my $line = <$fh> ) { - # Check if the line starts with Title: - if ( $line =~ m/Title: (.*)/ ) { - $title = $1; - } - # Check if the line starts with Uploaded By: - if ( $line =~ m/Uploaded By: (.*)/ ) { - $tag .= "uploader:$1, "; - } - # Check if the line starts with Upload Time: - if ( $line =~ m/Upload Time: (.*)/ ) { - $tag .= "Upload Time:$1, "; - } - # Check if the line starts with TAGS: - if ( $line =~ m/Tags: (.*)/ ) { - $tag .= $1; - return ( tags => $tag , title => $title ); - } + or return ( error => "Could not open $filepath!" ); + + my $tag = ""; + my $title = ""; + while ( my $line = <$fh> ) { + + # Check if the line starts with Title: + if ( $line =~ m/Title: (.*)/ ) { + $title = $1; + } + + # Check if the line starts with Uploaded By: + if ( $line =~ m/Uploaded By: (.*)/ ) { + $tag .= "uploader:$1, "; + } + + # Check if the line starts with Upload Time: + if ( $line =~ m/Upload Time: (.*)/ ) { + $tag .= "upload_time:$1, "; + } + + # Check if the line starts with TAGS: + if ( $line =~ m/Tags: (.*)/ ) { + $tag .= $1; + return ( tags => $tag, title => $title ); } - return ( error => "No tags were found in galleryinfo.txt!" ); + } + return ( error => "No tags were found in galleryinfo.txt!" ); } else { return ( error => "No galleryinfo.txt file found in this archive!" ); } diff --git a/tests/LANraragi/Plugin/Metadata/ChaikaFile.t b/tests/LANraragi/Plugin/Metadata/ChaikaFile.t index 2e850726c..29ba2ee13 100644 --- a/tests/LANraragi/Plugin/Metadata/ChaikaFile.t +++ b/tests/LANraragi/Plugin/Metadata/ChaikaFile.t @@ -16,8 +16,6 @@ my $cwd = getcwd(); my $SAMPLES = "$cwd/tests/samples"; require "$cwd/tests/mocks.pl"; -use_ok('LANraragi::Plugin::Metadata::ChaikaFile'); - my @tags_list = ( 'full censorship', 'female:sole female', 'male:sole male', 'artist:kemuri haku', 'female:tall girl', 'female:cunnilingus', 'male:shotacon', 'female:defloration', diff --git a/tests/LANraragi/Plugin/Metadata/HatH.t b/tests/LANraragi/Plugin/Metadata/HatH.t new file mode 100644 index 000000000..ab0e3ed47 --- /dev/null +++ b/tests/LANraragi/Plugin/Metadata/HatH.t @@ -0,0 +1,49 @@ +# LANraragi::Plugin::Metadata::HatH +use strict; +use warnings; +use utf8; +use Data::Dumper; +use File::Temp qw(tempfile); +use File::Copy "cp"; + +use Cwd qw( getcwd ); + +use Test::Trap; +use Test::More; +use Test::Deep; + +my $cwd = getcwd(); +my $SAMPLES = "$cwd/tests/samples"; +require "$cwd/tests/mocks.pl"; + +my @tags_list = ( + 'upload_time:2020-11-11 00:00', 'uploader:Katlan', 'language:english', 'language:translated', + 'artist:yyyy', 'male:dark skin', 'female:fox girl' +); + +use_ok('LANraragi::Plugin::Metadata::HatH'); + +note('testing reading galleryinfo.txt...'); +{ + # Copy the sample json to a temporary directory as it's deleted once parsed + my ( $fh, $filename ) = tempfile(); + cp( $SAMPLES . "/hath/galleryinfo.txt", $fh ); + + no warnings 'once', 'redefine'; + local *LANraragi::Plugin::Metadata::HatH::get_plugin_logger = sub { return get_logger_mock(); }; + local *LANraragi::Plugin::Metadata::HatH::extract_file_from_archive = sub { $filename }; + local *LANraragi::Plugin::Metadata::HatH::is_file_in_archive = sub { 1 }; + + my %dummyhash = ( file_path => "test" ); + + my $saveTitle = 0; + my $addextra = 0; + my $addother = 0; + my $addsource = ''; + my %hath_tags = trap { LANraragi::Plugin::Metadata::HatH::get_tags( "", \%dummyhash ); }; + + is( $hath_tags{title}, "xxxxxxxxxx", 'gallery title' ); + is( $hath_tags{tags}, join( ", ", @tags_list ), 'gallery tag list' ); +} + +done_testing(); diff --git a/tests/modules.t b/tests/modules.t index 323efbd1a..ded771a20 100644 --- a/tests/modules.t +++ b/tests/modules.t @@ -43,6 +43,7 @@ my @modules = ( "LANraragi::Plugin::Metadata::Hitomi", "LANraragi::Plugin::Metadata::Hentag", "LANraragi::Plugin::Metadata::HentagOnline", "LANraragi::Plugin::Metadata::ComicInfo", "LANraragi::Plugin::Metadata::ChaikaFile", "LANraragi::Plugin::Metadata::Ksk", + "LANraragi::Plugin::Metadata::HatH" ); # Test all modules load properly diff --git a/tests/samples/hath/galleryinfo.txt b/tests/samples/hath/galleryinfo.txt new file mode 100644 index 000000000..2a7bd8306 --- /dev/null +++ b/tests/samples/hath/galleryinfo.txt @@ -0,0 +1,11 @@ +Title: xxxxxxxxxx +Upload Time: 2020-11-11 00:00 +Uploaded By: Katlan +Downloaded: 2021-12-26 22:09 +Tags: language:english, language:translated, artist:yyyy, male:dark skin, female:fox girl + +Uploader's Comments: + +[...] + +Downloaded from E-Hentai Galleries by the Hentai@Home Downloader <3 \ No newline at end of file