Skip to content

Commit

Permalink
Add test and sample galleryinfo.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed May 7, 2024
1 parent d83ea34 commit 1132db8
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 33 deletions.
65 changes: 34 additions & 31 deletions lib/LANraragi/Plugin/Metadata/HatH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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/PY2dnBtm0qlQpKKZIkIQgCer0eW1tbDIdDJpMJc3NzuK5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Jhw8fGAwGANRqNTRNI0kSXr58\nyc2bN6nX64RhyP379xFPnjxJlVJIKTl37hydTocoiuh0OszOzmJZFv1+n8FgwJ07d7hy5Qrj8ZiP\nHz/S7/c5ffo0CwsL9Ho9ZmZmEI8ePUoNwyBJEs6cOcPCwgLfvn3j/fv35PN5bNtGKZUdjp8/f3Lr\n1q3svLVaLTzPI4oiLMviL7opJdyaltNwAAAAAElFTkSuQmCC",
parameters => []
);
Expand All @@ -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!" );
}
Expand Down
2 changes: 0 additions & 2 deletions tests/LANraragi/Plugin/Metadata/ChaikaFile.t
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
49 changes: 49 additions & 0 deletions tests/LANraragi/Plugin/Metadata/HatH.t
Original file line number Diff line number Diff line change
@@ -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();
1 change: 1 addition & 0 deletions tests/modules.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/samples/hath/galleryinfo.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1132db8

Please sign in to comment.