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

[nHentai] Add support to set upload date in timestamp field using epoch stamp #1077

Merged
merged 2 commits into from
Sep 29, 2024
Merged
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
16 changes: 13 additions & 3 deletions lib/LANraragi/Plugin/Metadata/nHentai.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sub plugin_info {
<br><i class='fa fa-exclamation-circle'></i> This plugin will use the source: tag of the archive if it exists.",
icon =>
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\nB3RJTUUH4wYCFA8s1yKFJwAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH\nAAACL0lEQVQ4y6XTz0tUURQH8O+59773nLFcaGWTk4UUVCBFiJs27VxEQRH0AyRo4x8Q/Qtt2rhr\nU6soaCG0KYKSwIhMa9Ah+yEhZM/5oZMG88N59717T4sxM8eZCM/ycD6Xwznn0pWhG34mh/+PA8mk\n8jO5heziP0sFYwfgMDFQJg4IUjmquSFGG+OIlb1G9li5kykgTgvzSoUCaIYlo8/Igcjpj5wOkARp\n8AupP0uzJLijCY4zzoXOxdBLshAgABr8VOp7bpAXDEI7IBrhdksnjNr3WzI4LaIRV9fk2iAaYV/y\nA1dPiYjBAALgpQxnhV2XzTCAGWGeq7ACBvCdzKQyTH+voAm2hGlpcmQt2Bc2K+ymAhWPxTzPDQLt\nOKo1FiNBQaArq9WNRQwEgKl7XQ1duzSRSn/88vX0qf7DPQddx1nI5UfHxt+m0sLYPiP3shRAG8MD\nok1XEEXR/EI2ly94nrNYWG6Nx0/2Hp2b94dv34mlZge1e4hVCJ4jc6tl9ZP803n3/i4lpdyzq2N0\n7M3DkSeF5ZVYS8v1qxcGz5+5eey4nPDbmGdE9FpGeWErVNe2tTabX3r0+Nk3PwOgXFkdfz99+exA\nMtFZITEt9F23mpLG0hYTVQCKpfKPlZ/rqWKpYoAPcTmpginW76QBbb0OBaBaDdjaDbNlJmQE3/d0\nMYoaybU9126oPkrEhpr+U2wjtoVVGBowkslEsVSupRKdu0Mduq7q7kqExjSS3V2dvwDLavx0eczM\neAAAAABJRU5ErkJggg==",
parameters => [],
parameters => [ { type => "bool", desc => "Fetch date uploaded and set timestamp tag" } ],
oneshot_arg => "nHentai Gallery URL (Will attach tags matching this exact gallery to your archive)"
);

Expand All @@ -43,6 +43,7 @@ sub get_tags {
shift;
my $lrr_info = shift; # Global info hash
my $ua = $lrr_info->{user_agent}; # UserAgent from login plugin
my ($add_uploaded) = @_; # Parameters

my $logger = get_plugin_logger();

Expand Down Expand Up @@ -77,7 +78,7 @@ sub get_tags {

$logger->debug("Detected nHentai gallery ID is $galleryID");

my %hashdata = get_tags_from_NH( $galleryID, $ua );
my %hashdata = get_tags_from_NH( $galleryID, $ua, $add_uploaded );

$logger->info( "Sending the following tags to LRR: " . $hashdata{tags} );

Expand Down Expand Up @@ -213,9 +214,14 @@ sub get_title_from_json {
return $json->{"title"}{"pretty"};
}

sub get_upload_from_json {
my ($json) = @_;
return $json->{"upload_date"};
}

sub get_tags_from_NH {

my ( $gID, $ua ) = @_;
my ( $gID, $ua, $add_uploaded ) = @_;

my %hashdata = ( tags => "" );

Expand All @@ -224,6 +230,10 @@ sub get_tags_from_NH {

if ($json) {
my @tags = get_tags_from_json($json);
if ($add_uploaded) {
my @upload = get_upload_from_json($json);
push( @tags, "timestamp:@upload");
}
push( @tags, "source:nhentai.net/g/$gID" ) if ( @tags > 0 );

# Use NH's "pretty" names (romaji titles without extraneous data we already have like (Event)[Artist], etc)
Expand Down