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 plugin (Hentai@Home) #944

Merged
merged 4 commits into from
May 7, 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
82 changes: 82 additions & 0 deletions lib/LANraragi/Plugin/Metadata/HatH.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package LANraragi::Plugin::Metadata::HatH;

use strict;
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);
use LANraragi::Utils::Archive qw(is_file_in_archive extract_file_from_archive);

#Meta-information about your plugin.
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 =>
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wYDFB0m9797jwAAAB1pVFh0Q29tbWVudAAAAAAAQ3Jl\nYXRlZCB3aXRoIEdJTVBkLmUHAAAEbklEQVQ4y1WUPW/TUBSGn3uvHdv5cBqSOrQJgQ4ghqhCAgQM\nIIRAjF2Y2JhA/Q0g8R9YmJAqNoZKTAwMSAwdQEQUypeQEBEkTdtUbdzYiW1sM1RY4m5Hunp1znmf\n94jnz5+nAGmakiQJu7u7KKWwbRspJWma0m63+fHjB9PpFM/z6Ha7FAoFD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FAoIIfjXuW3bnD17NkuJlBLHcdA0\nDYAgCHj27BmO47C6uopM05RyucyLFy/QNA3XdRFCYBgGQRCwubnJhw8fGAwGANRqNTRNI0kSXr58\nyc2bN6nX64RhyP379xFPnjxJlVJIKTl37hydTocoiuh0OszOzmJZFv1+n8FgwJ07d7hy5Qrj8ZiP\nHz/S7/c5ffo0CwsL9Ho9ZmZmEI8ePUoNwyBJEs6cOcPCwgLfvn3j/fv35PN5bNtGKZUdjp8/f3Lr\n1q3svLVaLTzPI4oiLMviL7opJdyaltNwAAAAAElFTkSuQmCC",
parameters => []
);

}

#Mandatory function to be implemented by your plugin
sub get_tags {

shift;
my $lrr_info = shift; # Global info hash

my $logger = get_plugin_logger();
my $file = $lrr_info->{file_path};

my $path_in_archive = is_file_in_archive( $file, "galleryinfo.txt" );
if ($path_in_archive) {

# Extract galleryinfo.txt
my $filepath = extract_file_from_archive( $file, $path_in_archive );

# 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 );
}
}
return ( error => "No tags were found in galleryinfo.txt!" );
} else {
return ( error => "No galleryinfo.txt file found in this archive!" );
}
}

1;
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",
"LANraragi::Plugin::Login::Pixiv", "LANraragi::Plugin::Metadata::Pixiv",
);

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