-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add plugin (Hentai@Home) a plugin that can collects metadata embedded into your archives by HentaiAtHome Downloader's galleryinfo txt files. * Fix package name * Add test and sample galleryinfo.txt --------- Co-authored-by: Difegue <[email protected]> Co-authored-by: Difegue <[email protected]>
- Loading branch information
1 parent
7397258
commit 6439966
Showing
5 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\nIIRAjF2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0jYcPHyKE\n4OjRo8RxTBRF9Pt95ubmMud93+f79+80m03k/v4+UspDKDWNRqPBu3fvSNOUtbU16vU6ly5dwnEc\ncrkcrutimib5fD4zxzRNVldXWVpaQqysrKSdTofLly8zmUwoFAoIIfjXuW3bnD17NkuJlBLHcdA0\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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |