Skip to content

Commit

Permalink
(#1101) Remove archiver key requirement for exh downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Oct 28, 2024
1 parent c1d8128 commit 9116c41
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions lib/LANraragi/Plugin/Download/EHentai.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ sub plugin_info {

return (
# Standard metadata
name => "E*Hentai Downloader",
type => "download",
namespace => "ehdl",
login_from => "ehlogin",
author => "Difegue",
version => "1.0",
name => "E*Hentai Downloader",
type => "download",
namespace => "ehdl",
login_from => "ehlogin",
author => "Difegue",
version => "1.0",
description =>
"Downloads the given e*hentai URL and adds it to LANraragi. This uses GP to call the archiver, so make sure you have enough!",

Expand Down Expand Up @@ -53,27 +53,35 @@ sub provide_url {

$logger->debug("gID: $gID, gToken: $gToken");

# The API can give us archiver keys, but they seem to be invalid...
# Which means it's time for some ol' DOM parsing.
my $response = $lrr_info->{user_agent}->max_redirects(5)->get($url)->result;
my $content = $response->body;
my $dom = Mojo::DOM->new($content);
my $archiverurl = "$domain\/archiver.php?gid=$gID&token=$gToken";
my $content, my $response;

eval {
# Archiver key is stuck in an onclick in the "Archive Download" link.
my $onclick = $dom->at(".g2")->at("a")->attr('onclick');
if ( $onclick =~ /.*or=(.*)'.*/gim ) {
$archKey = $1;
# E-H downloads still require an archiver key for the time being.
if ( $domain eq 'https://e-hentai.org' ) {

# The API can give us archiver keys, but they seem to be invalid...
# Which means it's time for some ol' DOM parsing.
$response = $lrr_info->{user_agent}->max_redirects(5)->get($url)->result;
$content = $response->body;
my $dom = Mojo::DOM->new($content);

eval {
# Archiver key is stuck in an onclick in the "Archive Download" link.
my $onclick = $dom->at(".g2")->at("a")->attr('onclick');
if ( $onclick =~ /.*or=(.*)'.*/gim ) {
$archKey = $1;
}
};

if ( $archKey eq "" ) {
return ( error => "Couldn't retrieve archiver key for gID $gID gToken $gToken" );
}
};

if ( $archKey eq "" ) {
return ( error => "Couldn't retrieve archiver key for gID $gID gToken $gToken" );
# Use archiver key in archiver.php
# https://e-hentai.org/archiver.php?gid=xxxxxxx&token=yyyyyyy&or=441617--08433a31606bc6c730e260c7fcbb2e71699949ce
$archiverurl = "$domain\/archiver.php?gid=$gID&token=$gToken&or=$archKey";
}

# Use archiver key in archiver.php
# https://exhentai.org/archiver.php?gid=1638076&token=817f55f6fd&or=441617--08433a31606bc6c730e260c7fcbb2e71699949ce
my $archiverurl = "$domain\/archiver.php?gid=$gID&token=$gToken&or=$archKey";
$logger->info("Archiver URL: $archiverurl");

# Do a quick GET to check for potential errors
Expand All @@ -97,7 +105,7 @@ sub provide_url {
$content = $response->body;
$logger->debug("/archiver.php result: $content");

if ($content =~ /.*Insufficient funds.*/gim) {
if ( $content =~ /.*Insufficient funds.*/gim ) {
$logger->debug("Not enough GP, aborting download.");
return ( error => "You do not have enough GP to download this URL." );
}
Expand Down

0 comments on commit 9116c41

Please sign in to comment.