Skip to content

Commit 585bccb

Browse files
committed
add new plugin
1 parent ebf0b2e commit 585bccb

1 file changed

Lines changed: 133 additions & 0 deletions

File tree

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package LANraragi::Plugin::Metadata::Ehviewer;
2+
3+
use strict;
4+
use warnings;
5+
use LANraragi::Utils::Logging qw(get_plugin_logger);
6+
use LANraragi::Utils::Archive qw(is_file_in_archive extract_file_from_archive);
7+
use utf8;
8+
# Meta-information about the plugin.
9+
sub plugin_info {
10+
11+
return (
12+
# Standard metadata:
13+
name => 'Ehviewer plugin',
14+
type => 'metadata',
15+
namespace => 'ehviewerplugin',
16+
login_from => "ehlogin",
17+
author => 'Me',
18+
version => '1.0',
19+
description => '使用从Ehviewer下载的文件中的.ehviewer提供的Gid和Token搜索画廊',
20+
icon => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAQXSURBVEhLtZXNT1RnFMbfO5e2YtKmXXXTjRsTV+1CF03T9g+ouybdNKZpHeRrEJgZmC+ZAUEcBgexLahoWpu0VoM1UrAiMiMGRLFKIqO1RsuHJtWmWoR/4Olz3nvvwEwHicYuHt5779x7fu85zzkvSnU0Qmtv0/+jDkr/KfTji5RR6OGL1jNBVirratV4nkxepkzqFbnX4FU8fbZMYjASEXx1ZRSZ+/dwanICKh6GStqQlTLNQuSFPVF81nccoeHTCKd+QSR1Jiu5b+D6Bt/bdLgTJ38dR/rGFFTdNn7XYH2/KkTEl5MjQ5icuYu/Hj/C0PXJrEZ/y2BhYQHrol6YfK97NI30zetQvhKoQBlU+44lkPZoGTAnE8oVD8Fz7Aimpu/CrP4cZs0XMGvd2LgrhMXFRawLV+OlQAW6xy9oiOEvgRnywNhRDTMZYwyRHc8B5UPMZBSVAycwNfMHXDVb9U4NrxuvByvx0dd7UBwoh8tfii6WTiBFPjc2JXfik2/34+19rUsZaUA+xAYJxNPfa0FqCaHWNwexNsjd1rEslFFXiu70IEboSUfqLG7cm0OGevjob7zT2crmIEhnZW28ACQGz0AvMjPTKPaWYE3Zpxi7fQsfdO5GUaCS9a+AUV+G/efPYv7JE5Qe/w6vharwaqgC/YQemxiHavTpJsqCCkGqBn7C4/l5zD18gNkHf/L6H3z4ZRyukEDKdUZdqUGcZzPIvUv8CJbj4NgIzt1kx8W8UDvrLNBqmaz1bsOayi24dOc23t8X1wZrSLBCe5KSgLxW4Sr9rGfUhkgmTX6oloCVTWGIbTwhRm0JNh/sxJvcXZFkEqY3VBc90RB5Fq2FwQ30MJNhB9IShGJHqlZqCWKZZDJFgWRmp+HycdBk5/Wlum038KPiBglYhS56kpaAke0M6tfgnrELGJYBbWYGAhEVgrhsiM5EppllcFFvxXx6Tt6jN0ZEIEPMhMNIPzQk4sGhi4QIWMrkAHbnQCgC3DxWTmUmtemxn09oNfafROJMn574d/e24OMjB5Cm6bfuz2HL0W+gGqqxmXNy6c7vbOVZuHu/t0ACkLMtC5Eu4HHRfO40frw8ZunKRWo8RxviEWznRo5O8LdrEwgN9hFSgzJuRu5/uHoZjYyhWuqh2ghoi+RBRDxllZ9l4pTrw4+taYldJCvPLtm5LpOIpqtdLE0TW5Zl060rAB5PGpDg4ZlTLhtksMMMGpoVg2lJQOkcymCLGjqgGGx5YNADwymRzoKAHIgAnGvpbRkkCSq7lQ6S1QZo6TmwO8gxWaQzIECCt/F4STDOfzJZDhJJcNY8ByBaCZBYDnAyedr/Z4EKSHadBfA6fw5EUiYnA1E7M3BWy4cVALI6pZP6CyQfoD0QgG1yex4gEcW/X0p3UAMSG4wAAAAASUVORK5CYII=',
21+
22+
# Custom arguments:
23+
parameters => [
24+
{ type => 'bool', desc => '如果可用,请保存原始日文标题,而不是英文或 ' . '罗马化标题' },
25+
{ type => 'bool', desc => '保存额外的时间戳(发布时间)和上传者元数据' },
26+
{ type => 'bool', desc => '使用 ExHentai 链接作为源而不是 E-Hentai 链接' }
27+
],
28+
oneshot_arg => '输入有效的 EH 库 URL 以将此 EH 库中的元数据复制到此 LANraragi 存档',
29+
cooldown => 4
30+
);
31+
}
32+
33+
# Mandatory function implemented by every plugin.
34+
sub get_tags {
35+
36+
shift;
37+
my $lrr_info = shift;
38+
my $ua = $lrr_info->{user_agent};
39+
my $logger = get_plugin_logger();
40+
my $gallery_id = '';
41+
my $gallery_token = '';
42+
my ( $save_jpn_title, $save_additional_metadata, $use_exhentai ) = @_;
43+
44+
# Use the URL from oneshot parameters or source tag first when applicable.
45+
if ( $lrr_info->{oneshot_param} =~ /e(?:x|-)hentai\.org\/g\/(\d+)\/([0-9a-z]+)/i ) {
46+
$gallery_id = $1;
47+
$gallery_token = $2;
48+
$logger->debug("Directly using gallery ID $gallery_id and token $gallery_token from oneshot parameters.");
49+
} elsif ( $lrr_info->{existing_tags} =~ /source:e(?:x|-)hentai\.org\/g\/(\d+)\/([0-9a-z]+)/i ) {
50+
$gallery_id = $1;
51+
$gallery_token = $2;
52+
$logger->debug("Directly using gallery ID $gallery_id and token $gallery_token from source tag.");
53+
} else {
54+
55+
# Use the gallery ID and token in the filename to directly locate the gallery. Note that the regex does not have
56+
# "$" at the end, so the filename can have other information attached after the identifiers.
57+
58+
#获取压缩包内.ehviewer文件
59+
my $path_in_archive = is_file_in_archive( $lrr_info->{file_path}, ".ehviewer" );
60+
61+
my $filepath;
62+
my $delete_after_parse;
63+
64+
#把.ehviewer从解压包提取出来
65+
if($path_in_archive) {
66+
$filepath = extract_file_from_archive( $lrr_info->{file_path}, $path_in_archive );
67+
$logger->debug("Found file in archive at $filepath");
68+
$delete_after_parse = 1;
69+
} else {
70+
return ( error => "No in-archive .ehviewer file found!" );
71+
}
72+
73+
#打开.ehviewer
74+
open( my $fh, '<:encoding(UTF-8)', $filepath )
75+
or return ( error => "Could not open $filepath!" );
76+
77+
#读取.ehviewer第三行和第四行的画廊Gid和Token
78+
while( <$fh> ) {
79+
if( $. == 3 ) {
80+
$gallery_id = $_;
81+
chomp $gallery_id;
82+
83+
$logger->debug("Gid:" . $gallery_id);
84+
}elsif( $. == 4 ) {
85+
$gallery_token = $_;
86+
chomp $gallery_token;
87+
88+
$logger->debug("Gtoken:" . $gallery_token);
89+
last;
90+
}
91+
}
92+
93+
#删除解压的文件
94+
if ($delete_after_parse){
95+
unlink $filepath;
96+
}
97+
98+
if ( $gallery_id eq '' || $gallery_token eq '' ) {
99+
my $file_error = 'Skipping archive without connecting to EH, because the archive title does not have valid '
100+
. 'gallery identifiers from Mayriad\'s EH Master Script.';
101+
$logger->error($file_error);
102+
return ( error => $file_error );
103+
}
104+
}
105+
106+
# Retrieve metadata directly using EH API.
107+
$logger->info('Source identified. Calling E-Hentai metadata plugin to retrieve metadata from EH API.');
108+
my ( $eh_all_tags, $eh_title ) = LANraragi::Plugin::Metadata::EHentai::get_tags_from_EH( $ua, $gallery_id,
109+
$gallery_token, $save_jpn_title, $save_additional_metadata );
110+
111+
# Add source URL and title if possible.
112+
if ( $eh_all_tags ne "" ) {
113+
114+
# Title is always updated to hide the identifiers and also to reflect title changes due to rename petitions.
115+
my %metadata = ( tags => $eh_all_tags, title => $eh_title );
116+
117+
# Add the source tag outside get_tags_from_EH(), so that this tag is only added when metadata has been
118+
# successfully retrieved; otherwise $metadata{tags} may only contain this source tag and truly untagged
119+
# galleries may be incorrectly hidden.
120+
my $host = ( $use_exhentai ? 'exhentai.org' : 'e-hentai.org' );
121+
$metadata{tags} .= ", source:$host/g/$gallery_id/$gallery_token";
122+
123+
# Return a hash containing the new metadata to be added to LRR.
124+
return %metadata;
125+
} else {
126+
my $source_error = 'No matching EH gallery found. The archive title may have incorrect gallery identifiers.';
127+
$logger->error($source_error);
128+
return ( error => $source_error );
129+
}
130+
131+
}
132+
133+
1;

0 commit comments

Comments
 (0)