diff --git a/.perltidyrc b/.perltidyrc new file mode 100644 index 000000000..b4b3796c2 --- /dev/null +++ b/.perltidyrc @@ -0,0 +1,6 @@ +-bar +-ce +-vt=2 +-nsfs +-nolq +-l=132 \ No newline at end of file diff --git a/lib/LANraragi.pm b/lib/LANraragi.pm index 74bb4f10b..64fc1afdb 100755 --- a/lib/LANraragi.pm +++ b/lib/LANraragi.pm @@ -29,8 +29,8 @@ sub startup { my $config = $self->plugin( 'Config', { file => 'lrr.conf' } ); # Load package.json to get version/vername - my $packagejson = decode_json(Mojo::File->new('package.json')->slurp); - + my $packagejson = decode_json( Mojo::File->new('package.json')->slurp ); + my $version = $packagejson->{version}; my $vername = $packagejson->{version_name}; @@ -70,8 +70,7 @@ sub startup { if ($devmode) { $self->mode('development'); - $self->LRR_LOGGER->info( - "LANraragi $version (re-)started. (Debug Mode)"); + $self->LRR_LOGGER->info("LANraragi $version (re-)started. (Debug Mode)"); #Tell the mojo logger to print to stdout as well $self->log->on( @@ -83,11 +82,9 @@ sub startup { print "\n"; } ); - } - else { + } else { $self->mode('production'); - $self->LRR_LOGGER->info( - "LANraragi $version started. (Production Mode)"); + $self->LRR_LOGGER->info("LANraragi $version started. (Production Mode)"); } #Plugin listing @@ -104,28 +101,25 @@ sub startup { } #Start Background worker - if ( -e "./.shinobu-pid" && eval { retrieve("./.shinobu-pid"); }) { + if ( -e "./.shinobu-pid" && eval { retrieve("./.shinobu-pid"); } ) { # Deserialize process - my $proc = ${retrieve("./.shinobu-pid")}; + my $proc = ${ retrieve("./.shinobu-pid") }; my $pid = $proc->pid; - $self->LRR_LOGGER->info( - "Terminating previous Shinobu Worker if it exists... (PID is $pid)" - ); - $proc->kill(); + $self->LRR_LOGGER->info("Terminating previous Shinobu Worker if it exists... (PID is $pid)"); + $proc->kill(); } my $proc = start_shinobu(); - $self->LRR_LOGGER->debug( - "Shinobu Worker new PID is " . $proc->pid ); + $self->LRR_LOGGER->debug( "Shinobu Worker new PID is " . $proc->pid ); LANraragi::Utils::Routing::apply_routes($self); $self->LRR_LOGGER->info("Routing done! Ready to receive requests."); # Warm search cache $self->LRR_LOGGER->info("Warming up search cache..."); - LANraragi::Model::Search::do_search("","",0,"title","asc", 0, 0); + LANraragi::Model::Search::do_search( "", "", 0, "title", "asc", 0, 0 ); $self->LRR_LOGGER->info("Done!"); } diff --git a/lib/LANraragi/Controller/Api.pm b/lib/LANraragi/Controller/Api.pm index 45c2a4af5..cdf1e34ee 100755 --- a/lib/LANraragi/Controller/Api.pm +++ b/lib/LANraragi/Controller/Api.pm @@ -26,14 +26,12 @@ sub check_id_parameter { my ( $mojo, $endpoint ) = @_; my $id = $mojo->req->param('id') || 0; - unless ( $id ) { + unless ($id) { #High-level API documentation! $mojo->render( - json => { - error => "API usage: $endpoint?id=YOUR_ID" - }, - status => 400 + json => { error => "API usage: $endpoint?id=YOUR_ID" }, + status => 400 ); } return $id; @@ -41,14 +39,14 @@ sub check_id_parameter { # Renders the basic success API JSON template. sub success { - my ($mojo, $operation) = @_; + my ( $mojo, $operation ) = @_; $mojo->render( - json => { - operation => $operation, - success => 1 - } - ); + json => { + operation => $operation, + success => 1 + } + ); } sub serve_archivelist { @@ -58,8 +56,8 @@ sub serve_archivelist { } sub serve_opds { - my $self = shift; - $self->render( text => LANraragi::Model::Api::generate_opds_catalog($self), format => 'xml'); + my $self = shift; + $self->render( text => LANraragi::Model::Api::generate_opds_catalog($self), format => 'xml' ); } sub serve_untagged_archivelist { @@ -70,17 +68,17 @@ sub serve_untagged_archivelist { sub serve_tag_stats { my $self = shift; - $self->render( json => from_json(LANraragi::Model::Stats::build_tag_json)); + $self->render( json => from_json(LANraragi::Model::Stats::build_tag_json) ); } sub serve_backup { my $self = shift; - $self->render( json => from_json(LANraragi::Model::Backup::build_backup_JSON)); + $self->render( json => from_json(LANraragi::Model::Backup::build_backup_JSON) ); } sub drop_database { LANraragi::Utils::Database::drop_database(); - success(shift, "drop_database"); + success( shift, "drop_database" ); } sub clean_database { @@ -97,7 +95,7 @@ sub clean_database { sub clear_cache { invalidate_cache(); - success(shift, "clear_cache"); + success( shift, "clear_cache" ); } # Uses a plugin, with the standard global arguments and a provided oneshot argument. @@ -108,15 +106,15 @@ sub use_plugin { sub serve_thumbnail { my $self = shift; - my $id = check_id_parameter($self, "thumbnail") || return; - LANraragi::Model::Api::serve_thumbnail($self, $id); + my $id = check_id_parameter( $self, "thumbnail" ) || return; + LANraragi::Model::Api::serve_thumbnail( $self, $id ); } # Use RenderFile to get the file of the provided id to the client. sub serve_file { my $self = shift; - my $id = check_id_parameter($self, "servefile") || return; + my $id = check_id_parameter( $self, "servefile" ) || return; my $redis = $self->LRR_CONF->get_redis(); my $file = $redis->hget( $id, "file" ); @@ -126,30 +124,25 @@ sub serve_file { # Serve an archive page from the temporary folder, using RenderFile. sub serve_page { - my $self = shift; - my $id = check_id_parameter($self, "servefile") || return; - LANraragi::Model::Api::serve_page($self, $id); + my $self = shift; + my $id = check_id_parameter( $self, "servefile" ) || return; + LANraragi::Model::Api::serve_page( $self, $id ); } sub extract_archive { my $self = shift; - my $id = check_id_parameter($self, "extract") || return; + my $id = check_id_parameter( $self, "extract" ) || return; my $readerjson; - eval { - $readerjson = - LANraragi::Model::Reader::build_reader_JSON( $self, $id, "0", "0" ); - }; + eval { $readerjson = LANraragi::Model::Reader::build_reader_JSON( $self, $id, "0", "0" ); }; my $err = $@; if ($err) { - $self->render( - json => { - error => $err - }, - status => 500); - } - else { + $self->render( + json => { error => $err }, + status => 500 + ); + } else { $self->render( json => decode_json($readerjson) ); } } @@ -173,12 +166,13 @@ sub clean_tempfolder { sub clear_new { my $self = shift; - my $id = check_id_parameter($self, "clear_new") || return; + my $id = check_id_parameter( $self, "clear_new" ) || return; my $redis = $self->LRR_CONF->get_redis(); # Just set isnew to false for the provided ID. - if ($redis->hget( $id, "isnew") ne "false") { + if ( $redis->hget( $id, "isnew" ) ne "false" ) { + # Bust search cache...partially! LANraragi::Utils::Database::invalidate_isnew_cache(); @@ -198,12 +192,12 @@ sub clear_new { #Clear new flag in all archives. sub clear_new_all { - my $self = shift; + my $self = shift; my $redis = $self->LRR_CONF->get_redis(); # Get all archives thru redis # 40-character long keys only => Archive IDs - my @keys = $redis->keys('????????????????????????????????????????'); + my @keys = $redis->keys('????????????????????????????????????????'); foreach my $idall (@keys) { $redis->hset( $idall, "isnew", "false" ); @@ -212,7 +206,7 @@ sub clear_new_all { # Bust search cache completely, this is a big change invalidate_cache(); $redis->quit(); - success($self, "clear_new_all"); + success( $self, "clear_new_all" ); } #Use all enabled plugins on an archive ID. Tags are automatically saved in the background. @@ -220,13 +214,12 @@ sub clear_new_all { sub use_enabled_plugins { my $self = shift; - my $id = check_id_parameter($self, "autoplugin") || return; + my $id = check_id_parameter( $self, "autoplugin" ) || return; my $redis = $self->LRR_CONF->get_redis(); if ( $redis->exists($id) && LANraragi::Model::Config->enable_autotag ) { - my ( $succ, $fail, $addedtags ) = - LANraragi::Model::Plugins::exec_enabled_plugins_on_file($id); + my ( $succ, $fail, $addedtags ) = LANraragi::Model::Plugins::exec_enabled_plugins_on_file($id); $self->render( json => { @@ -251,7 +244,7 @@ sub use_enabled_plugins { sub shinobu_status { my $self = shift; - my $shinobu = ${retrieve("./.shinobu-pid")}; + my $shinobu = ${ retrieve("./.shinobu-pid") }; $self->render( json => { @@ -264,16 +257,16 @@ sub shinobu_status { sub stop_shinobu { my $self = shift; - my $shinobu = ${retrieve("./.shinobu-pid")}; + my $shinobu = ${ retrieve("./.shinobu-pid") }; #commit sudoku $shinobu->kill(); - success($self, "shinobu_stop"); + success( $self, "shinobu_stop" ); } sub restart_shinobu { my $self = shift; - my $shinobu = ${retrieve("./.shinobu-pid")}; + my $shinobu = ${ retrieve("./.shinobu-pid") }; #commit sudoku $shinobu->kill(); diff --git a/lib/LANraragi/Controller/Backup.pm b/lib/LANraragi/Controller/Backup.pm index 3edd4ceda..4c3a1aba8 100755 --- a/lib/LANraragi/Controller/Backup.pm +++ b/lib/LANraragi/Controller/Backup.pm @@ -12,7 +12,7 @@ sub index { if ( $self->req->param('dobackup') ) { my $json = LANraragi::Model::Backup::build_backup_JSON(); -#Write json to file in the user directory and serve that file through render_static + #Write json to file in the user directory and serve that file through render_static my $file = $self->LRR_CONF->get_userdir . '/backup.json'; if ( -e $file ) { unlink $file } @@ -25,8 +25,7 @@ sub index { $self->render_file( filepath => $file ); - } - else { #Get with no parameters => Regular HTML printout + } else { #Get with no parameters => Regular HTML printout $self->render( template => "backup", title => $self->LRR_CONF->get_htmltitle, @@ -52,8 +51,7 @@ sub restore { success => 1 } ); - } - else { + } else { $self->render( json => { operation => "restore_backup", diff --git a/lib/LANraragi/Controller/Batch.pm b/lib/LANraragi/Controller/Batch.pm index dbde84010..a0648a7c8 100644 --- a/lib/LANraragi/Controller/Batch.pm +++ b/lib/LANraragi/Controller/Batch.pm @@ -26,13 +26,12 @@ sub index { #Only show IDs that still have their files present. foreach my $id (@keys) { my $zipfile = $redis->hget( $id, "file" ); - my $title = $redis->hget( $id, "title" ); + my $title = $redis->hget( $id, "title" ); $title = redis_decode($title); - if (-e $zipfile) { - $arclist .= - "
  • " - . "
  • "; + if ( -e $zipfile ) { + $arclist .= "
  • "; + $arclist .= "
  • "; } } @@ -78,14 +77,15 @@ sub socket { my $plugin = get_plugin($pluginname); #Global arguments can come from the database or the user override - my @args = @{ $command->{"args"} }; - my $timeout = $command->{"timeout"} || 0; + my @args = @{ $command->{"args"} }; + my $timeout = $command->{"timeout"} || 0; if ($plugin) { #If the array is empty(no overrides) if ( !@args ) { $logger->debug("No user overrides given."); + # Try getting the saved defaults @args = get_plugin_parameters($pluginname); } @@ -97,40 +97,35 @@ sub socket { return; } $logger->debug("Processing $id"); - + my %plugin_result; - eval { - %plugin_result = LANraragi::Model::Plugins::exec_metadata_plugin( - $plugin, $id, "", @args ); - }; + eval { %plugin_result = LANraragi::Model::Plugins::exec_metadata_plugin( $plugin, $id, "", @args ); }; if ($@) { $plugin_result{error} = $@; } #If the plugin exec returned tags, add them - unless ( exists $plugin_result{error} ) { - LANraragi::Utils::Database::add_tags($id, $plugin_result{new_tags}); + unless ( exists $plugin_result{error} ) { + LANraragi::Utils::Database::add_tags( $id, $plugin_result{new_tags} ); - if (exists $plugin_result{title}) { - LANraragi::Utils::Database::set_title($id, $plugin_result{title}); + if ( exists $plugin_result{title} ) { + LANraragi::Utils::Database::set_title( $id, $plugin_result{title} ); } } # Send reply message for completed archive $client->send( - { - json => { + { json => { id => $id, success => exists $plugin_result{error} ? 0 : 1, message => $plugin_result{error}, tags => $plugin_result{new_tags}, - title => exists $plugin_result{title} ? $plugin_result{title}:"" + title => exists $plugin_result{title} ? $plugin_result{title} : "" } } ); - } - else { + } else { $client->finish( 1001 => 'This plugin does not exist' ); } } diff --git a/lib/LANraragi/Controller/Config.pm b/lib/LANraragi/Controller/Config.pm index 1d8fafb4b..740ec9ac1 100755 --- a/lib/LANraragi/Controller/Config.pm +++ b/lib/LANraragi/Controller/Config.pm @@ -3,7 +3,7 @@ use Mojo::Base 'Mojolicious::Controller'; use Encode; -use LANraragi::Utils::Generic qw(generate_themes_selector generate_themes_header remove_spaces remove_newlines); +use LANraragi::Utils::Generic qw(generate_themes_selector generate_themes_header remove_spaces remove_newlines); use LANraragi::Utils::TempFolder qw(get_tempsize); use Authen::Passphrase::BlowfishCrypt; @@ -73,13 +73,13 @@ sub save_config { #for checkboxes, #we check if the parameter exists in the POST to return either 1 or 0. - enablepass => ( scalar $self->req->param('enablepass') ? '1' : '0' ), - autotag => ( scalar $self->req->param('autotag') ? '1' : '0' ), - devmode => ( scalar $self->req->param('devmode') ? '1' : '0' ), - enableresize => ( scalar $self->req->param('enableresize') ? '1' : '0' ), - blackliston => ( scalar $self->req->param('blackliston') ? '1' : '0' ), - nofunmode => ( scalar $self->req->param('nofunmode') ? '1' : '0' ), - tagregex => ( scalar $self->req->param('tagregex') ? '1' : '0' ) + enablepass => ( scalar $self->req->param('enablepass') ? '1' : '0' ), + autotag => ( scalar $self->req->param('autotag') ? '1' : '0' ), + devmode => ( scalar $self->req->param('devmode') ? '1' : '0' ), + enableresize => ( scalar $self->req->param('enableresize') ? '1' : '0' ), + blackliston => ( scalar $self->req->param('blackliston') ? '1' : '0' ), + nofunmode => ( scalar $self->req->param('nofunmode') ? '1' : '0' ), + tagregex => ( scalar $self->req->param('tagregex') ? '1' : '0' ) ); #only add newpassword field as password if enablepass = 1 @@ -100,17 +100,16 @@ sub save_config { } } - #Verifications. - if ( $self->req->param('newpassword') ne $self->req->param('newpassword2') ) - { #Password check + #Password check + if ( $self->req->param('newpassword') ne $self->req->param('newpassword2') ) { $success = 0; $errormess = "Mismatched passwords."; } # Numbers only in fields w. numbers - if ( $confhash{pagesize} =~ /\D+/ || - $confhash{readerquality} =~ /\D+/ || - $confhash{sizethreshold} =~ /\D+/) { + if ( $confhash{pagesize} =~ /\D+/ + || $confhash{readerquality} =~ /\D+/ + || $confhash{sizethreshold} =~ /\D+/ ) { $success = 0; $errormess = "Invalid characters."; } @@ -118,17 +117,16 @@ sub save_config { #Did all the checks pass ? if ($success) { - # Clean up the user's inputs for non-toggle options and encode for redis insertion + # Clean up the user's inputs for non-toggle options and encode for redis insertion foreach my $key ( keys %confhash ) { - remove_spaces ( $confhash{$key} ); + remove_spaces( $confhash{$key} ); remove_newlines( $confhash{$key} ); - $confhash{$key} = encode_utf8 ( $confhash{$key} ); - $self->LRR_LOGGER->debug("Saving $key with value ".$confhash{$key}); + $confhash{$key} = encode_utf8( $confhash{$key} ); + $self->LRR_LOGGER->debug( "Saving $key with value " . $confhash{$key} ); } -#for all keys of the hash, add them to the redis config hash with the matching keys. - $redis->hset( "LRR_CONFIG", $_, $confhash{$_}, sub { } ) - for keys %confhash; + #for all keys of the hash, add them to the redis config hash with the matching keys. + $redis->hset( "LRR_CONFIG", $_, $confhash{$_}, sub { } ) for keys %confhash; $redis->wait_all_responses; } diff --git a/lib/LANraragi/Controller/Edit.pm b/lib/LANraragi/Controller/Edit.pm index 543162a33..3bfcfbd77 100755 --- a/lib/LANraragi/Controller/Edit.pm +++ b/lib/LANraragi/Controller/Edit.pm @@ -73,11 +73,9 @@ sub index { if ( $redis->exists($id) ) { my %hash = $redis->hgetall($id); - my ( $name, $title, $tags, $file, $thumbhash ) = - @hash{qw(name title tags file thumbhash)}; + my ( $name, $title, $tags, $file, $thumbhash ) = @hash{qw(name title tags file thumbhash)}; - ( $_ = redis_decode($_) ) - for ( $name, $title, $tags ); + ( $_ = redis_decode($_) ) for ( $name, $title, $tags ); #Build plugin listing my @pluginlist = get_plugins("metadata"); @@ -98,8 +96,9 @@ sub index { csshead => generate_themes_header($self), version => $self->LRR_VERSION ); + } else { + $self->redirect_to('index'); } - else { $self->redirect_to('index') } } 1; diff --git a/lib/LANraragi/Controller/Index.pm b/lib/LANraragi/Controller/Index.pm index 216cb1e32..de3c05403 100755 --- a/lib/LANraragi/Controller/Index.pm +++ b/lib/LANraragi/Controller/Index.pm @@ -17,7 +17,7 @@ sub random_archive { my $redis = $self->LRR_CONF->get_redis(); - # We get a random archive ID. + # We get a random archive ID. # We check for the length to (sort-of) avoid not getting an archive ID. # TODO: This will loop infinitely if there are zero archives in store. until ($archiveexists) { @@ -26,10 +26,9 @@ sub random_archive { $self->LRR_LOGGER->debug("Found key $archive"); #We got a key, but does the matching archive still exist on the server? - if ( length($archive) == 40 - && $redis->type($archive) eq "hash" - && $redis->hexists( $archive, "file" ) ) - { + if ( length($archive) == 40 + && $redis->type($archive) eq "hash" + && $redis->hexists( $archive, "file" ) ) { my $arclocation = $redis->hget( $archive, "file" ); if ( -e $arclocation ) { $archiveexists = 1; } } @@ -49,17 +48,15 @@ sub index { my $force = 0; #Checking if the user still has the default password enabled - my $ppr = Authen::Passphrase->from_rfc2307( $self->LRR_CONF->get_password ); - my $passcheck = - ( $ppr->match("kamimamita") && $self->LRR_CONF->enable_pass ); + my $ppr = Authen::Passphrase->from_rfc2307( $self->LRR_CONF->get_password ); + my $passcheck = ( $ppr->match("kamimamita") && $self->LRR_CONF->enable_pass ); - my $userlogged = - $self->LRR_CONF->enable_pass == 0 || $self->session('is_logged'); + my $userlogged = $self->LRR_CONF->enable_pass == 0 || $self->session('is_logged'); #Read favtags if there are any and craft an array to use in templating my @validFavs; - for ( my $i = 1 ; $i < 6 ; $i++ ) { + for ( my $i = 1; $i < 6; $i++ ) { my $favTag = $self->LRR_CONF->get_favtag($i); if ( $favTag ne "" ) { @@ -70,17 +67,17 @@ sub index { $redis->quit(); $self->render( - template => "index", - version => $self->LRR_VERSION, - title => $self->LRR_CONF->get_htmltitle, - pagesize => $self->LRR_CONF->get_pagesize, - userlogged => $userlogged, - motd => $self->LRR_CONF->get_motd, - cssdrop => generate_themes_selector, - csshead => generate_themes_header($self), - favtags => \@validFavs, - usingdefpass => $passcheck, - debugmode => $self->app->mode eq "development" + template => "index", + version => $self->LRR_VERSION, + title => $self->LRR_CONF->get_htmltitle, + pagesize => $self->LRR_CONF->get_pagesize, + userlogged => $userlogged, + motd => $self->LRR_CONF->get_motd, + cssdrop => generate_themes_selector, + csshead => generate_themes_header($self), + favtags => \@validFavs, + usingdefpass => $passcheck, + debugmode => $self->app->mode eq "development" ); } diff --git a/lib/LANraragi/Controller/Logging.pm b/lib/LANraragi/Controller/Logging.pm index 3ffe6fa19..4475cfb6b 100644 --- a/lib/LANraragi/Controller/Logging.pm +++ b/lib/LANraragi/Controller/Logging.pm @@ -23,36 +23,34 @@ sub index { sub print_lines_from_file { - my ($mojo, $file) = @_; + my ( $mojo, $file ) = @_; # Number of lines to read - my $lines = 100; + my $lines = 100; my $logdir = get_logdir(); if ( $mojo->req->param('lines') ) { $lines = $mojo->req->param('lines'); } - $mojo->render( - text => get_lines_from_file( $lines, $logdir."/$file.log" ) - ); + $mojo->render( text => get_lines_from_file( $lines, $logdir . "/$file.log" ) ); } sub print_general { - print_lines_from_file(shift, "lanraragi"); + print_lines_from_file( shift, "lanraragi" ); } sub print_shinobu { - print_lines_from_file(shift, "shinobu"); + print_lines_from_file( shift, "shinobu" ); } sub print_plugins { - print_lines_from_file(shift, "plugins"); + print_lines_from_file( shift, "plugins" ); } sub print_redis { - print_lines_from_file(shift, "redis"); + print_lines_from_file( shift, "redis" ); } sub print_mojo { @@ -61,7 +59,7 @@ sub print_mojo { #Depending on the mode, look for development or production.log my $mode = $self->app->mode; - print_lines_from_file($self, $mode); + print_lines_from_file( $self, $mode ); } 1; diff --git a/lib/LANraragi/Controller/Login.pm b/lib/LANraragi/Controller/Login.pm index d61223b27..5553efffb 100755 --- a/lib/LANraragi/Controller/Login.pm +++ b/lib/LANraragi/Controller/Login.pm @@ -18,8 +18,7 @@ sub check { $self->session( is_logged => 1 ); $self->session( expiration => 60 * 60 * 24 ); $self->redirect_to('index'); - } - else { + } else { $self->render( template => "login", title => $self->LRR_CONF->get_htmltitle, @@ -37,8 +36,8 @@ sub check { sub logged_in { my $self = shift; return 1 - if $self->session('is_logged') || - $self->LRR_CONF->enable_pass == 0; + if $self->session('is_logged') + || $self->LRR_CONF->enable_pass == 0; $self->redirect_to('login'); return 0; } @@ -46,17 +45,15 @@ sub logged_in { #For APIs, the request can also be authentified with a valid API Key. sub logged_in_api { my $self = shift; - my $key = $self->req->param('key') || ''; + my $key = $self->req->param('key') || ''; return 1 - if ($key ne "" && $key eq $self->LRR_CONF->get_apikey) || - $self->session('is_logged') || - $self->LRR_CONF->enable_pass == 0; + if ( $key ne "" && $key eq $self->LRR_CONF->get_apikey ) + || $self->session('is_logged') + || $self->LRR_CONF->enable_pass == 0; $self->render( - json => { - error => "This API is protected and requires login or an API Key." - }, - status => 401 - ); + json => { error => "This API is protected and requires login or an API Key." }, + status => 401 + ); return 0; } @@ -73,9 +70,9 @@ sub index { $self->render( template => "login", title => $self->LRR_CONF->get_htmltitle, - cssdrop => generate_themes_selector, - csshead => generate_themes_header($self), - version => $self->LRR_VERSION + cssdrop => generate_themes_selector, + csshead => generate_themes_header($self), + version => $self->LRR_VERSION ); } diff --git a/lib/LANraragi/Controller/Plugins.pm b/lib/LANraragi/Controller/Plugins.pm index 98ad225f0..ac10e3e03 100644 --- a/lib/LANraragi/Controller/Plugins.pm +++ b/lib/LANraragi/Controller/Plugins.pm @@ -43,15 +43,16 @@ sub craft_plugin_array { my $namespace = $pluginfo->{namespace}; my @redisparams = get_plugin_parameters($namespace); - if ($pluginfo->{type} ne "login") { + if ( $pluginfo->{type} ne "login" ) { + # Add whether the plugin is enabled to the hash directly $pluginfo->{enabled} = is_plugin_enabled($namespace); } # Add redis values to the members of the parameters array my @paramhashes = (); - my $counter = 0; - foreach my $param (@{$pluginfo->{parameters}}) { + my $counter = 0; + foreach my $param ( @{ $pluginfo->{parameters} } ) { $param->{value} = $redisparams[$counter]; push @paramhashes, $param; $counter++; @@ -98,19 +99,20 @@ sub save_config { #Loop through the namespaced request parameters #Start at 1 because that's where TT2's loop.count starts - for ( my $i = 1 ; $i <= $argcount ; $i++ ) { + for ( my $i = 1; $i <= $argcount; $i++ ) { my $param = $namespace . "_CFG_" . $i; - + my $value = $self->req->param($param); # Check if the parameter exists in the request - if ( $value ) { - push (@customargs, $value ); + if ($value) { + push( @customargs, $value ); } else { + # Checkboxes don't exist in the parameter list if they're not checked. - push (@customargs, ""); + push( @customargs, "" ); } - + } my $encodedargs = encode_json( \@customargs ); @@ -152,10 +154,10 @@ sub process_upload { my $filetext = $file->slurp; my $plugintype = ""; - if ($filetext =~ /package LANraragi::Plugin::(Login|Metadata|Scripts)::/) { + if ( $filetext =~ /package LANraragi::Plugin::(Login|Metadata|Scripts)::/ ) { $plugintype = $1; } else { - my $errormess= "Could not find a valid plugin package type in the plugin \"$filename\"!"; + my $errormess = "Could not find a valid plugin package type in the plugin \"$filename\"!"; $logger->error($errormess); $self->render( @@ -170,7 +172,7 @@ sub process_upload { return; } - my $dir = getcwd() . ("/lib/LANraragi/Plugin/$plugintype/"); + my $dir = getcwd() . ("/lib/LANraragi/Plugin/$plugintype/"); my $output_file = $dir . $filename; $logger->info("Uploading new plugin $filename to $output_file ..."); @@ -191,8 +193,7 @@ sub process_upload { }; if ($@) { - $logger->error( - "Could not instantiate plugin at namespace $pluginclass!"); + $logger->error("Could not instantiate plugin at namespace $pluginclass!"); $logger->error($@); unlink($output_file); @@ -222,16 +223,14 @@ sub process_upload { } ); - } - else { + } else { $self->render( json => { operation => "upload_plugin", name => $file->filename, success => 0, - error => "This file isn't a plugin - " - . "Please upload a Perl Module (.pm) file." + error => "This file isn't a plugin - " . "Please upload a Perl Module (.pm) file." } ); } diff --git a/lib/LANraragi/Controller/Reader.pm b/lib/LANraragi/Controller/Reader.pm index 621cc0d2f..f8f987b17 100755 --- a/lib/LANraragi/Controller/Reader.pm +++ b/lib/LANraragi/Controller/Reader.pm @@ -26,8 +26,8 @@ sub index { #Get a computed archive name if the archive exists my $arcname = $redis->hget( $id, "title" ); - my $tags = $redis->hget( $id, "tags" ); - my $filename = $redis->hget( $id, "file" ); + my $tags = $redis->hget( $id, "tags" ); + my $filename = $redis->hget( $id, "file" ); $arcname = redis_decode($arcname); $tags = redis_decode($tags); $filename = redis_decode($filename); @@ -42,18 +42,14 @@ sub index { my $imgpaths = ""; #Load a json matching pages to paths - eval { - $imgpaths = - LANraragi::Model::Reader::build_reader_JSON( $self, $id, $force, - $thumbreload ); - }; + eval { $imgpaths = LANraragi::Model::Reader::build_reader_JSON( $self, $id, $force, $thumbreload ); }; if ($@) { my $err = $@; # Add some more info for RAR5 - if ($filename =~ /^.+\.rar$/ && $err =~ /Unrecognized archive format.*$/) { - $err.= "\n RAR5 archives are not supported."; + if ( $filename =~ /^.+\.rar$/ && $err =~ /Unrecognized archive format.*$/ ) { + $err .= "\n RAR5 archives are not supported."; } $self->render( @@ -75,11 +71,10 @@ sub index { cssdrop => generate_themes_selector, csshead => generate_themes_header($self), version => $self->LRR_VERSION, - userlogged => $self->LRR_CONF->enable_pass == 0 - || $self->session('is_logged') + userlogged => $self->LRR_CONF->enable_pass == 0 || $self->session('is_logged') ); - } - else { + } else { + # No parameters back the fuck off $self->redirect_to('index'); } diff --git a/lib/LANraragi/Controller/Search.pm b/lib/LANraragi/Controller/Search.pm index e74d62c7f..6111ad89f 100644 --- a/lib/LANraragi/Controller/Search.pm +++ b/lib/LANraragi/Controller/Search.pm @@ -10,9 +10,9 @@ sub handle_datatables { my $redis = $self->LRR_CONF->get_redis(); my $req = $self->req; - my $draw = $req->param('draw'); - my $start = $req->param('start'); - my $length = $req->param('length'); + my $draw = $req->param('draw'); + my $start = $req->param('start'); + my $length = $req->param('length'); # Jesus christ what the fuck datatables my $filter = $req->param('search[value]'); @@ -21,39 +21,36 @@ sub handle_datatables { my $sortkey = $req->param("columns[$sortindex][name]"); # See if specific column searches were made - my $i = 0; + my $i = 0; my $columnfilter = ""; my $newfilter = 0; my $untaggedfilter = 0; - while ($req->param("columns[$i][name]")) { + while ( $req->param("columns[$i][name]") ) { # Favtags (tags column) - if ($req->param("columns[$i][name]") eq "tags") { + if ( $req->param("columns[$i][name]") eq "tags" ) { $columnfilter = $req->param("columns[$i][search][value]"); - } - + } + # New filter (isnew column) - if ($req->param("columns[$i][name]") eq "isnew") { + if ( $req->param("columns[$i][name]") eq "isnew" ) { $newfilter = $req->param("columns[$i][search][value]") eq "true"; - } + } # Untagged filter (untagged column) - if ($req->param("columns[$i][name]") eq "untagged") { + if ( $req->param("columns[$i][name]") eq "untagged" ) { $untaggedfilter = $req->param("columns[$i][search][value]") eq "true"; - } + } $i++; } - if ($sortorder && $sortorder eq 'desc') { $sortorder = 1; } - else { $sortorder = 0; } + $sortorder = ( $sortorder && $sortorder eq 'desc' ) ? 1 : 0; - my ($total, $filtered, @ids) = - LANraragi::Model::Search::do_search($filter, $columnfilter, $start, $sortkey, $sortorder, $newfilter, $untaggedfilter); + my ( $total, $filtered, @ids ) = + LANraragi::Model::Search::do_search( $filter, $columnfilter, $start, $sortkey, $sortorder, $newfilter, $untaggedfilter ); - $self->render( - json => get_datatables_object($draw, $redis, $total, $filtered, @ids) - ); + $self->render( json => get_datatables_object( $draw, $redis, $total, $filtered, @ids ) ); $redis->quit(); } @@ -72,15 +69,12 @@ sub handle_api { my $newfilter = $req->param('newonly'); my $untaggedf = $req->param('untaggedonly'); - if ($sortorder && $sortorder eq 'desc') { $sortorder = 1; } - else { $sortorder = 0; } + $sortorder = ( $sortorder && $sortorder eq 'desc' ) ? 1 : 0; - my ($total, $filtered, @ids) = - LANraragi::Model::Search::do_search($filter, "", $start, $sortkey, $sortorder, $newfilter eq "true", $untaggedf eq "true"); + my ( $total, $filtered, @ids ) = + LANraragi::Model::Search::do_search( $filter, "", $start, $sortkey, $sortorder, $newfilter eq "true", $untaggedf eq "true" ); - $self->render( - json => get_datatables_object(0, $redis, $total, $filtered, @ids) - ); + $self->render( json => get_datatables_object( 0, $redis, $total, $filtered, @ids ) ); $redis->quit(); } @@ -91,18 +85,18 @@ sub get_datatables_object { my ( $draw, $redis, $total, $filtered, @keys ) = @_; - # Get archive data from keys + # Get archive data from keys my @data = (); foreach my $key (@keys) { - push @data, LANraragi::Utils::Database::build_archive_JSON($redis, $key->{id}); + push @data, LANraragi::Utils::Database::build_archive_JSON( $redis, $key->{id} ); } # Create json object matching the datatables structure return { - draw => $draw, - recordsTotal => $total, + draw => $draw, + recordsTotal => $total, recordsFiltered => $filtered, - data => \@data + data => \@data }; } diff --git a/lib/LANraragi/Controller/Stats.pm b/lib/LANraragi/Controller/Stats.pm index 5498c5485..b28d3d8c7 100755 --- a/lib/LANraragi/Controller/Stats.pm +++ b/lib/LANraragi/Controller/Stats.pm @@ -8,7 +8,6 @@ use LANraragi::Utils::Generic qw(generate_themes_selector generate_themes_header sub index { my $self = shift; - $self->render( template => "stats", title => $self->LRR_CONF->get_htmltitle, diff --git a/lib/LANraragi/Controller/Upload.pm b/lib/LANraragi/Controller/Upload.pm index 6d4efeb07..f82e3f11d 100755 --- a/lib/LANraragi/Controller/Upload.pm +++ b/lib/LANraragi/Controller/Upload.pm @@ -29,24 +29,26 @@ sub process_upload { # Update $tempfile to the exact reference created by the host filesystem # This is done by finding the first (and only) file in $tempdir. - find(sub { + find( + sub { return if -d $_; $tempfile = $File::Find::name; $filename = $_; - }, $tempdir); + }, + $tempdir + ); # Compute an ID here my $id = LANraragi::Utils::Database::compute_id($tempfile); $self->LRR_LOGGER->debug("ID of uploaded file is $id"); # Future home of the file - my $output_file = $self->LRR_CONF->get_userdir . '/' - . $filename; + my $output_file = $self->LRR_CONF->get_userdir . '/' . $filename; #Check if the ID is already in the database, and #that the file it references still exists on the filesystem my $redis = $self->LRR_CONF->get_redis(); - my $isdupe = $redis->exists($id) && -e $redis->hget($id, "file"); + my $isdupe = $redis->exists($id) && -e $redis->hget( $id, "file" ); if ( -e $output_file || $isdupe ) { @@ -65,49 +67,47 @@ sub process_upload { : "A file with the same name is present in the Library." } ); - } - else { + } else { # Add the file to the database ourselves so Shinobu doesn't do it # This allows autoplugin to be ran ASAP. - LANraragi::Utils::Database::add_archive_to_redis( $id, $output_file, - $redis ); + LANraragi::Utils::Database::add_archive_to_redis( $id, $output_file, $redis ); # Invalidate search cache ourselves, Shinobu won't do it since the file is already in the database invalidate_cache(); # Move the file to the content folder. # Move to a .tmp first in case copy to the content folder takes a while... - move($tempfile,$output_file.".upload"); + move( $tempfile, $output_file . ".upload" ); + # Then rename inside the content folder itself to proc Shinobu. - move($output_file.".upload", $output_file); + move( $output_file . ".upload", $output_file ); if ( -e $output_file ) { $self->render( - json => { - operation => "upload", - name => $file->filename, - type => $uploadMime, - success => 1, - id => $id - } + json => { + operation => "upload", + name => $file->filename, + type => $uploadMime, + success => 1, + id => $id + } ); } else { $self->render( - json => { - operation => "upload", - name => $file->filename, - type => $uploadMime, - success => 0, - error => "The file couldn't be moved to your content folder!" - } + json => { + operation => "upload", + name => $file->filename, + type => $uploadMime, + success => 0, + error => "The file couldn't be moved to your content folder!" + } ); } - + } $redis->quit(); - } - else { + } else { $self->render( json => { @@ -126,12 +126,12 @@ sub index { my $self = shift; $self->render( - template => "upload", - title => $self->LRR_CONF->get_htmltitle, - autoplugin => $self->LRR_CONF->enable_autotag, - cssdrop => generate_themes_selector, - csshead => generate_themes_header($self), - version => $self->LRR_VERSION + template => "upload", + title => $self->LRR_CONF->get_htmltitle, + autoplugin => $self->LRR_CONF->enable_autotag, + cssdrop => generate_themes_selector, + csshead => generate_themes_header($self), + version => $self->LRR_VERSION ); } diff --git a/lib/LANraragi/Model/Api.pm b/lib/LANraragi/Model/Api.pm index b0aee93c7..125b05e69 100644 --- a/lib/LANraragi/Model/Api.pm +++ b/lib/LANraragi/Model/Api.pm @@ -11,11 +11,11 @@ use File::Temp qw(tempfile); use File::Copy "cp"; use Mojo::JSON qw(decode_json encode_json); -use LANraragi::Utils::Generic qw(get_tag_with_namespace remove_spaces remove_newlines); -use LANraragi::Utils::Archive qw(extract_thumbnail); -use LANraragi::Utils::Plugins qw(get_plugin get_plugin_parameters); +use LANraragi::Utils::Generic qw(get_tag_with_namespace remove_spaces remove_newlines); +use LANraragi::Utils::Archive qw(extract_thumbnail); +use LANraragi::Utils::Plugins qw(get_plugin get_plugin_parameters); use LANraragi::Utils::TempFolder qw(get_temp); -use LANraragi::Utils::Database qw(redis_decode); +use LANraragi::Utils::Database qw(redis_decode); # Functions used by the API. @@ -27,7 +27,7 @@ sub generate_archive_list { my @list = (); foreach my $id (@keys) { - if (-e $redis->hget($id, "file")) { + if ( -e $redis->hget( $id, "file" ) ) { my $arcdata = LANraragi::Utils::Database::build_archive_JSON( $redis, $id ); push @list, $arcdata; } @@ -42,28 +42,28 @@ sub generate_opds_catalog { my $mojo = shift; my $redis = $mojo->LRR_CONF->get_redis; my @keys = (); - + # Detailed pages just return a single entry instead of all the archives. - if ($mojo->req->param('id')) { - @keys = ($mojo->req->param('id')); + if ( $mojo->req->param('id') ) { + @keys = ( $mojo->req->param('id') ); } else { @keys = $redis->keys('????????????????????????????????????????'); } - my @list = (); + my @list = (); foreach my $id (@keys) { - my $file = $redis->hget($id, "file"); - if (-e $file) { - my $arcdata = LANraragi::Utils::Database::build_archive_JSON($redis, $id); + my $file = $redis->hget( $id, "file" ); + if ( -e $file ) { + my $arcdata = LANraragi::Utils::Database::build_archive_JSON( $redis, $id ); my $tags = $arcdata->{tags}; # Infer a few OPDS-related fields from the tags - $arcdata->{dateadded} = get_tag_with_namespace("dateadded", $tags, "2010-01-10T10:01:11Z"); - $arcdata->{author} = get_tag_with_namespace("artist", $tags, ""); - $arcdata->{language} = get_tag_with_namespace("language", $tags, ""); - $arcdata->{circle} = get_tag_with_namespace("group", $tags, ""); - $arcdata->{event} = get_tag_with_namespace("event", $tags, ""); + $arcdata->{dateadded} = get_tag_with_namespace( "dateadded", $tags, "2010-01-10T10:01:11Z" ); + $arcdata->{author} = get_tag_with_namespace( "artist", $tags, "" ); + $arcdata->{language} = get_tag_with_namespace( "language", $tags, "" ); + $arcdata->{circle} = get_tag_with_namespace( "group", $tags, "" ); + $arcdata->{event} = get_tag_with_namespace( "event", $tags, "" ); # Application/zip is universally hated by all readers so it's better to use x-cbz and x-cbr here. if ( $file =~ /^(.*\/)*.+\.(rar|cbr)$/ ) { @@ -72,8 +72,7 @@ sub generate_opds_catalog { $arcdata->{mimetype} = "application/x-cbz"; } - for (values %{$arcdata}) - { escape_xml($_); } + for ( values %{$arcdata} ) { escape_xml($_); } push @list, $arcdata; } @@ -81,8 +80,8 @@ sub generate_opds_catalog { $redis->quit; - if ($mojo->req->param('id')) { - @keys = ($mojo->req->param('id')); + if ( $mojo->req->param('id') ) { + @keys = ( $mojo->req->param('id') ); } else { @keys = $redis->keys('????????????????????????????????????????'); } @@ -109,35 +108,35 @@ sub escape_xml { # Tags added automatically by the autotagger are ignored. sub find_untagged_archives { - my $redis = LANraragi::Model::Config->get_redis; - my @keys = $redis->keys('????????????????????????????????????????'); + my $redis = LANraragi::Model::Config->get_redis; + my @keys = $redis->keys('????????????????????????????????????????'); my @untagged; #Parse the archive list. foreach my $id (@keys) { my $zipfile = $redis->hget( $id, "file" ); - if ($zipfile && -e $zipfile ) { + if ( $zipfile && -e $zipfile ) { my $title = $redis->hget( $id, "title" ); $title = redis_decode($title); - my $tagstr = $redis->hget($id, "tags"); + my $tagstr = $redis->hget( $id, "tags" ); $tagstr = redis_decode($tagstr); - my @tags = split(/,\s?/, $tagstr); + my @tags = split( /,\s?/, $tagstr ); my $nondefaulttags = 0; - + foreach my $t (@tags) { remove_spaces($t); remove_newlines($t); - + # the following are the only namespaces that LANraragi::Utils::Database::parse_name adds # date_added added for convenience as running the matching plugin doesn't really count as tagging - $nondefaulttags += 1 unless $t =~ /(artist|parody|series|language|event|group|date_added):.*/ + $nondefaulttags += 1 unless $t =~ /(artist|parody|series|language|event|group|date_added):.*/; } - + #If the archive has no tags, or the tags namespaces are only from #filename parsing (probably), add it to the list. - if (!@tags || $nondefaulttags == 0) { + if ( !@tags || $nondefaulttags == 0 ) { push @untagged, $id; } } @@ -148,8 +147,8 @@ sub find_untagged_archives { sub serve_thumbnail { - my ($self, $id) = @_; - my $dirname = LANraragi::Model::Config->get_userdir; + my ( $self, $id ) = @_; + my $dirname = LANraragi::Model::Config->get_userdir; #Thumbnails are stored in the content directory, thumb subfolder. my $thumbname = $dirname . "/thumb/" . $id . ".jpg"; @@ -162,72 +161,74 @@ sub serve_thumbnail { #If it doesn't exist, serve an error placeholder instead. if ( -e $thumbname ) { $self->render_file( filepath => $thumbname ); - } - else { + } else { $self->render_file( filepath => "./public/img/noThumb.png" ); } } sub serve_page { - my ($self, $id) = @_; - my $path = $self->req->param('path') || "404.xyz"; + my ( $self, $id ) = @_; + my $path = $self->req->param('path') || "404.xyz"; my $tempfldr = get_temp(); my $file = $tempfldr . "/$id/$path"; - my $abspath = abs_path($file); # abs_path returns null if the path is invalid. + my $abspath = abs_path($file); # abs_path returns null if the path is invalid. - if (!$abspath) { - $self->render( + if ( !$abspath ) { + $self->render( json => { error => "Invalid path.", - path => $file + path => $file }, - status => 500); + status => 500 + ); } # This API can only serve files from the temp folder - if (index($abspath, $tempfldr) != -1) { + if ( index( $abspath, $tempfldr ) != -1 ) { # Apply resizing transformation if set in Settings - if (LANraragi::Model::Config->enable_resize) { + if ( LANraragi::Model::Config->enable_resize ) { # Use File::Temp to copy the extracted file and resize it - my ($fh, $filename) = tempfile(); - cp( $file, $fh); + my ( $fh, $filename ) = tempfile(); + cp( $file, $fh ); my $threshold = LANraragi::Model::Config->get_threshold; - my $quality = LANraragi::Model::Config->get_readquality; - LANraragi::Model::Reader::resize_image($filename, $quality, $threshold); + my $quality = LANraragi::Model::Config->get_readquality; + LANraragi::Model::Reader::resize_image( $filename, $quality, $threshold ); $self->render_file( filepath => $filename ); - + } else { - # Serve extracted file directly + + # Serve extracted file directly $self->render_file( filepath => $file ); } } else { - $self->render( + $self->render( json => { error => "This API cannot render files outside of the temporary folder.", - path => $abspath + path => $abspath }, - status => 500); + status => 500 + ); } } sub use_plugin { - my ($self) = @_; + my ($self) = @_; my $id = $self->req->param('id') || 0; my $plugname = $self->req->param('plugin'); my $input = $self->req->param('arg'); - + my $plugin = get_plugin($plugname); my %plugin_result; my %pluginfo; - if (!$plugin) { + if ( !$plugin ) { $plugin_result{error} = "Plugin not found on system."; } else { %pluginfo = $plugin->plugin_info(); @@ -236,17 +237,12 @@ sub use_plugin { my @settings = get_plugin_parameters($plugname); #Execute the plugin, appending the custom args at the end - if ($pluginfo{type} eq "script") { - eval { - %plugin_result = LANraragi::Model::Plugins::exec_script_plugin( $plugin, $input, @settings ); - }; + if ( $pluginfo{type} eq "script" ) { + eval { %plugin_result = LANraragi::Model::Plugins::exec_script_plugin( $plugin, $input, @settings ); }; } - if ($pluginfo{type} eq "metadata") { - eval { - %plugin_result = LANraragi::Model::Plugins::exec_metadata_plugin( $plugin, $id, - $input, @settings ); - }; + if ( $pluginfo{type} eq "metadata" ) { + eval { %plugin_result = LANraragi::Model::Plugins::exec_metadata_plugin( $plugin, $id, $input, @settings ); }; } if ($@) { @@ -268,4 +264,4 @@ sub use_plugin { } -1; \ No newline at end of file +1; diff --git a/lib/LANraragi/Model/Backup.pm b/lib/LANraragi/Model/Backup.pm index b088b49c1..a248fb22b 100755 --- a/lib/LANraragi/Model/Backup.pm +++ b/lib/LANraragi/Model/Backup.pm @@ -28,12 +28,11 @@ sub build_backup_JSON { my %hash = $redis->hgetall($id); - my ( $name, $title, $tags, $thumbhash ) = - @hash{qw(name title tags thumbhash)}; + my ( $name, $title, $tags, $thumbhash ) = @hash{qw(name title tags thumbhash)}; ( $_ = redis_decode($_) ) for ( $name, $title, $tags ); ( remove_newlines($_) ) for ( $name, $title, $tags ); - ( $_ = encode_json($_)) for ( $name, $title, $tags ); + ( $_ = encode_json($_) ) for ( $name, $title, $tags ); #Backup all user-generated metadata, alongside the unique ID. $json .= qq( @@ -80,8 +79,7 @@ sub restore_from_JSON { $redis->hset( $id, "tags", $tags ); if ( $redis->hexists( $id, "thumbhash" ) - && $redis->hget( $id, "thumbhash" ) eq "" ) - { + && $redis->hget( $id, "thumbhash" ) eq "" ) { $redis->hset( $id, "thumbhash", $thumbhash ); } diff --git a/lib/LANraragi/Model/Config.pm b/lib/LANraragi/Model/Config.pm index c9d124d48..eaa4713ea 100755 --- a/lib/LANraragi/Model/Config.pm +++ b/lib/LANraragi/Model/Config.pm @@ -13,8 +13,7 @@ use Mojo::Home; my $home = Mojo::Home->new; $home->detect; -my $config = Mojolicious::Plugin::Config->register( Mojolicious->new, - { file => $home . '/lrr.conf' } ); +my $config = Mojolicious::Plugin::Config->register( Mojolicious->new, { file => $home . '/lrr.conf' } ); #Address and port of your redis instance. sub get_redisad { return $config->{redis_address} } @@ -51,8 +50,9 @@ sub get_redis_conf { my $redis = get_redis(); if ( $redis->hexists( "LRR_CONFIG", $param ) ) { + # Call Utils::Database directly as importing it with use; would cause circular dependencies... - my $value = LANraragi::Utils::Database::redis_decode($redis->hget( "LRR_CONFIG", $param ) ); + my $value = LANraragi::Utils::Database::redis_decode( $redis->hget( "LRR_CONFIG", $param ) ); #failsafe against blank config values unless ( $value =~ /^\s*$/ ) { @@ -65,16 +65,13 @@ sub get_redis_conf { #Functions that return the config variables stored in Redis, or default values if they don't exist. Descriptions for each one of these can be found in the web configuration page. sub get_htmltitle { + + #enforcing unicode to make sure it doesn't fuck up the templates by appearing in some other encoding return encode( 'utf-8', &get_redis_conf( "htmltitle", "LANraragi" ) ); -}; #enforcing unicode to make sure it doesn't fuck up the templates by appearing in some other encoding +} sub get_motd { - return encode( - 'utf-8', - &get_redis_conf( - "motd", "Welcome to this Library running LANraragi!" - ) - ); + return encode( 'utf-8', &get_redis_conf( "motd", "Welcome to this Library running LANraragi!" ) ); } sub get_userdir { @@ -82,7 +79,7 @@ sub get_userdir { # Content path can be overriden by LRR_DATA_DIRECTORY my $dir = &get_redis_conf( "dirname", "./content" ); - if ($ENV{LRR_DATA_DIRECTORY}) { + if ( $ENV{LRR_DATA_DIRECTORY} ) { $dir = $ENV{LRR_DATA_DIRECTORY}; } @@ -97,7 +94,7 @@ sub get_userdir { sub enable_devmode { - if ($ENV{LRR_FORCE_DEBUG}) { + if ( $ENV{LRR_FORCE_DEBUG} ) { return 1; } @@ -105,27 +102,28 @@ sub enable_devmode { } sub get_password { - return &get_redis_conf( "password", - '{CRYPT}$2a$08$4AcMwwkGXnWtFTOLuw/hduQlRdqWQIBzX3UuKn.M1qTFX5R4CALxy' ); -}; #bcrypt hash for "kamimamita" + + #bcrypt hash for "kamimamita" + return &get_redis_conf( "password", '{CRYPT}$2a$08$4AcMwwkGXnWtFTOLuw/hduQlRdqWQIBzX3UuKn.M1qTFX5R4CALxy' ); +} sub get_tagblacklist { return &get_redis_conf( "blacklist", -"already uploaded, forbidden content, incomplete, ongoing, complete, various, digital, translated, russian, chinese, portuguese, french, spanish, italian, vietnamese, german, indonesian" + "already uploaded, forbidden content, incomplete, ongoing, complete, various, digital, translated, russian, chinese, portuguese, french, spanish, italian, vietnamese, german, indonesian" ); } -sub get_tempmaxsize { return &get_redis_conf( "tempmaxsize", "500" ) } -sub get_pagesize { return &get_redis_conf( "pagesize", "100" ) } -sub enable_pass { return &get_redis_conf( "enablepass", "1" ) } -sub enable_nofun { return &get_redis_conf( "nofunmode", "0" ) } -sub enable_autotag { return &get_redis_conf( "autotag", "1" ) } -sub get_apikey { return &get_redis_conf( "apikey", "" ) } -sub get_tagregex { return &get_redis_conf( "tagregex", "1" ) } -sub enable_blacklst { return &get_redis_conf( "blackliston", "1") }; -sub enable_resize { return &get_redis_conf( "enableresize", "0") }; -sub get_threshold { return &get_redis_conf( "sizethreshold", "1000") }; -sub get_readquality { return &get_redis_conf( "readerquality", "50") }; +sub get_tempmaxsize { return &get_redis_conf( "tempmaxsize", "500" ) } +sub get_pagesize { return &get_redis_conf( "pagesize", "100" ) } +sub enable_pass { return &get_redis_conf( "enablepass", "1" ) } +sub enable_nofun { return &get_redis_conf( "nofunmode", "0" ) } +sub enable_autotag { return &get_redis_conf( "autotag", "1" ) } +sub get_apikey { return &get_redis_conf( "apikey", "" ) } +sub get_tagregex { return &get_redis_conf( "tagregex", "1" ) } +sub enable_blacklst { return &get_redis_conf( "blackliston", "1" ) } +sub enable_resize { return &get_redis_conf( "enableresize", "0" ) } +sub get_threshold { return &get_redis_conf( "sizethreshold", "1000" ) } +sub get_readquality { return &get_redis_conf( "readerquality", "50" ) } #Use the number of the favtag you want to get as a parameter to this sub. sub get_favtag { return &get_redis_conf( "fav" . $_[1], "" ) } @@ -143,8 +141,7 @@ sub get_favtag { return &get_redis_conf( "fav" . $_[1], "" ) } #(\(([^([)]+)\))? returns the content of (Series). Optional. #(\[([^]]+)\])? returns the content of [Language]. Optional. #\s* indicates zero or more whitespaces. -my $regex = -qr/(\(([^([]+)\))?\s*(\[([^]]+)\])?\s*([^([]+)\s*(\(([^([)]+)\))?\s*(\[([^]]+)\])?/; +my $regex = qr/(\(([^([]+)\))?\s*(\[([^]]+)\])?\s*([^([]+)\s*(\(([^([)]+)\))?\s*(\[([^]]+)\])?/; sub get_regex { return $regex } 1; diff --git a/lib/LANraragi/Model/Plugins.pm b/lib/LANraragi/Model/Plugins.pm index 9ff839542..e9e055679 100755 --- a/lib/LANraragi/Model/Plugins.pm +++ b/lib/LANraragi/Model/Plugins.pm @@ -18,7 +18,7 @@ use LANraragi::Utils::Logging qw(get_logger); # Sub used by Auto-Plugin. sub exec_enabled_plugins_on_file { - my $id = shift; + my $id = shift; my $logger = get_logger( "Auto-Plugin", "lanraragi" ); $logger->info("Executing enabled metadata plugins on archive with id $id."); @@ -27,7 +27,7 @@ sub exec_enabled_plugins_on_file { my $failures = 0; my $addedtags = 0; - my @plugins = LANraragi::Utils::Plugins::get_enabled_plugins("metadata"); + my @plugins = LANraragi::Utils::Plugins::get_enabled_plugins("metadata"); foreach my $pluginfo (@plugins) { my $name = $pluginfo->{namespace}; @@ -36,35 +36,31 @@ sub exec_enabled_plugins_on_file { my %plugin_result; #Every plugin execution is eval'd separately - eval { - %plugin_result = exec_metadata_plugin( $plugin, $id, "", @args ); - }; + eval { %plugin_result = exec_metadata_plugin( $plugin, $id, "", @args ); }; if ($@) { $failures++; $logger->error("$@"); - } elsif ( exists $plugin_result{error}) { + } elsif ( exists $plugin_result{error} ) { $failures++; - $logger->error($plugin_result{error}); + $logger->error( $plugin_result{error} ); } else { $successes++; } #If the plugin exec returned metadata, add it unless ( exists $plugin_result{error} ) { - LANraragi::Utils::Database::add_tags( $id, - $plugin_result{new_tags} ); + LANraragi::Utils::Database::add_tags( $id, $plugin_result{new_tags} ); # Sum up all the added tags for later reporting. # This doesn't take into account tags that are added twice - # (e.g by different plugins), but since this is more meant to show + # (e.g by different plugins), but since this is more meant to show # if the plugins added any data at all it's fine. - my @added_tags = split(',', $plugin_result{new_tags}); + my @added_tags = split( ',', $plugin_result{new_tags} ); $addedtags += @added_tags; if ( exists $plugin_result{title} ) { - LANraragi::Utils::Database::set_title( $id, - $plugin_result{title} ); + LANraragi::Utils::Database::set_title( $id, $plugin_result{title} ); # Increment added_tags if the title changed as well $addedtags++; @@ -79,18 +75,18 @@ sub exec_enabled_plugins_on_file { # Might be worth consolidating this later. sub exec_login_plugin { my $plugname = shift; - my $ua = Mojo::UserAgent->new; - my $logger = get_logger( "Plugin System", "lanraragi" ); + my $ua = Mojo::UserAgent->new; + my $logger = get_logger( "Plugin System", "lanraragi" ); if ($plugname) { $logger->debug("Calling matching login plugin $plugname."); my $loginplugin = LANraragi::Utils::Plugins::get_plugin($plugname); my @loginargs = LANraragi::Utils::Plugins::get_plugin_parameters($plugname); - if ($loginplugin->can('do_login')) { + if ( $loginplugin->can('do_login') ) { my $loggedinua = $loginplugin->do_login(@loginargs); - if (ref($loggedinua) eq "Mojo::UserAgent") { + if ( ref($loggedinua) eq "Mojo::UserAgent" ) { return $loggedinua; } else { $logger->error("Plugin did not return a Mojo::UserAgent object!"); @@ -115,12 +111,12 @@ sub exec_script_plugin { if ( $plugin->can('run_script') ) { my %pluginfo = $plugin->plugin_info(); - my $ua = exec_login_plugin($pluginfo{login_from}); + my $ua = exec_login_plugin( $pluginfo{login_from} ); # Bundle all the potentially interesting info in a hash my %infohash = ( - user_agent => $ua, - oneshot_param => $input + user_agent => $ua, + oneshot_param => $input ); # Scripts don't have any predefined metadata in their spec so they're just ran as-is. @@ -137,7 +133,7 @@ sub exec_metadata_plugin { my ( $plugin, $id, $oneshotarg, @args ) = @_; my $logger = get_logger( "Plugin System", "lanraragi" ); - if ($id eq 0) { + if ( $id eq 0 ) { return ( error => "Tried to call a metadata plugin without providing an id." ); } @@ -148,10 +144,9 @@ sub exec_metadata_plugin { my $redis = LANraragi::Model::Config->get_redis; my %hash = $redis->hgetall($id); - my ( $name, $title, $tags, $file, $thumbhash ) = - @hash{qw(name title tags file thumbhash)}; + my ( $name, $title, $tags, $file, $thumbhash ) = @hash{qw(name title tags file thumbhash)}; - ( $_ = LANraragi::Utils::Database::redis_decode($_) ) for ( $name, $title, $tags); + ( $_ = LANraragi::Utils::Database::redis_decode($_) ) for ( $name, $title, $tags ); # If the thumbnail hash is empty or undefined, we'll generate it here. unless ( length $thumbhash ) { @@ -160,29 +155,29 @@ sub exec_metadata_plugin { #eval the thumbnail extraction as it can error out and die eval { extract_thumbnail( $dirname, $id ) }; - if ($@) { + if ($@) { $logger->warn("Error building thumbnail: $@"); $thumbhash = ""; } else { $thumbhash = $redis->hget( $id, "thumbhash" ); $thumbhash = LANraragi::Utils::Database::redis_decode($thumbhash); } - } + } $redis->quit(); # Hand it off to the plugin here. # If the plugin requires a login, execute that first to get a UserAgent my %pluginfo = $plugin->plugin_info(); - my $ua = exec_login_plugin($pluginfo{login_from}); + my $ua = exec_login_plugin( $pluginfo{login_from} ); # Bundle all the potentially interesting info in a hash my %infohash = ( - archive_title => $title, - existing_tags => $tags, - thumbnail_hash => $thumbhash, - file_path => $file, - user_agent => $ua, - oneshot_param => $oneshotarg + archive_title => $title, + existing_tags => $tags, + thumbnail_hash => $thumbhash, + file_path => $file, + user_agent => $ua, + oneshot_param => $oneshotarg ); my %newmetadata = $plugin->get_tags( \%infohash, @args ); @@ -197,13 +192,13 @@ sub exec_metadata_plugin { } my @tagarray = split( ",", $newmetadata{tags} ); - my $newtags = ""; + my $newtags = ""; #Process new metadata, #stripping out blacklisted tags and tags that we already have in Redis - my $blist = LANraragi::Model::Config->get_tagblacklist; + my $blist = LANraragi::Model::Config->get_tagblacklist; my $blistenable = LANraragi::Model::Config->enable_blacklst; - my @blacklist = split( ',', $blist ); # array-ize the blacklist string + my @blacklist = split( ',', $blist ); # array-ize the blacklist string foreach my $tagtoadd (@tagarray) { @@ -220,14 +215,14 @@ sub exec_metadata_plugin { remove_spaces($black); if ( index( uc($tagtoadd), uc($black) ) != -1 ) { - $logger->info( - "Tag $tagtoadd is blacklisted, not adding."); + $logger->info("Tag $tagtoadd is blacklisted, not adding."); $good = 0; } } } if ($good) { + #This tag is processed and good to go $newtags .= " $tagtoadd,"; } diff --git a/lib/LANraragi/Model/Reader.pm b/lib/LANraragi/Model/Reader.pm index 8ed2bc37e..3872abeef 100755 --- a/lib/LANraragi/Model/Reader.pm +++ b/lib/LANraragi/Model/Reader.pm @@ -36,13 +36,13 @@ sub resize_image { if ( ( int( ( -s $imgpath ) / 1024 * 10 ) / 10 ) > $threshold ) { $img->Read($imgpath); - my ($origw, $origh) = $img->Get('width', 'height'); - if ($origw > 1064) { + my ( $origw, $origh ) = $img->Get( 'width', 'height' ); + if ( $origw > 1064 ) { $img->Resize( geometry => '1064x' ); } # Set format to jpeg and quality - $img->Set( quality => $quality, magick => "jpg"); + $img->Set( quality => $quality, magick => "jpg" ); $img->Write($imgpath); } } @@ -82,16 +82,13 @@ sub build_reader_JSON { unless ( -e $path ) { my $outpath = ""; - eval { - $outpath = extract_archive( $path, $zipfile ); - }; + eval { $outpath = extract_archive( $path, $zipfile ); }; if ($@) { my $log = $@; $self->LRR_LOGGER->error("Error extracting archive : $log"); die $log; - } - else { + } else { $self->LRR_LOGGER->debug("Extraction of archive to $outpath done"); $path = $outpath; } @@ -102,19 +99,23 @@ sub build_reader_JSON { #treat them and jam them into an array. my @images; eval { - find(sub { + find( + sub { # Is it an image? if ( is_image($_) ) { push @images, $File::Find::name; } - }, $path); + }, + $path + ); }; - # TODO: @images = nsort(@images); would theorically be better, but Sort::Naturally's nsort puts letters before numbers, which isn't what we want at all for pages in an archive. + # TODO: @images = nsort(@images); would theorically be better, but Sort::Naturally's nsort puts letters before numbers, + # which isn't what we want at all for pages in an archive. # To investigate further, perhaps with custom sorting algorithms? @images = sort { &expand($a) cmp &expand($b) } @images; - $self->LRR_LOGGER->debug("Files found in archive: \n " . Dumper @images); + $self->LRR_LOGGER->debug( "Files found in archive: \n " . Dumper @images ); #Convert page 1 into a thumbnail for the main reader index my $thumbname = $dirname . "/thumb/" . $id . ".jpg"; @@ -124,7 +125,7 @@ sub build_reader_JSON { $redis->hset( $id, "thumbhash", encode_utf8($shasum) ); $self->LRR_LOGGER->debug("Thumbnail not found at $thumbname! (force-thumb flag = $thumbreload)"); - $self->LRR_LOGGER->debug("Regenerating from " . $images[0]); + $self->LRR_LOGGER->debug( "Regenerating from " . $images[0] ); mkdir $dirname . "/thumb"; generate_thumbnail( $images[0], $thumbname ); diff --git a/lib/LANraragi/Model/Search.pm b/lib/LANraragi/Model/Search.pm index fef29e23a..ebd038a29 100644 --- a/lib/LANraragi/Model/Search.pm +++ b/lib/LANraragi/Model/Search.pm @@ -19,13 +19,14 @@ use LANraragi::Model::Api; # Performs a search on the database. sub do_search { - my ( $filter, $columnfilter, $start, $sortkey, $sortorder, $newonly, $untaggedonly) = @_; + my ( $filter, $columnfilter, $start, $sortkey, $sortorder, $newonly, $untaggedonly ) = @_; - my $redis = LANraragi::Model::Config->get_redis; + my $redis = LANraragi::Model::Config->get_redis; my $logger = get_logger( "Search Engine", "lanraragi" ); # Search filter results my @filtered; + # Get all archives from redis my @keys = $redis->keys('????????????????????????????????????????'); @@ -33,14 +34,14 @@ sub do_search { my $cachekey = encode_utf8("$columnfilter-$filter-$sortkey-$sortorder-$newonly-$untaggedonly"); $logger->debug("Search request: $cachekey"); - if ($redis->exists("LRR_SEARCHCACHE") && $redis->hexists("LRR_SEARCHCACHE", $cachekey)) { + if ( $redis->exists("LRR_SEARCHCACHE") && $redis->hexists( "LRR_SEARCHCACHE", $cachekey ) ) { $logger->debug("Using cache for this query."); - @filtered = @{ thaw $redis->hget("LRR_SEARCHCACHE", $cachekey)}; + @filtered = @{ thaw $redis->hget( "LRR_SEARCHCACHE", $cachekey ) }; } else { $logger->debug("No cache available, doing a full DB parse."); - # If the untagged filter is enabled, call the untagged files API + # If the untagged filter is enabled, call the untagged files API my %untagged = (); if ($untaggedonly) { %untagged = map { $_ => 1 } LANraragi::Model::Api::find_untagged_archives(); @@ -48,77 +49,78 @@ sub do_search { # Go through tags and apply search filter foreach my $id (@keys) { - my $tags = $redis->hget($id, "tags"); - my $title = $redis->hget($id, "title"); - my $file = $redis->hget($id, "file"); - my $isnew = $redis->hget($id, "isnew"); + my $tags = $redis->hget( $id, "tags" ); + my $title = $redis->hget( $id, "title" ); + my $file = $redis->hget( $id, "file" ); + my $isnew = $redis->hget( $id, "isnew" ); $title = redis_decode($title); $tags = redis_decode($tags); # Check new filter first - if ($newonly && $isnew && $isnew ne "true" && $isnew ne "block") { + if ( $newonly && $isnew && $isnew ne "true" && $isnew ne "block" ) { next; } # Check untagged filter second - unless (exists($untagged{$id}) || !$untaggedonly) { + unless ( exists( $untagged{$id} ) || !$untaggedonly ) { next; } my $fileok = $file && -e $file; - if ($file && $title && !$fileok) { + if ( $file && $title && !$fileok ) { $logger->debug("File $file for title $title does not exist and will not be in search results."); } # Check columnfilter and base search filter - if ($fileok - && matches_search_filter($columnfilter, $title . "," . $tags) - && matches_search_filter($filter, $title . "," . $tags)) { + if ( $fileok + && matches_search_filter( $columnfilter, $title . "," . $tags ) + && matches_search_filter( $filter, $title . "," . $tags ) ) { + # Push id to array push @filtered, { id => $id, title => $title, tags => $tags }; } } - if ($#filtered > 0) { + if ( $#filtered > 0 ) { - if (!$sortkey) { + if ( !$sortkey ) { $sortkey = "title"; } # Sort by the required metadata, asc or desc - @filtered = sort { - + @filtered = sort { + #Use either tags or title depending on the sortkey my $meta1 = $a->{title}; my $meta2 = $b->{title}; - if ($sortkey ne "title") { + if ( $sortkey ne "title" ) { my $re = qr/$sortkey/; - if ($a->{tags} =~ m/.*${re}:(.*)(\,.*|$)/) { + if ( $a->{tags} =~ m/.*${re}:(.*)(\,.*|$)/ ) { $meta1 = $1; } else { - $meta1 = "zzzz"; # Not a very good way to make items end at the bottom... + $meta1 = "zzzz"; # Not a very good way to make items end at the bottom... } - - if ($b->{tags} =~ m/.*${re}:(.*)(\,.*|$)/) { + + if ( $b->{tags} =~ m/.*${re}:(.*)(\,.*|$)/ ) { $meta2 = $1; } else { $meta2 = "zzzz"; } } - if ($sortorder) { - ncmp( lc($meta2), lc($meta1) ) + if ($sortorder) { + ncmp( lc($meta2), lc($meta1) ); } else { - ncmp( lc($meta1), lc($meta2) ) + ncmp( lc($meta1), lc($meta2) ); } } @filtered; } # Cache this query in Redis - eval { $redis->hset("LRR_SEARCHCACHE", $cachekey, nfreeze \@filtered); }; + eval { $redis->hset( "LRR_SEARCHCACHE", $cachekey, nfreeze \@filtered ); }; } $redis->quit(); @@ -126,8 +128,8 @@ sub do_search { my $keysperpage = LANraragi::Model::Config->get_pagesize; # Return total keys and the filtered ones - my $end = min($start+$keysperpage-1,$#filtered); - return ( $#keys+1, $#filtered+1, @filtered[$start..$end] ); + my $end = min( $start + $keysperpage - 1, $#filtered ); + return ( $#keys + 1, $#filtered + 1, @filtered[ $start .. $end ] ); } # matches_search_filter($filter, $tags) @@ -135,51 +137,51 @@ sub do_search { sub matches_search_filter { my ( $filter, $tags ) = @_; - if (!$filter) {$filter = "";} + if ( !$filter ) { $filter = ""; } - # Special characters: + # Special characters: # "" for exact search (or $ but is that one really useful) # ?/_ for any character # * % for multiple characters # - to exclude the next tag - $b = reverse($filter); - while ($b ne "") { + $b = reverse($filter); + while ( $b ne "" ) { - my $char = chop $b; + my $char = chop $b; my $isneg = 0; - if ($char eq "-") { + if ( $char eq "-" ) { $isneg = 1; - $char = chop $b; + $char = chop $b; } # Get characters until the next space, or the next " if the following char is " my $delimiter = ' '; - if ($char eq '"') { + if ( $char eq '"' ) { $delimiter = '"'; - $char = chop $b; + $char = chop $b; } - my $tag = ""; + my $tag = ""; my $isexact = 0; - TAGBUILD: while (1) { - if ($char eq $delimiter || $char eq "") { last TAGBUILD; } - $tag = $tag . $char; # Add characters in reverse order since we used reverse earlier on + TAGBUILD: while (1) { + if ( $char eq $delimiter || $char eq "" ) { last TAGBUILD; } + $tag = $tag . $char; # Add characters in reverse order since we used reverse earlier on $char = chop $b; - }; + } #If last char is $, enable isexact - if ($delimiter eq '"') { + if ( $delimiter eq '"' ) { $char = chop $b; - if ($char eq "\$") { + if ( $char eq "\$" ) { $isexact = 1; } else { $b = $b . $char; } } else { $char = chop $tag; - if ($char eq "\$") { + if ( $char eq "\$" ) { $isexact = 1; } else { $tag = $tag . $char; @@ -192,27 +194,27 @@ sub matches_search_filter { # Replace placeholders(with an extra backslash in em thanks to quotemeta) with regex-friendly variants, # ? _ => . $tag =~ s/\\\?|\_/\./g; + # * % => .* $tag =~ s/\\\*|\\\%/\.\*/g; # Got the tag, check if it's present my $tagpresent = 0; - if ($isexact) { # The tag must necessarily be complete if isexact = 1 - $tagpresent = $tags =~ m/(.*\,\s*|^)$tag(\,.*|$)/i; # Check for comma + potential space before and comma after the tag, or start/end of string to account for the first/last tag. + if ($isexact) { # The tag must necessarily be complete if isexact = 1 + # Check for comma + potential space before and comma after the tag, or start/end of string to account for the first/last tag. + $tagpresent = $tags =~ m/(.*\,\s*|^)$tag(\,.*|$)/i; } else { $tagpresent = $tags =~ m/.*$tag.*/i; } #present=true & isneg=true => false #present=false & isneg=false => false - return 0 if ($tagpresent == $isneg); + return 0 if ( $tagpresent == $isneg ); - }; + } # All filters passed! return 1; } - - -1; \ No newline at end of file +1; diff --git a/lib/LANraragi/Model/Stats.pm b/lib/LANraragi/Model/Stats.pm index c4ef17d4f..854a75675 100644 --- a/lib/LANraragi/Model/Stats.pm +++ b/lib/LANraragi/Model/Stats.pm @@ -20,8 +20,7 @@ sub get_archive_count { #Count files the old-fashioned way instead find( - { - wanted => sub { + { wanted => sub { return if -d $_; #Directories are excluded on the spot if ( $_ =~ /^.+\.(?:zip|rar|7z|tar|tar\.gz|lzma|xz|cbz|cbr)$/ ) { $count++; @@ -64,10 +63,8 @@ sub build_tag_json { remove_newlines($t); #Increment value of tag or create it - if ( exists( $tagcloud{$t} ) ) - { $tagcloud{$t}++; } - else - { $tagcloud{$t} = 1; } + if ( exists( $tagcloud{$t} ) ) { $tagcloud{$t}++; } + else { $tagcloud{$t} = 1; } } } @@ -77,15 +74,18 @@ sub build_tag_json { #Go through the tagCloud hash and build a JSON my $tagsjson = "["; - for(keys %tagcloud) { + for ( keys %tagcloud ) { my $w = $tagcloud{$_}; + # Split namespace # detect the : symbol and only use what's after it my $ns = ""; - my $t = $_; + my $t = $_; if ( $t =~ /(.*):(.*)/ ) { $ns = $1; $t = $2; } - if ($_ ne "") { $tagsjson .= qq({"text": "$t", "namespace": "$ns", "weight": $w },); } + if ( $_ ne "" ) { + $tagsjson .= qq({"text": "$t", "namespace": "$ns", "weight": $w },); + } } chop $tagsjson if $tagsjson ne "["; @@ -95,6 +95,7 @@ sub build_tag_json { } sub compute_content_size { + #Get size of archive folder my $dirname = LANraragi::Model::Config->get_userdir; my $size = 0; @@ -104,4 +105,4 @@ sub compute_content_size { return int( $size / 1073741824 * 100 ) / 100; } -1; \ No newline at end of file +1; diff --git a/lib/LANraragi/Plugin/Login/EHentai.pm b/lib/LANraragi/Plugin/Login/EHentai.pm index a76bce745..6a539ecd4 100644 --- a/lib/LANraragi/Plugin/Login/EHentai.pm +++ b/lib/LANraragi/Plugin/Login/EHentai.pm @@ -12,16 +12,17 @@ sub plugin_info { return ( #Standard metadata - name => "E-Hentai", - type => "login", - namespace => "ehlogin", - author => "Difegue", - version => "2.2", - description => "Handles login to E-H. If you have an account that can access fjorded content or exhentai, adding the credentials here will make more archives available for parsing.", - parameters => [ - {type => "int", desc => "ipb_member_id cookie"}, - {type => "string", desc => "ipb_pass_hash cookie"}, - {type => "string", desc => "star cookie (optional, if present you can view fjorded content without exhentai)"} + name => "E-Hentai", + type => "login", + namespace => "ehlogin", + author => "Difegue", + version => "2.2", + description => + "Handles login to E-H. If you have an account that can access fjorded content or exhentai, adding the credentials here will make more archives available for parsing.", + parameters => [ + { type => "int", desc => "ipb_member_id cookie" }, + { type => "string", desc => "ipb_pass_hash cookie" }, + { type => "string", desc => "star cookie (optional, if present you can view fjorded content without exhentai)" } ] ); @@ -33,8 +34,8 @@ sub do_login { # Login plugins only receive the parameters entered by the user. shift; - my ( $ipb_member_id, $ipb_pass_hash, $star) = @_; - return get_user_agent($ipb_member_id, $ipb_pass_hash, $star); + my ( $ipb_member_id, $ipb_pass_hash, $star ) = @_; + return get_user_agent( $ipb_member_id, $ipb_pass_hash, $star ); } # get_user_agent(ipb cookies) @@ -42,13 +43,13 @@ sub do_login { # Returns the UA object created. sub get_user_agent { - my ($ipb_member_id, $ipb_pass_hash, $star) = @_; + my ( $ipb_member_id, $ipb_pass_hash, $star ) = @_; my $logger = get_logger( "E-Hentai Login", "plugins" ); - my $ua = Mojo::UserAgent->new; + my $ua = Mojo::UserAgent->new; - if ($ipb_member_id ne "" && $ipb_pass_hash ne "") { - $logger->info( "Cookies provided ($ipb_member_id $ipb_pass_hash $star)!"); + if ( $ipb_member_id ne "" && $ipb_pass_hash ne "" ) { + $logger->info("Cookies provided ($ipb_member_id $ipb_pass_hash $star)!"); #Setup the needed cookies with both domains #They should translate to exhentai cookies with the igneous value generated @@ -115,7 +116,7 @@ sub get_user_agent { ) ); } else { - $logger->info( "No cookies provided, returning blank UserAgent."); + $logger->info("No cookies provided, returning blank UserAgent."); } return $ua; diff --git a/lib/LANraragi/Plugin/Metadata/Chaika.pm b/lib/LANraragi/Plugin/Metadata/Chaika.pm index 18188e1c4..cd07a4d47 100644 --- a/lib/LANraragi/Plugin/Metadata/Chaika.pm +++ b/lib/LANraragi/Plugin/Metadata/Chaika.pm @@ -21,10 +21,9 @@ sub plugin_info { author => "Difegue", version => "2.1", description => "Searches chaika.moe for tags matching your archive.", - icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\nB3RJTUUH4wYCFQocjU4r+QAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH\nAAAEZElEQVQ4y42T3WtTdxzGn/M7J+fk5SRpTk7TxMZkXU84tTbVNrUT3YxO7HA4pdtQZDe7cgx2\ns8vBRvEPsOwFYTDYGJUpbDI2wV04cGXCGFLonIu1L2ptmtrmxeb1JDkvv121ZKVze66f74eH7/f5\nMmjRwMCAwrt4/9KDpflMJpPHvyiR2DPcJklJ3TRDDa0xk36cvrm8vDwHAAwAqKrqjjwXecPG205w\nHBuqa9rk77/d/qJYLD7cCht5deQIIczbgiAEKLVAKXWUiqVV06Tf35q8dYVJJBJem2A7Kwi2nQzD\nZig1CG93+PO5/KN6tf5NKpVqbsBUVVVFUUxwHJc1TXNBoxojS7IbhrnLMMx9pVJlBqFQKBKPxwcB\nkJYgjKIo3QCE1nSKoghbfJuKRqN2RVXexMaQzWaLezyeEUEQDjscjk78PxFFUYRkMsltJgGA3t7e\nyMLCwie6rr8iCILVbDbvMgwzYRjGxe0o4XC4s1AoHPP5fMP5/NNOyzLKAO6Ew+HrDADBbre/Ryk9\nnzx81FXJNlEpVpF+OqtpWu2MpmnXWmH9/f2umZmZi4cOHXnLbILLzOchhz1YerJAs9m1GwRAg2GY\nh7GYah488BJYzYW+2BD61AFBlmX/1nSNRqN9//792ujoaIPVRMjOKHoie3DytVGmp2fXCAEAjuMm\nu7u7Umosho6gjL/u/QHeEgvJZHJ2K/D+/fuL4+PjXyvPd5ldkShy1UXcmb4DnjgQj/fd5gDA6/XS\nYCAwTwh9oT3QzrS1+VDVi+vd3Tsy26yQVoFF3dAXJVmK96p9EJ0iLNOwKKU3CQCk0+lSOpP5WLDz\nF9Q9kZqyO0SloOs6gMfbHSU5NLRiUOuax2/HyZPHEOsLw2SbP83eu/fLxrkNp9P554XxCzVa16MC\n7+BPnTk9cfmH74KJE8nmga7Xy5JkZ8VKifGIHpoBb1VX8hNTd3/t/7lQ3OeXfFPvf/jBRw8ezD/a\n7M/aWq91cGgnJaZ2VcgSdnV1XRNNd3vAoBVVYusmnEQS65hfgSG6c+zy3Kre7nF/KrukcMW0Zg8O\nD08DoJutDxxOEb5IPUymwrq8ft1gLKfkFojkkRxemERCAQUACPFWRazYLJcrFGwQhyufbQQ7rFpy\nLMkCwGZC34qPIuwp+XPOjBFwazQ/txrdFS2GGS/Xuj+pUKLGk1Kjvlded3s72lyGW+PLbGVcmrAA\ngN0wTk1NWYODg9XOKltGtpazi5GigzroUnHN5nUHG1ylRsG7rDXHmnEpu4CeEtEKkqNc6QqlLc/M\n8uT5lLH5eq0aGxsju1O7GQB498a5s/0x9dRALPaQEDZnYwnhWJtMCCNrjeb0UP34Z6e/PW22zjPP\n+vwXBwfPvbw38XnXjk7GsiwKAIQQhjAMMrlsam45d+zLH6/8o6vkWcBcrXbVKQhf6bpucCwLjmUB\nSmmhXC419eblrbD/TAgAkUjE987xE0c7ZDmk66ajUCnq+cL63fErl25s5/8baQPaWLhx6goAAAAA\nSUVORK5CYII=", - parameters => [ - {type => "bool", desc => "Save archive title"} - ], + icon => + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\nB3RJTUUH4wYCFQocjU4r+QAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH\nAAAEZElEQVQ4y42T3WtTdxzGn/M7J+fk5SRpTk7TxMZkXU84tTbVNrUT3YxO7HA4pdtQZDe7cgx2\ns8vBRvEPsOwFYTDYGJUpbDI2wV04cGXCGFLonIu1L2ptmtrmxeb1JDkvv121ZKVze66f74eH7/f5\nMmjRwMCAwrt4/9KDpflMJpPHvyiR2DPcJklJ3TRDDa0xk36cvrm8vDwHAAwAqKrqjjwXecPG205w\nHBuqa9rk77/d/qJYLD7cCht5deQIIczbgiAEKLVAKXWUiqVV06Tf35q8dYVJJBJem2A7Kwi2nQzD\nZig1CG93+PO5/KN6tf5NKpVqbsBUVVVFUUxwHJc1TXNBoxojS7IbhrnLMMx9pVJlBqFQKBKPxwcB\nkJYgjKIo3QCE1nSKoghbfJuKRqN2RVXexMaQzWaLezyeEUEQDjscjk78PxFFUYRkMsltJgGA3t7e\nyMLCwie6rr8iCILVbDbvMgwzYRjGxe0o4XC4s1AoHPP5fMP5/NNOyzLKAO6Ew+HrDADBbre/Ryk9\nnzx81FXJNlEpVpF+OqtpWu2MpmnXWmH9/f2umZmZi4cOHXnLbILLzOchhz1YerJAs9m1GwRAg2GY\nh7GYah488BJYzYW+2BD61AFBlmX/1nSNRqN9//792ujoaIPVRMjOKHoie3DytVGmp2fXCAEAjuMm\nu7u7Umosho6gjL/u/QHeEgvJZHJ2K/D+/fuL4+PjXyvPd5ldkShy1UXcmb4DnjgQj/fd5gDA6/XS\nYCAwTwh9oT3QzrS1+VDVi+vd3Tsy26yQVoFF3dAXJVmK96p9EJ0iLNOwKKU3CQCk0+lSOpP5WLDz\nF9Q9kZqyO0SloOs6gMfbHSU5NLRiUOuax2/HyZPHEOsLw2SbP83eu/fLxrkNp9P554XxCzVa16MC\n7+BPnTk9cfmH74KJE8nmga7Xy5JkZ8VKifGIHpoBb1VX8hNTd3/t/7lQ3OeXfFPvf/jBRw8ezD/a\n7M/aWq91cGgnJaZ2VcgSdnV1XRNNd3vAoBVVYusmnEQS65hfgSG6c+zy3Kre7nF/KrukcMW0Zg8O\nD08DoJutDxxOEb5IPUymwrq8ft1gLKfkFojkkRxemERCAQUACPFWRazYLJcrFGwQhyufbQQ7rFpy\nLMkCwGZC34qPIuwp+XPOjBFwazQ/txrdFS2GGS/Xuj+pUKLGk1Kjvlded3s72lyGW+PLbGVcmrAA\ngN0wTk1NWYODg9XOKltGtpazi5GigzroUnHN5nUHG1ylRsG7rDXHmnEpu4CeEtEKkqNc6QqlLc/M\n8uT5lLH5eq0aGxsju1O7GQB498a5s/0x9dRALPaQEDZnYwnhWJtMCCNrjeb0UP34Z6e/PW22zjPP\n+vwXBwfPvbw38XnXjk7GsiwKAIQQhjAMMrlsam45d+zLH6/8o6vkWcBcrXbVKQhf6bpucCwLjmUB\nSmmhXC419eblrbD/TAgAkUjE987xE0c7ZDmk66ajUCnq+cL63fErl25s5/8baQPaWLhx6goAAAAA\nSUVORK5CYII=", + parameters => [ { type => "bool", desc => "Save archive title" } ], oneshot_arg => "Chaika Gallery or Archive URL (Will attach matching tags to your archive)" ); @@ -34,40 +33,36 @@ sub plugin_info { sub get_tags { shift; - my $lrr_info = shift; # Global info hash - my ($savetitle) = @_; # Plugin parameters + my $lrr_info = shift; # Global info hash + my ($savetitle) = @_; # Plugin parameters - my $logger = get_logger( "Chaika", "plugins" ); - my $newtags = ""; + my $logger = get_logger( "Chaika", "plugins" ); + my $newtags = ""; my $newtitle = ""; # Parse the given link to see if we can extract type and ID my $oneshotarg = $lrr_info->{oneshot_param}; - if ( $oneshotarg =~ - /https?:\/\/panda\.chaika\.moe\/(gallery|archive)\/([0-9]*)\/?.*/ ) - { - ($newtags, $newtitle) = tags_from_chaika_id( $1, $2 ); - } - else { + if ( $oneshotarg =~ /https?:\/\/panda\.chaika\.moe\/(gallery|archive)\/([0-9]*)\/?.*/ ) { + ( $newtags, $newtitle ) = tags_from_chaika_id( $1, $2 ); + } else { # Try SHA-1 reverse search first - ($newtags, $newtitle) = tags_from_sha1($lrr_info->{thumbnail_hash}); + ( $newtags, $newtitle ) = tags_from_sha1( $lrr_info->{thumbnail_hash} ); # Try search if it fails if ( $newtags eq "" ) { - ($newtags, $newtitle) = search_for_archive( $lrr_info->{archive_title}, $lrr_info->{existing_tags} ); + ( $newtags, $newtitle ) = search_for_archive( $lrr_info->{archive_title}, $lrr_info->{existing_tags} ); } } if ( $newtags eq "" ) { $logger->info("No matching Chaika Archive Found!"); return ( error => "No matching Chaika Archive Found!" ); - } - else { + } else { + #Return a hash containing the new metadata - if ($savetitle && $newtags ne "") - { return ( tags => $newtags, title => $newtitle ); } - else { return ( tags => $newtags ); } + if ( $savetitle && $newtags ne "" ) { return ( tags => $newtags, title => $newtitle ); } + else { return ( tags => $newtags ); } } } @@ -99,15 +94,15 @@ sub search_for_archive { } $logger->debug("Calling $URL"); - my $ua = Mojo::UserAgent->new; + my $ua = Mojo::UserAgent->new; my $res = $ua->get($URL)->result; my $textrep = $res->body; $logger->debug("Chaika API returned this JSON: $textrep"); - my ($chaitags, $chaititle) = parse_chaika_json( $res->json->{"galleries"}->[0] ); + my ( $chaitags, $chaititle ) = parse_chaika_json( $res->json->{"galleries"}->[0] ); $logger->info("Sending the following tags to LRR: $chaitags"); - return ($chaitags, $chaititle); + return ( $chaitags, $chaititle ); } # Uses the jsearch API to get the best json for a file. @@ -124,10 +119,10 @@ sub tags_from_chaika_id { my $textrep = $res->body; $logger->debug("Chaika API returned this JSON: $textrep"); - my ($chaitags, $chaititle) = parse_chaika_json( $res->json ); + my ( $chaitags, $chaititle ) = parse_chaika_json( $res->json ); $logger->info("Sending the following tags to LRR: $chaitags"); - return ($chaitags, $chaititle); + return ( $chaitags, $chaititle ); } @@ -142,18 +137,18 @@ sub tags_from_sha1 { # The jsearch API immediately returns a JSON. # Said JSON is an array containing multiple archive objects. # We just take the first one. - my $ua = Mojo::UserAgent->new; - my $res = $ua->get($URL)->result; - my ($chaitags, $chaititle) = parse_chaika_json( $res->json->[0] ); + my $ua = Mojo::UserAgent->new; + my $res = $ua->get($URL)->result; + my ( $chaitags, $chaititle ) = parse_chaika_json( $res->json->[0] ); $logger->info("SHA-1 reverse search found the following tags: $chaitags"); - return ($chaitags, $chaititle); + return ( $chaitags, $chaititle ); } # Parses the JSON obtained from the Chaika API to get the tags. sub parse_chaika_json { my $logger = get_logger( "Chaika", "plugins" ); - my $json = $_[0]; + my $json = $_[0]; # If the json contains a gallery id, we switch to it. # Gallery IDs often have more metadata stored. @@ -168,12 +163,12 @@ sub parse_chaika_json { # Switch to gallery tags if there are any. # Occasionally archives won't have a matching gallery despite the ID being there. (huh) - if ($res->json->{"tags"}) { + if ( $res->json->{"tags"} ) { $json = $res->json; } else { - $logger->debug("Gallery doesn't actually have tags! Switching back to Archive.") + $logger->debug("Gallery doesn't actually have tags! Switching back to Archive."); } - + } my $tags = $json->{"tags"}; @@ -187,7 +182,7 @@ sub parse_chaika_json { $res .= $tag; } - return ($res, $json->{"title"}); + return ( $res, $json->{"title"} ); } diff --git a/lib/LANraragi/Plugin/Metadata/CopyTags.pm b/lib/LANraragi/Plugin/Metadata/CopyTags.pm index b63142413..8dcc4d218 100644 --- a/lib/LANraragi/Plugin/Metadata/CopyTags.pm +++ b/lib/LANraragi/Plugin/Metadata/CopyTags.pm @@ -17,10 +17,9 @@ sub plugin_info { author => "Difegue", version => "2.1", description => "Apply custom tag modifications.", - icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\nB3RJTUUH4wYCFQ05iQtpeQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH\nAAAD8ElEQVQ4y4WUW2yURRTHfzPfty2UWrZbqdrdhktowQAJiQ/iDUwkaFJ5IAQfGjWBByMhwYAm\nBH3xqT5ArARS9cUgJC1qjCDxCY1JEy6lLVJrW9lKq6Wlgcqy2W7b/S4zx4fdbstFneRMZjLJb/7n\nf86MOn78+MlEIvE6gIhgRRARECGTmaS0tJT6+vrvo7HKxserq6f4v9Hc3PyxiBh5yBgYGJBUKiW/\n9vZKV/eVb7s6OyN79uxhbGwMKVx8f2gRUUEQEAQhfhDg+wGeHxAaA8DZs2e50tVNZ+flJ3v7B8ra\n29uJx+M0NTXhed6DCg8dPtzs+77xfV883xfP8yVXCM/zxA9CCcNQzv3402+bX96yuK2tjd27dxOP\nx2loaCCdTj+gkIJlICAFLz0vx/RMjmx2kunpaXK5nF5au3RJb29fzdq162ouX+p4ZHh4mO3bt98j\n0DU2n5oUZqUUvudz8cIFEvEEoQkRIBarXLFr584frLVmdHRUj4yNXu3r69tbVVV1u7W1lcbGxjxQ\njMzjKxAw1rJoURlr1q7B9wMEQaFKBerDwMfzPKKLo6t+uXp12Z07d16pq6tL79ixg0gkgjamkCv5\nvItKUfkrFCilmN0orZmayrJgQSlDQ0NPHz3WskhrTXd3NwBaxBR8m007v7aza+a8RQTXcaipTTAx\nMYHn+2SnJ4nFYgwODuaBRmxB3FylEEGsLRKliBZcHSFVkSFVOUWiOk5uxiObzZJKpfJAa8wciPvA\nzIflzxSKW+EtDgx8wKUbXVSYcuM4TtEWba1VSkGkJILruvmIuFibh2gNjtI4SuNqB6XBVQ7jFTdo\nK/+GiWemNmmt59omFouNfXf6dLsIalZZGJrI6lV1zwIcOP8hQ871YsE0mpRJUVFWTnZ5WjpSF09t\n+WhbJdf4DMDdv2/foYMHDx46c+YMW7dupba2lutDw1UrV674G+B3/xr9VT1gVLFMWjk4SoOg/ope\nZyo9/elzq1/QQIs7v8u11oyMjFBTU6OszKas0I4D6t4nG1qDAqwWJnWG0IbrAdz737ZSCmsNUvAw\nmAnxJsxcHyEoV+FUgDiWhXfL2RS89FXdtSfeYss8oDEGz/Ow1mKMQReq9vXmE4SSVyPAAl3KiT9b\n2X/7XZZMPcbz9sWTl94/9+bn63vUXvaKCxCGIclkkmQyCcCxlhZJ/jHI3XR60hqjpdinloiUSJ/0\nlZQuLC/Z0L9B4n2V73zR08ORXUcEyFd2fHycTCZT7KWLHR3q5s3xyslMxlhrlYjklVvLuv6V/tE3\nTr29vGzZxlffe+q1jV82hObRwFZXVxONRvnXn/e/ounCJzU/z5yPPOzsH4cGnEj6mhLzAAAAAElF\nTkSuQmCC", - parameters => [ - {type => "string", desc => "Tags to copy, separated by commas."} - ] + icon => + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\nB3RJTUUH4wYCFQ05iQtpeQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH\nAAAD8ElEQVQ4y4WUW2yURRTHfzPfty2UWrZbqdrdhktowQAJiQ/iDUwkaFJ5IAQfGjWBByMhwYAm\nBH3xqT5ArARS9cUgJC1qjCDxCY1JEy6lLVJrW9lKq6Wlgcqy2W7b/S4zx4fdbstFneRMZjLJb/7n\nf86MOn78+MlEIvE6gIhgRRARECGTmaS0tJT6+vrvo7HKxserq6f4v9Hc3PyxiBh5yBgYGJBUKiW/\n9vZKV/eVb7s6OyN79uxhbGwMKVx8f2gRUUEQEAQhfhDg+wGeHxAaA8DZs2e50tVNZ+flJ3v7B8ra\n29uJx+M0NTXhed6DCg8dPtzs+77xfV883xfP8yVXCM/zxA9CCcNQzv3402+bX96yuK2tjd27dxOP\nx2loaCCdTj+gkIJlICAFLz0vx/RMjmx2kunpaXK5nF5au3RJb29fzdq162ouX+p4ZHh4mO3bt98j\n0DU2n5oUZqUUvudz8cIFEvEEoQkRIBarXLFr584frLVmdHRUj4yNXu3r69tbVVV1u7W1lcbGxjxQ\njMzjKxAw1rJoURlr1q7B9wMEQaFKBerDwMfzPKKLo6t+uXp12Z07d16pq6tL79ixg0gkgjamkCv5\nvItKUfkrFCilmN0orZmayrJgQSlDQ0NPHz3WskhrTXd3NwBaxBR8m007v7aza+a8RQTXcaipTTAx\nMYHn+2SnJ4nFYgwODuaBRmxB3FylEEGsLRKliBZcHSFVkSFVOUWiOk5uxiObzZJKpfJAa8wciPvA\nzIflzxSKW+EtDgx8wKUbXVSYcuM4TtEWba1VSkGkJILruvmIuFibh2gNjtI4SuNqB6XBVQ7jFTdo\nK/+GiWemNmmt59omFouNfXf6dLsIalZZGJrI6lV1zwIcOP8hQ871YsE0mpRJUVFWTnZ5WjpSF09t\n+WhbJdf4DMDdv2/foYMHDx46c+YMW7dupba2lutDw1UrV674G+B3/xr9VT1gVLFMWjk4SoOg/ope\nZyo9/elzq1/QQIs7v8u11oyMjFBTU6OszKas0I4D6t4nG1qDAqwWJnWG0IbrAdz737ZSCmsNUvAw\nmAnxJsxcHyEoV+FUgDiWhXfL2RS89FXdtSfeYss8oDEGz/Ow1mKMQReq9vXmE4SSVyPAAl3KiT9b\n2X/7XZZMPcbz9sWTl94/9+bn63vUXvaKCxCGIclkkmQyCcCxlhZJ/jHI3XR60hqjpdinloiUSJ/0\nlZQuLC/Z0L9B4n2V73zR08ORXUcEyFd2fHycTCZT7KWLHR3q5s3xyslMxlhrlYjklVvLuv6V/tE3\nTr29vGzZxlffe+q1jV82hObRwFZXVxONRvnXn/e/ounCJzU/z5yPPOzsH4cGnEj6mhLzAAAAAElF\nTkSuQmCC", + parameters => [ { type => "string", desc => "Tags to copy, separated by commas." } ] ); } @@ -28,14 +27,14 @@ sub plugin_info { #Mandatory function to be implemented by your plugin sub get_tags { - shift; - my $lrr_info = shift; # Global info hash - my ($tagstocopy) = @_; # Plugin parameters + shift; + my $lrr_info = shift; # Global info hash + my ($tagstocopy) = @_; # Plugin parameters my $logger = get_logger( "Tag Copy", "plugins" ); #Tags to copy is the first global argument - $logger->debug("Sending the following tags to LRR: " . $tagstocopy ); + $logger->debug( "Sending the following tags to LRR: " . $tagstocopy ); return ( tags => $tagstocopy ); } diff --git a/lib/LANraragi/Plugin/Metadata/DateAdded.pm b/lib/LANraragi/Plugin/Metadata/DateAdded.pm index 01d371a12..2f4a88a41 100644 --- a/lib/LANraragi/Plugin/Metadata/DateAdded.pm +++ b/lib/LANraragi/Plugin/Metadata/DateAdded.pm @@ -3,7 +3,7 @@ package LANraragi::Plugin::Metadata::DateAdded; use strict; use warnings; -#Plugins can freely use all Perl packages already installed on the system +#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. use Mojo::UserAgent; @@ -21,11 +21,11 @@ sub plugin_info { author => "Utazukin", version => "0.3", description => "Adds the unix time stamp of the date the archive was added as a tag under the \"date_added\" namespace.", - icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\nB3RJTUUH4wYCFQY4HfiAJAAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH\nAAADKUlEQVQ4y6WVsUtrVxzHP+fmkkiqJr2CQWKkvCTwJgkJDpmyVAR1cVOhdq04tHNB7BD8A97S\nXYkO3dRRsMSlFoIOLYFEohiDiiTNNeaGpLn5dRDv06ev75V+4SyH8/2c3/n+zuEoEeFTqtfrb5RS\nJZ/P98m1iMirI5fLMT8/L+FwWEKhkIRCIXn79q2srKxIpVL5qE/7cINms8ny8rIkEgkpl8skk0lm\nZ2eZmZkhHo+TzWYJBoOyvr4u7Xb7RYHq6ZEvLi6Ynp6WVqvFwsIC4+PjRCIRDMNAKcXNzQ2lUols\nNsvOzg6xWIxMJqOeRuEAq9UqqVRKhoaGmJubY2pqCl3XiUajXF5e0t/fz+DgIIVCAbfbzdbWFtvb\n24yMjLC/v6+eZWjbNqurq5JIJGRtbU0syxLbtsU0TXmqXq8njUZDRERubm4knU6LYRiSyWScDBER\nGo0G4XBYFhcX5fz8XP4yTbGLf0hnd0s+plqtJru7u7K0tCSRSEQ6nc77ppycnFCv10kmk4yOjoII\n2kiIv3//lfbGu1dvh1KKVCrF2NgYmqaRy+UAHoCHh4f4fD4mJiZwuVz4fT74YhDvTz/TPv2TX378\ngWKx+Azo9/sZGBhAKYVhGBSLxa8doGmaABiGQT6fp9VqPbg0jcr897w7+I3FxUVs23aAlmVxe3tL\nPB7n/v6eWq22D6A/lq+UotlsEo1G8Xg8jvFNOMzCN99iGF/icrmc+b6+PrxeL6enp7hcLpR6aLT+\nuEDTNEqlErFYDMuy8Hq9AHg8HpaXv3uRYbfbRdM0TNNE096/Dweo6zoHBwfE43F0XXeAjyf4UJVK\nhUql8iwGJ8NHeb1e9vb2CAaDADQajRcgy7IACAQCHB0d/TtQ0zQuLi7Y3Nzk+vqacrkMwNXVFXd3\nd7Tbbc7Ozuh0OmxsbHB1dfViQ/21+3V8fIxpmkxOTmKaJrZt0263sW0b27ZJp9M0m010XX8RhwN8\nNPV6PQCKxSL5fB7DMAgEAnS7XarVKtVqFbfbjVIK27ZRSjkeB9jtdikUChQKBf6vlIg4Gb3Wzc/V\n8PDwV36//1x9zhfwX/QPryPQMvGWTdEAAAAASUVORK5CYII=", - parameters => [ - {type => "bool", desc => "Use file modified time instead of current time."} - ], - oneshot_arg => "Use file modified time (yes/true), or use current time (no/false).
    Leaving blank uses the global setting (default: current time)" + icon => + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\nB3RJTUUH4wYCFQY4HfiAJAAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH\nAAADKUlEQVQ4y6WVsUtrVxzHP+fmkkiqJr2CQWKkvCTwJgkJDpmyVAR1cVOhdq04tHNB7BD8A97S\nXYkO3dRRsMSlFoIOLYFEohiDiiTNNeaGpLn5dRDv06ev75V+4SyH8/2c3/n+zuEoEeFTqtfrb5RS\nJZ/P98m1iMirI5fLMT8/L+FwWEKhkIRCIXn79q2srKxIpVL5qE/7cINms8ny8rIkEgkpl8skk0lm\nZ2eZmZkhHo+TzWYJBoOyvr4u7Xb7RYHq6ZEvLi6Ynp6WVqvFwsIC4+PjRCIRDMNAKcXNzQ2lUols\nNsvOzg6xWIxMJqOeRuEAq9UqqVRKhoaGmJubY2pqCl3XiUajXF5e0t/fz+DgIIVCAbfbzdbWFtvb\n24yMjLC/v6+eZWjbNqurq5JIJGRtbU0syxLbtsU0TXmqXq8njUZDRERubm4knU6LYRiSyWScDBER\nGo0G4XBYFhcX5fz8XP4yTbGLf0hnd0s+plqtJru7u7K0tCSRSEQ6nc77ppycnFCv10kmk4yOjoII\n2kiIv3//lfbGu1dvh1KKVCrF2NgYmqaRy+UAHoCHh4f4fD4mJiZwuVz4fT74YhDvTz/TPv2TX378\ngWKx+Azo9/sZGBhAKYVhGBSLxa8doGmaABiGQT6fp9VqPbg0jcr897w7+I3FxUVs23aAlmVxe3tL\nPB7n/v6eWq22D6A/lq+UotlsEo1G8Xg8jvFNOMzCN99iGF/icrmc+b6+PrxeL6enp7hcLpR6aLT+\nuEDTNEqlErFYDMuy8Hq9AHg8HpaXv3uRYbfbRdM0TNNE096/Dweo6zoHBwfE43F0XXeAjyf4UJVK\nhUql8iwGJ8NHeb1e9vb2CAaDADQajRcgy7IACAQCHB0d/TtQ0zQuLi7Y3Nzk+vqacrkMwNXVFXd3\nd7Tbbc7Ozuh0OmxsbHB1dfViQ/21+3V8fIxpmkxOTmKaJrZt0263sW0b27ZJp9M0m010XX8RhwN8\nNPV6PQCKxSL5fB7DMAgEAnS7XarVKtVqFbfbjVIK27ZRSjkeB9jtdikUChQKBf6vlIg4Gb3Wzc/V\n8PDwV36//1x9zhfwX/QPryPQMvGWTdEAAAAASUVORK5CYII=", + parameters => [ { type => "bool", desc => "Use file modified time instead of current time." } ], + oneshot_arg => + "Use file modified time (yes/true), or use current time (no/false).
    Leaving blank uses the global setting (default: current time)" ); } @@ -34,26 +34,26 @@ sub plugin_info { sub get_tags { shift; - my $lrr_info = shift; # Global info hash - my ($use_filetime) = @_; # Plugin parameters + my $lrr_info = shift; # Global info hash + my ($use_filetime) = @_; # Plugin parameters #Use the logger to output status - they'll be passed to a specialized logfile and written to STDOUT. - my $logger = get_logger("Date Added Plugin","plugins"); + my $logger = get_logger( "Date Added Plugin", "plugins" ); #Work your magic here - You can create subroutines below to organize the code better - $logger->debug("Processing file: " . $lrr_info->{file_path}); - my $newtags = ""; - my $oneshotarg = $lrr_info->{oneshot_param}; - my $oneshot_file_time = $oneshotarg =~ /^(yes|true)$/i; + $logger->debug( "Processing file: " . $lrr_info->{file_path} ); + my $newtags = ""; + my $oneshotarg = $lrr_info->{oneshot_param}; + my $oneshot_file_time = $oneshotarg =~ /^(yes|true)$/i; my $oneshot_current_time = $oneshotarg =~ /^(no|false)$/i; - if ($oneshot_file_time || ($use_filetime && !$oneshot_current_time)) { - $logger->info("Using file date"); - $newtags = "date_added:" . (stat($lrr_info->{file_path}))[9]; #9 is the unix time stamp for date modified. + if ( $oneshot_file_time || ( $use_filetime && !$oneshot_current_time ) ) { + $logger->info("Using file date"); + $newtags = "date_added:" . ( stat( $lrr_info->{file_path} ) )[9]; #9 is the unix time stamp for date modified. } else { - $logger->info("Using current date"); - $newtags = "date_added:" . time(); + $logger->info("Using current date"); + $newtags = "date_added:" . time(); } return ( tags => $newtags ); } diff --git a/lib/LANraragi/Plugin/Metadata/EHentai.pm b/lib/LANraragi/Plugin/Metadata/EHentai.pm index c4f8d3037..8bfdaac6c 100644 --- a/lib/LANraragi/Plugin/Metadata/EHentai.pm +++ b/lib/LANraragi/Plugin/Metadata/EHentai.pm @@ -26,12 +26,13 @@ sub plugin_info { author => "Difegue", version => "2.3", description => "Searches g.e-hentai for tags matching your archive.", - icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wYBFg0JvyFIYgAAAB1pVFh0Q29tbWVudAAAAAAAQ3Jl\nYXRlZCB3aXRoIEdJTVBkLmUHAAAEo0lEQVQ4y02UPWhT7RvGf8/5yMkxMU2NKaYIFtKAHxWloYNU\ncRDeQTsUFPwAFwUHByu4ODq4Oghdiri8UIrooCC0Lx01ONSKfYOioi1WpWmaxtTm5PTkfNzv0H/D\n/9oeePjdPNd13Y8aHR2VR48eEUURpmmiaRqmaXbOAK7r4vs+IsLk5CSTk5P4vo9hGIgIsViMra0t\nCoUCRi6XY8+ePVSrVTRN61yybZuXL1/y7t078vk8mUyGvXv3cuLECWZnZ1lbW6PdbpNIJHAcB8uy\nePr0KYZlWTSbTRKJBLquo5TCMAwmJia4f/8+Sini8Ti1Wo0oikin09i2TbPZJJPJUK/XefDgAefO\nnWNlZQVD0zSUUvi+TxAE6LqOrut8/fqVTCaDbdvkcjk0TSOdTrOysoLrujiOw+bmJmEYMjAwQLVa\nJZVKYXR1ddFut/F9H9M0MU0T3/dZXV3FdV36+/vp7u7m6NGj7Nq1i0qlwuLiIqVSib6+Pubn5wGw\nbZtYLIaxMymVSuH7PpZlEUURSina7TZBEOD7Pp8/fyYMQ3zfZ25ujv3795NOp3n48CE9PT3ouk4Q\nBBi/fv3Ctm0cx6Grq4utrS26u7sREQzDIIoifv78SU9PD5VKhTAMGRoaYnV1leHhYa5evUoQBIRh\niIigiQhRFKHrOs1mE9u2iaKIkydPYhgGAKZp8v79e+LxOPl8Htd1uXbtGrdv3yYMQ3ZyAODFixeb\nrVZLvn//Lq7rSqVSkfX1dREROXz4sBw/flyUUjI6OipXrlyRQ4cOSbPZlCiKxHVdCcNQHMcRz/PE\ndV0BGL53756sra1JrVaT9fV1cRxHRESGhoakr69PUqmUvHr1SsrlsuzI931ptVriuq78+fNHPM+T\nVqslhoikjh075p09e9ba6aKu6/T39zM4OMjS0hIzMzM0Gg12794N0LEIwPd9YrEYrusShiEK4Nmz\nZ41yudyVy+XI5/MMDAyQzWap1+tks1lEhIWFBQqFArZto5QiCAJc1+14t7m5STweRwOo1WoSBAEj\nIyMUi0WSySQiQiqV6lRoYWGhY3673e7sfRAEiAjZbBbHcbaBb9++5cCBA2SzWZLJJLZt43kesViM\nHX379g1d1wnDsNNVEQEgCAIajQZ3797dBi4tLWGaJq7rYpompVKJmZkZ2u12B3j58mWUUmiahoiw\nsbFBEASdD2VsbIwnT55gACil+PHjB7Ozs0xPT/P7929u3ryJZVmEYUgYhhQKBZRSiAie52EYBkop\nLMvi8ePHTE1NUSwWt0OZn5/3hoeHzRs3bqhcLseXL1+YmJjowGzbRtO07RT/F8jO09+8ecP58+dJ\nJBKcPn0abW5uThWLRevOnTv/Li4u8vr1a3p7e9E0jXg8zsePHymVSnz69Kmzr7quY9s2U1NTXLp0\nCc/zOHLkCPv27UPxf6rX63+NjIz8IyKMj48zPT3NwYMHGRwcpLe3FwARodVqcf36dS5evMj4+DhB\nEHDmzBkymQz6DqxSqZDNZr8tLy//DYzdunWL5eVlqtUqHz58IJVKkUwmaTQalMtlLly4gIjw/Plz\nTp06RT6fZ2Njg/8AqMV7tO07rnsAAAAASUVORK5CYII=", - parameters => [ - {type => "string", desc => "Forced language to use in searches"}, - {type => "bool", desc => "Save archive title"}, - {type => "bool", desc => "Fetch using thumbnail first"}, - {type => "bool", desc => "Use ExHentai (enable to search for fjorded content without star cookie)"} + icon => + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wYBFg0JvyFIYgAAAB1pVFh0Q29tbWVudAAAAAAAQ3Jl\nYXRlZCB3aXRoIEdJTVBkLmUHAAAEo0lEQVQ4y02UPWhT7RvGf8/5yMkxMU2NKaYIFtKAHxWloYNU\ncRDeQTsUFPwAFwUHByu4ODq4Oghdiri8UIrooCC0Lx01ONSKfYOioi1WpWmaxtTm5PTkfNzv0H/D\n/9oeePjdPNd13Y8aHR2VR48eEUURpmmiaRqmaXbOAK7r4vs+IsLk5CSTk5P4vo9hGIgIsViMra0t\nCoUCRi6XY8+ePVSrVTRN61yybZuXL1/y7t078vk8mUyGvXv3cuLECWZnZ1lbW6PdbpNIJHAcB8uy\nePr0KYZlWTSbTRKJBLquo5TCMAwmJia4f/8+Sini8Ti1Wo0oikin09i2TbPZJJPJUK/XefDgAefO\nnWNlZQVD0zSUUvi+TxAE6LqOrut8/fqVTCaDbdvkcjk0TSOdTrOysoLrujiOw+bmJmEYMjAwQLVa\nJZVKYXR1ddFut/F9H9M0MU0T3/dZXV3FdV36+/vp7u7m6NGj7Nq1i0qlwuLiIqVSib6+Pubn5wGw\nbZtYLIaxMymVSuH7PpZlEUURSina7TZBEOD7Pp8/fyYMQ3zfZ25ujv3795NOp3n48CE9PT3ouk4Q\nBBi/fv3Ctm0cx6Grq4utrS26u7sREQzDIIoifv78SU9PD5VKhTAMGRoaYnV1leHhYa5evUoQBIRh\niIigiQhRFKHrOs1mE9u2iaKIkydPYhgGAKZp8v79e+LxOPl8Htd1uXbtGrdv3yYMQ3ZyAODFixeb\nrVZLvn//Lq7rSqVSkfX1dREROXz4sBw/flyUUjI6OipXrlyRQ4cOSbPZlCiKxHVdCcNQHMcRz/PE\ndV0BGL53756sra1JrVaT9fV1cRxHRESGhoakr69PUqmUvHr1SsrlsuzI931ptVriuq78+fNHPM+T\nVqslhoikjh075p09e9ba6aKu6/T39zM4OMjS0hIzMzM0Gg12794N0LEIwPd9YrEYrusShiEK4Nmz\nZ41yudyVy+XI5/MMDAyQzWap1+tks1lEhIWFBQqFArZto5QiCAJc1+14t7m5STweRwOo1WoSBAEj\nIyMUi0WSySQiQiqV6lRoYWGhY3673e7sfRAEiAjZbBbHcbaBb9++5cCBA2SzWZLJJLZt43kesViM\nHX379g1d1wnDsNNVEQEgCAIajQZ3797dBi4tLWGaJq7rYpompVKJmZkZ2u12B3j58mWUUmiahoiw\nsbFBEASdD2VsbIwnT55gACil+PHjB7Ozs0xPT/P7929u3ryJZVmEYUgYhhQKBZRSiAie52EYBkop\nLMvi8ePHTE1NUSwWt0OZn5/3hoeHzRs3bqhcLseXL1+YmJjowGzbRtO07RT/F8jO09+8ecP58+dJ\nJBKcPn0abW5uThWLRevOnTv/Li4u8vr1a3p7e9E0jXg8zsePHymVSnz69Kmzr7quY9s2U1NTXLp0\nCc/zOHLkCPv27UPxf6rX63+NjIz8IyKMj48zPT3NwYMHGRwcpLe3FwARodVqcf36dS5evMj4+DhB\nEHDmzBkymQz6DqxSqZDNZr8tLy//DYzdunWL5eVlqtUqHz58IJVKkUwmaTQalMtlLly4gIjw/Plz\nTp06RT6fZ2Njg/8AqMV7tO07rnsAAAAASUVORK5CYII=", + parameters => [ + { type => "string", desc => "Forced language to use in searches" }, + { type => "bool", desc => "Save archive title" }, + { type => "bool", desc => "Fetch using thumbnail first" }, + { type => "bool", desc => "Use ExHentai (enable to search for fjorded content without star cookie)" } ], oneshot_arg => "E-H Gallery URL (Will attach tags matching this exact gallery to your archive)" ); @@ -42,8 +43,8 @@ sub plugin_info { sub get_tags { shift; - my $lrr_info = shift; # Global info hash - my ($lang, $savetitle, $usethumbs, $enablepanda) = @_; # Plugin parameters + my $lrr_info = shift; # Global info hash + my ( $lang, $savetitle, $usethumbs, $enablepanda ) = @_; # Plugin parameters # Use the logger to output status - they'll be passed to a specialized logfile and written to STDOUT. my $logger = get_logger( "E-Hentai", "plugins" ); @@ -51,7 +52,7 @@ sub get_tags { # Work your magic here - You can create subroutines below to organize the code better my $gID = ""; my $gToken = ""; - my $domain = ($enablepanda ? 'https://exhentai.org' : 'https://e-hentai.org'); + my $domain = ( $enablepanda ? 'https://exhentai.org' : 'https://e-hentai.org' ); # Quick regex to get the E-H archive ids from the provided url or source tag if ( $lrr_info->{oneshot_param} =~ /.*\/g\/([0-9]*)\/([0-z]*)\/*.*/ ) { @@ -63,15 +64,20 @@ sub get_tags { $gToken = $2; $logger->debug("Skipping search and using gallery $gID / $gToken from source tag"); } else { + # Craft URL for Text Search on EH if there's no user argument - ( $gID, $gToken ) = - &lookup_gallery( $lrr_info->{archive_title}, $lrr_info->{existing_tags}, - $lrr_info->{thumbnail_hash}, $lang, $lrr_info->{user_agent}, $domain, $usethumbs); + ( $gID, $gToken ) = &lookup_gallery( + $lrr_info->{archive_title}, + $lrr_info->{existing_tags}, + $lrr_info->{thumbnail_hash}, + $lang, $lrr_info->{user_agent}, + $domain, $usethumbs + ); } - # If an error occured, return a hash containing an error message. - # LRR will display that error to the client. - # Using the GToken to store error codes - not the cleanest but it's convenient + # If an error occured, return a hash containing an error message. + # LRR will display that error to the client. + # Using the GToken to store error codes - not the cleanest but it's convenient if ( $gID eq "" ) { if ( $gToken ne "" ) { @@ -81,18 +87,17 @@ sub get_tags { $logger->info("No matching EH Gallery Found!"); return ( error => "No matching EH Gallery Found!" ); - } - else { + } else { $logger->debug("EH API Tokens are $gID / $gToken"); } - my ( $ehtags, $ehtitle) = &get_tags_from_EH( $gID, $gToken ); + my ( $ehtags, $ehtitle ) = &get_tags_from_EH( $gID, $gToken ); my %hashdata = ( tags => $ehtags ); # Add source URL and title if possible - if ($hashdata{tags} ne "") { + if ( $hashdata{tags} ne "" ) { - $hashdata{tags} .= ", source:". (split( '://', $domain))[1] . "/g/$gID/$gToken"; + $hashdata{tags} .= ", source:" . ( split( '://', $domain ) )[1] . "/g/$gID/$gToken"; if ($savetitle) { $hashdata{title} = $ehtitle; } } @@ -106,24 +111,26 @@ sub get_tags { sub lookup_gallery { - my ( $title, $tags, $thumbhash, $defaultlanguage, $ua, $domain, $usethumbs) = @_; + my ( $title, $tags, $thumbhash, $defaultlanguage, $ua, $domain, $usethumbs ) = @_; my $logger = get_logger( "E-Hentai", "plugins" ); my $URL = ""; #Thumbnail reverse image search - if ( $thumbhash ne "" && $usethumbs) { + if ( $thumbhash ne "" && $usethumbs ) { $logger->info("Reverse Image Search Enabled, trying first."); #search with image SHA hash - $URL = $domain - . "?advsearch=1&f_sname=on&f_stags=on&f_sdt2=on&f_spf=&f_spt=&f_sfu=on&f_sft=on&f_sfl=on&f_shash=". $thumbhash + $URL = + $domain + . "?advsearch=1&f_sname=on&f_stags=on&f_sdt2=on&f_spf=&f_spt=&f_sfu=on&f_sft=on&f_sfl=on&f_shash=" + . $thumbhash . "&fs_covers=1&fs_similar=1&f_search="; #Add the language override, if it's defined. if ( $defaultlanguage ne "" ) { $URL = $URL . uri_escape_utf8("language:$defaultlanguage"); - } + } $logger->debug("Using URL $URL (archive thumbnail hash)"); @@ -138,11 +145,12 @@ sub lookup_gallery { $URL = $domain . "?advsearch=1&f_sname=on&f_stags=on&f_sdt2=on&f_spf=&f_spt=&f_sfu=on&f_sft=on&f_sfl=on" - . "&f_search=" . uri_escape_utf8(qw(").$title.qw(")); + . "&f_search=" + . uri_escape_utf8( qw(") . $title . qw(") ); #Add the language override, if it's defined. if ( $defaultlanguage ne "" ) { - $URL = $URL . "+" . uri_escape_utf8("language:$defaultlanguage"); + $URL = $URL . "+" . uri_escape_utf8("language:$defaultlanguage"); } #Add artist tag from the OG tags if it exists @@ -158,8 +166,8 @@ sub lookup_gallery { # Performs a remote search on e- or exhentai, and returns the ID/token matching the found gallery. sub ehentai_parse() { - my $URL = $_[0]; - my $ua = $_[1]; + my $URL = $_[0]; + my $ua = $_[1]; my $logger = get_logger( "E-Hentai", "plugins" ); my $response = $ua->max_redirects(5)->get($URL)->result; @@ -172,7 +180,7 @@ sub ehentai_parse() { my $gID = ""; my $gToken = ""; - my $dom = Mojo::DOM->new( $content ); + my $dom = Mojo::DOM->new($content); eval { # Get the first row of the search results @@ -181,16 +189,16 @@ sub ehentai_parse() { my $firstgal = $dom->at(".glink")->parent->attr('href'); # A EH link looks like xhentai.org/g/{gallery id}/{gallery token} - my $url = ( split( 'hentai.org/g/', $firstgal ) )[1]; - my @values = ( split( '/', $url ) ); + my $url = ( split( 'hentai.org/g/', $firstgal ) )[1]; + my @values = ( split( '/', $url ) ); $gID = $values[0]; $gToken = $values[1]; }; if ( index( $content, "You are opening" ) != -1 ) { - my $rand = 15 + int(rand(51 - 15)); - $logger->info("Sleeping for $rand seconds due to EH excessive requests warning" ); + my $rand = 15 + int( rand( 51 - 15 ) ); + $logger->info("Sleeping for $rand seconds due to EH excessive requests warning"); sleep($rand); } @@ -234,11 +242,11 @@ sub get_tags_from_EH { $ehtags = $ehtags . ", category:" . $ehcat; $logger->info("Sending the following tags to LRR: $ehtags"); - return ($ehtags, $ehtitle); - } - else { + return ( $ehtags, $ehtitle ); + } else { + #if an error occurs(no tags available) return empty strings. - return ("",""); + return ( "", "" ); } } diff --git a/lib/LANraragi/Plugin/Metadata/Eze.pm b/lib/LANraragi/Plugin/Metadata/Eze.pm index ebaaa4e54..55bd5eb1c 100644 --- a/lib/LANraragi/Plugin/Metadata/Eze.pm +++ b/lib/LANraragi/Plugin/Metadata/Eze.pm @@ -25,10 +25,9 @@ sub plugin_info { author => "Difegue", version => "2.2", description => "Collects metadata embedded into your archives by the eze userscript. (info.json files)", - icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\nB3RJTUUH4wYCFDYBnHlU6AAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH\nAAAETUlEQVQ4y22UTWhTWRTHf/d9JHmNJLFpShMcKoRIqxXE4sKpjgthYLCLggU/wI1CUWRUxlmU\nWblw20WZMlJc1yKKKCjCdDdYuqgRiygq2mL8aJpmQot5uabv3XdnUftG0bu593AOv3M45/yvGBgY\n4OrVqwRBgG3bGIaBbduhDSClxPM8tNZMTEwwMTGB53lYloXWmkgkwqdPnygUCljZbJbW1lYqlQqG\nYYRBjuNw9+5dHj16RD6fJ51O09bWxt69e5mammJ5eZm1tTXi8Tiu6xKNRrlx4wZWNBqlXq8Tj8cx\nTRMhBJZlMT4+zuXLlxFCEIvFqFarBEFAKpXCcRzq9TrpdJparcbIyAiHDh1icXERyzAMhBB4nofv\n+5imiWmavHr1inQ6jeM4ZLNZDMMglUqxuLiIlBLXdfn48SNKKXp6eqhUKiQSCaxkMsna2hqe52Hb\nNsMdec3n8+Pn2+vpETt37qSlpYVyucz8/DzT09Ns3bqVYrEIgOM4RCIRrI1MiUQCz/P43vE8jxcv\nXqCUwvM8Zmdn2bJlC6lUitHRUdrb2zFNE9/3sd6/f4/jOLiuSzKZDCH1wV/EzMwM3d3dNN69o729\nnXK5jFKKPXv2sLS0RF9fHydOnMD3fZRSaK0xtNYEQYBpmtTr9RC4b98+LMsCwLZtHj9+TCwWI5/P\nI6Xk5MmTXLhwAaUUG3MA4M6dOzQaDd68eYOUkqHIZj0U2ay11mzfvp1du3YhhGBgYIDjx4/T3d1N\nvV4nCAKklCilcF2XZrOJlBIBcOnSJc6ePYsQgj9yBf1l//7OJcXPH1Y1wK/Ff8SfvT995R9d/SA8\nzyMaja5Xq7Xm1q1bLCwssLS09M1Atm3bFr67urq+8W8oRUqJlBJLCMHNmze5d+8e2Ww2DPyrsSxq\ntRqZTAattZibm6PZbHJFVoUQgtOxtAbwfR8A13WJxWIYANVqFd/36e/v/ypzIpEgCAKEEMzNzYXN\n34CN/FsSvu+jtSaTyeC67jrw4cOHdHZ2kslkQmCz2SQSiYT269evMU0zhF2RVaH1ejt932dlZYXh\n4eF14MLCArZtI6UMAb+1/qBPx9L6jNOmAY4dO/b/agBnnDb9e1un3vhQzp8/z/Xr19eBQgjevn3L\n1NTUd5WilKJQKGAYxje+lpYWrl27xuTk5PqKARSLRfr6+hgaGiKbzfLy5UvGx8dRSqGUwnEcDMNA\nKYUQIlRGNBplZmaGw4cPE4/HOXDgAMbs7Cy9vb1cvHiR+fl5Hjx4QC6XwzAMYrEYz549Y3p6mufP\nn4d6NU0Tx3GYnJzk6NGjNJtNduzYQUdHB+LL8mu1Gv39/WitGRsb4/79+3R1dbF7925yuVw4/Uaj\nwalTpzhy5AhjY2P4vs/BgwdJp9OYG7ByuUwmk6FUKgFw7tw5SqUSlUqFp0+fkkgk2LRpEysrKzx5\n8oTBwUG01ty+fZv9+/eTz+dZXV3lP31rAEu+yXjEAAAAAElFTkSuQmCC", - parameters => [ - {type => "bool", desc => "Save archive title"} - ] + icon => + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\nB3RJTUUH4wYCFDYBnHlU6AAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH\nAAAETUlEQVQ4y22UTWhTWRTHf/d9JHmNJLFpShMcKoRIqxXE4sKpjgthYLCLggU/wI1CUWRUxlmU\nWblw20WZMlJc1yKKKCjCdDdYuqgRiygq2mL8aJpmQot5uabv3XdnUftG0bu593AOv3M45/yvGBgY\n4OrVqwRBgG3bGIaBbduhDSClxPM8tNZMTEwwMTGB53lYloXWmkgkwqdPnygUCljZbJbW1lYqlQqG\nYYRBjuNw9+5dHj16RD6fJ51O09bWxt69e5mammJ5eZm1tTXi8Tiu6xKNRrlx4wZWNBqlXq8Tj8cx\nTRMhBJZlMT4+zuXLlxFCEIvFqFarBEFAKpXCcRzq9TrpdJparcbIyAiHDh1icXERyzAMhBB4nofv\n+5imiWmavHr1inQ6jeM4ZLNZDMMglUqxuLiIlBLXdfn48SNKKXp6eqhUKiQSCaxkMsna2hqe52Hb\nNsMdec3n8+Pn2+vpETt37qSlpYVyucz8/DzT09Ns3bqVYrEIgOM4RCIRrI1MiUQCz/P43vE8jxcv\nXqCUwvM8Zmdn2bJlC6lUitHRUdrb2zFNE9/3sd6/f4/jOLiuSzKZDCH1wV/EzMwM3d3dNN69o729\nnXK5jFKKPXv2sLS0RF9fHydOnMD3fZRSaK0xtNYEQYBpmtTr9RC4b98+LMsCwLZtHj9+TCwWI5/P\nI6Xk5MmTXLhwAaUUG3MA4M6dOzQaDd68eYOUkqHIZj0U2ay11mzfvp1du3YhhGBgYIDjx4/T3d1N\nvV4nCAKklCilcF2XZrOJlBIBcOnSJc6ePYsQgj9yBf1l//7OJcXPH1Y1wK/Ff8SfvT995R9d/SA8\nzyMaja5Xq7Xm1q1bLCwssLS09M1Atm3bFr67urq+8W8oRUqJlBJLCMHNmze5d+8e2Ww2DPyrsSxq\ntRqZTAattZibm6PZbHJFVoUQgtOxtAbwfR8A13WJxWIYANVqFd/36e/v/ypzIpEgCAKEEMzNzYXN\n34CN/FsSvu+jtSaTyeC67jrw4cOHdHZ2kslkQmCz2SQSiYT269evMU0zhF2RVaH1ejt932dlZYXh\n4eF14MLCArZtI6UMAb+1/qBPx9L6jNOmAY4dO/b/agBnnDb9e1un3vhQzp8/z/Xr19eBQgjevn3L\n1NTUd5WilKJQKGAYxje+lpYWrl27xuTk5PqKARSLRfr6+hgaGiKbzfLy5UvGx8dRSqGUwnEcDMNA\nKYUQIlRGNBplZmaGw4cPE4/HOXDgAMbs7Cy9vb1cvHiR+fl5Hjx4QC6XwzAMYrEYz549Y3p6mufP\nn4d6NU0Tx3GYnJzk6NGjNJtNduzYQUdHB+LL8mu1Gv39/WitGRsb4/79+3R1dbF7925yuVw4/Uaj\nwalTpzhy5AhjY2P4vs/BgwdJp9OYG7ByuUwmk6FUKgFw7tw5SqUSlUqFp0+fkkgk2LRpEysrKzx5\n8oTBwUG01ty+fZv9+/eTz+dZXV3lP31rAEu+yXjEAAAAAElFTkSuQmCC", + parameters => [ { type => "bool", desc => "Save archive title" } ] ); } @@ -37,8 +36,8 @@ sub plugin_info { sub get_tags { shift; - my $lrr_info = shift; # Global info hash - my ($savetitle) = @_; # Plugin parameters + my $lrr_info = shift; # Global info hash + my ($savetitle) = @_; # Plugin parameters my $logger = get_logger( "eze", "plugins" ); if ( is_file_in_archive( $lrr_info->{file_path}, "info.json" ) ) { @@ -63,7 +62,7 @@ sub get_tags { $logger->debug("Found and loaded the following JSON: $stringjson"); #Parse it - my ($tags, $title) = tags_from_eze_json($hashjson); + my ( $tags, $title ) = tags_from_eze_json($hashjson); #Delete it unlink $filepath; @@ -71,15 +70,14 @@ sub get_tags { #Return tags $logger->info("Sending the following tags to LRR: $tags"); - if ($savetitle) { + if ($savetitle) { $logger->info("Parsed title is $title"); - return ( tags => $tags, title => $title ); - } else { - return ( tags => $tags ); + return ( tags => $tags, title => $title ); + } else { + return ( tags => $tags ); } - } - else { + } else { return ( error => "No eze info.json file found in this archive!" ); } @@ -99,7 +97,7 @@ sub tags_from_eze_json { # We use the parse_name routine used by Auto-Tag to get the title. my $ogtitle = $hash->{"gallery_info"}->{"title"}; - my ($title, $autotags) = LANraragi::Utils::Database::parse_name($ogtitle); + my ( $title, $autotags ) = LANraragi::Utils::Database::parse_name($ogtitle); remove_spaces($title); foreach my $namespace ( sort keys %$tags ) { @@ -116,16 +114,16 @@ sub tags_from_eze_json { # Add source tag if possible - my $site = $hash->{"gallery_info"}->{"source"}->{"site"}; - my $gid = $hash->{"gallery_info"}->{"source"}->{"gid"}; + my $site = $hash->{"gallery_info"}->{"source"}->{"site"}; + my $gid = $hash->{"gallery_info"}->{"source"}->{"gid"}; my $gtoken = $hash->{"gallery_info"}->{"source"}->{"token"}; - if ($site && $gid && $gtoken) { + if ( $site && $gid && $gtoken ) { $return .= ", source: $site.org/g/$gid/$gtoken"; } #Done-o - return ($return, $title); + return ( $return, $title ); } diff --git a/lib/LANraragi/Plugin/Metadata/Hdoujin.pm b/lib/LANraragi/Plugin/Metadata/Hdoujin.pm index 4ec8feb7c..70817deba 100644 --- a/lib/LANraragi/Plugin/Metadata/Hdoujin.pm +++ b/lib/LANraragi/Plugin/Metadata/Hdoujin.pm @@ -23,16 +23,18 @@ sub plugin_info { author => "Pao", version => "0.5", description => "Collects metadata embedded into your archives by HDoujin Downloader's json or txt files.", - icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wYDFB0m9797jwAAAB1pVFh0Q29tbWVudAAAAAAAQ3Jl\nYXRlZCB3aXRoIEdJTVBkLmUHAAAEbklEQVQ4y1WUPW/TUBSGn3uvHdv5cBqSOrQJgQ4ghqhCAgQM\nIIRAjF2Y2JhA/Q0g8R9YmJAqNoZKTAwMSAwdQEQUypeQEBEkTdtUbdzYiW1sM1RY4m5Hunp1znmf\n94jnz5+nAGmakiQJu7u7KKWwbRspJWma0m63+fHjB9PpFM/z6Ha7FAoFDMNga2uLx48fkyQJ29vb\nyCRJSNMUz/PY2dnBtm0qlQpKKZIkIQgCer0eW1tbDIdDJpMJc3NzuK5Lt9tF13WWl5dJkoRyuYyU\nUrK3t0ccx9TrdQzD4F/HSilM08Q0TWzbplqtUqvVKBaLKKVoNpt8/vyZKIq4fv064/EY2ev1KBQK\n2LadCQkhEEJkteu6+L6P7/tMJhOm0ylKKarVKjdu3GA6nXL+/HmSJEHWajV0Xf9P7N8TQhDHMWEY\nIoRgOBzieR4At2/f5uTJk0RRRLFYZHZ2liNHjqBFUcRoNKJarSKlRAiRmfPr1y/SNMVxHI4dO8aF\nCxfI5/O4rotSirdv33L16lV+//7Nly9fUEqh5XI5dF0nTdPMaSEEtm3TaDSwLAvLstB1nd3dXUql\nEqZpYlkW6+vrdLtdHjx4wPb2NmEYHgpalkUQBBwcHLC2tsbx48cpFos4jkMQBIRhyGQyYTgcsrGx\nQavVot1uc+LECcbjMcPhkFKpRC6XQ0vTlDAMieOYQqGA4zhcu3YNwzDQdR3DMA4/ahpCCPL5fEbC\nvXv3WFlZ4c+fP7TbbZaWlpBRFGXjpmnK/Pw8QRAwnU6RUqJpGp7nMRqNcF0XwzCQUqKUolwus7y8\njO/7lMtlFhcX0YQQeJ6XMXfq1Cn29/epVCrouk4QBNi2TalUIoqizLg0TQEYjUbU63VmZmYOsdE0\nDd/3s5HH4zG6rtNsNrEsi0qlQqFQYH19nVevXjEej/8Tm0wmlMtlhBAMBgOkaZo0Gg329vbY2dkh\nCIJsZ0oplFK8efOGp0+fcvHiRfL5PAAHBweEYcj8/HxGydevX5FxHDMajajVanz69Ik4jkmSBF3X\n0TSNzc1N7t69S6vV4vXr10gp8X2f4XBIpVLJghDHMRsbG2jT6TRLxuLiIr1eDwBN09A0jYcPHyKE\n4OjRo8RxTBRF9Pt95ubmMud93+f79+80m03k/v4+UspDKDWNRqPBu3fvSNOUtbU16vU6ly5dwnEc\ncrkcrutimib5fD4zxzRNVldXWVpaQqysrKSdTofLly8zmUwoFAoIIfjXuW3bnD17NkuJlBLHcdA0\nDYAgCHj27BmO47C6uopM05RyucyLFy/QNA3XdRFCYBgGQRCwubnJhw8fGAwGANRqNTRNI0kSXr58\nyc2bN6nX64RhyP379xFPnjxJlVJIKTl37hydTocoiuh0OszOzmJZFv1+n8FgwJ07d7hy5Qrj8ZiP\nHz/S7/c5ffo0CwsL9Ho9ZmZmEI8ePUoNwyBJEs6cOcPCwgLfvn3j/fv35PN5bNtGKZUdjp8/f3Lr\n1q3svLVaLTzPI4oiLMviL7opJdyaltNwAAAAAElFTkSuQmCC", - parameters => [] + icon => + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI\nWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wYDFB0m9797jwAAAB1pVFh0Q29tbWVudAAAAAAAQ3Jl\nYXRlZCB3aXRoIEdJTVBkLmUHAAAEbklEQVQ4y1WUPW/TUBSGn3uvHdv5cBqSOrQJgQ4ghqhCAgQM\nIIRAjF2Y2JhA/Q0g8R9YmJAqNoZKTAwMSAwdQEQUypeQEBEkTdtUbdzYiW1sM1RY4m5Hunp1znmf\n94jnz5+nAGmakiQJu7u7KKWwbRspJWma0m63+fHjB9PpFM/z6Ha7FAoFDMNga2uLx48fkyQJ29vb\nyCRJSNMUz/PY2dnBtm0qlQpKKZIkIQgCer0eW1tbDIdDJpMJc3NzuK5Lt9tF13WWl5dJkoRyuYyU\nUrK3t0ccx9TrdQzD4F/HSilM08Q0TWzbplqtUqvVKBaLKKVoNpt8/vyZKIq4fv064/EY2ev1KBQK\n2LadCQkhEEJkteu6+L6P7/tMJhOm0ylKKarVKjdu3GA6nXL+/HmSJEHWajV0Xf9P7N8TQhDHMWEY\nIoRgOBzieR4At2/f5uTJk0RRRLFYZHZ2liNHjqBFUcRoNKJarSKlRAiRmfPr1y/SNMVxHI4dO8aF\nCxfI5/O4rotSirdv33L16lV+//7Nly9fUEqh5XI5dF0nTdPMaSEEtm3TaDSwLAvLstB1nd3dXUql\nEqZpYlkW6+vrdLtdHjx4wPb2NmEYHgpalkUQBBwcHLC2tsbx48cpFos4jkMQBIRhyGQyYTgcsrGx\nQavVot1uc+LECcbjMcPhkFKpRC6XQ0vTlDAMieOYQqGA4zhcu3YNwzDQdR3DMA4/ahpCCPL5fEbC\nvXv3WFlZ4c+fP7TbbZaWlpBRFGXjpmnK/Pw8QRAwnU6RUqJpGp7nMRqNcF0XwzCQUqKUolwus7y8\njO/7lMtlFhcX0YQQeJ6XMXfq1Cn29/epVCrouk4QBNi2TalUIoqizLg0TQEYjUbU63VmZmYOsdE0\nDd/3s5HH4zG6rtNsNrEsi0qlQqFQYH19nVevXjEej/8Tm0wmlMtlhBAMBgOkaZo0Gg329vbY2dkh\nCIJsZ0oplFK8efOGp0+fcvHiRfL5PAAHBweEYcj8/HxGydevX5FxHDMajajVanz69Ik4jkmSBF3X\n0TSNzc1N7t69S6vV4vXr10gp8X2f4XBIpVLJghDHMRsbG2jT6TRLxuLiIr1eDwBN09A0jYcPHyKE\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 $lrr_info = shift; # Global info hash my $logger = get_logger( "Hdoujin", "plugins" ); my $file = $lrr_info->{file_path}; @@ -68,8 +70,7 @@ sub get_tags { $logger->info("Sending the following tags to LRR: $tags"); return ( tags => $tags ); - } - elsif ( is_file_in_archive( $file, "info.txt" ) ) { + } elsif ( is_file_in_archive( $file, "info.txt" ) ) { # Extract info.txt my $filepath = extract_file_from_archive( $file, "info.txt" ); @@ -78,11 +79,11 @@ sub get_tags { open( my $fh, '<:encoding(UTF-8)', $filepath ) or return ( error => "Could not open $filepath!" ); - while( my $line = <$fh>) { + while ( my $line = <$fh> ) { # Check if the line starts with TAGS: - if ($line =~ m/TAGS: (.*)/) { - return ( tags => $1); + if ( $line =~ m/TAGS: (.*)/ ) { + return ( tags => $1 ); } } return ( error => "No tags were found in info.txt!" ); @@ -97,54 +98,51 @@ sub get_tags { #Goes through the JSON hash obtained from an info.json file and return the contained tags. sub tags_from_Hdoujin_json { - my $hash = $_[0]; - my $return = ""; + my $hash = $_[0]; + my $return = ""; + + #HDoujin jsons are composed of a main manga_info object, containing fields for every metadata. + #Those fields can contain either a single tag or an array of tags. -#HDoujin jsons are composed of a main manga_info object, containing fields for every metadata. -#Those fields can contain either a single tag or an array of tags. - - my $tags = $hash->{"manga_info"}; + my $tags = $hash->{"manga_info"}; - #Take every key in the manga_info hash, except for title which we're already processing - - my @filtered_keys = grep { $_ ne "tags" and $_ ne "title" } keys(%$tags); + #Take every key in the manga_info hash, except for title which we're already processing - foreach my $namespace ( @filtered_keys ) { + my @filtered_keys = grep { $_ ne "tags" and $_ ne "title" } keys(%$tags); + + foreach my $namespace (@filtered_keys) { my $members = $tags->{$namespace}; - - if(ref($members) eq 'ARRAY'){ - - - foreach my $tag (@$members){ - - $return .= ", " unless $return eq ""; - $return .= $namespace . ":" . $tag unless $members eq ""; - - } - - } - else { - - $return .= ", " unless $return eq ""; - $return .= $namespace . ":" . $members unless $members eq ""; - - } - - } - - my $tagsobj = $hash->{"manga_info"}->{"tags"}; - - if (ref($tagsobj) eq 'HASH'){ - - return $return . "," . tags_from_wRespect($hash); - - } - else { - - return $return . "," . tags_from_noRespect($hash); - - } + + if ( ref($members) eq 'ARRAY' ) { + + foreach my $tag (@$members) { + + $return .= ", " unless $return eq ""; + $return .= $namespace . ":" . $tag unless $members eq ""; + + } + + } else { + + $return .= ", " unless $return eq ""; + $return .= $namespace . ":" . $members unless $members eq ""; + + } + + } + + my $tagsobj = $hash->{"manga_info"}->{"tags"}; + + if ( ref($tagsobj) eq 'HASH' ) { + + return $return . "," . tags_from_wRespect($hash); + + } else { + + return $return . "," . tags_from_noRespect($hash); + + } } @@ -152,14 +150,13 @@ sub tags_from_wRespect { my $hash = $_[0]; my $return = ""; - my $tags = $hash->{"manga_info"}->{"tags"}; + my $tags = $hash->{"manga_info"}->{"tags"}; foreach my $namespace ( keys(%$tags) ) { my $members = $tags->{$namespace}; foreach my $tag (@$members) { - $return .= ", " unless $return eq ""; $return .= $namespace . ":" . $tag; @@ -174,27 +171,26 @@ sub tags_from_noRespect { my $hash = $_[0]; my $return = ""; - my $tags = $hash->{"manga_info"}; - - my @filtered_keys = grep { /^tags/ } keys(%$tags); - - foreach my $namespace ( @filtered_keys ) { - - my $members = $tags->{$namespace}; - - if(ref($members) eq 'ARRAY'){ - - - foreach my $tag (@$members){ - - $return .= ", " unless $return eq ""; - $return .= $namespace . ":" . $tag; - - } - - } - - } + my $tags = $hash->{"manga_info"}; + + my @filtered_keys = grep { /^tags/ } keys(%$tags); + + foreach my $namespace (@filtered_keys) { + + my $members = $tags->{$namespace}; + + if ( ref($members) eq 'ARRAY' ) { + + foreach my $tag (@$members) { + + $return .= ", " unless $return eq ""; + $return .= $namespace . ":" . $tag; + + } + + } + + } return $return; diff --git a/lib/LANraragi/Plugin/Metadata/Koromo.pm b/lib/LANraragi/Plugin/Metadata/Koromo.pm index 29c828b7e..cba9711d8 100644 --- a/lib/LANraragi/Plugin/Metadata/Koromo.pm +++ b/lib/LANraragi/Plugin/Metadata/Koromo.pm @@ -23,8 +23,9 @@ sub plugin_info { author => "CirnoT", version => "1.1", description => "Collects metadata embedded into your archives by the Koromo Copy downloader. (Info.json files)", - icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpVoqDmYQcchQnSyIijhKFYtgobQVWnUweekfNDEkKS6OgmvBwZ/FqoOLs64OroIg+APi4uqk6CIl3pcUWsR44fE+zrvn8N59gNCoMs3qGgc03TbTibiUy69IoVeE0QsRAYgys4xkZiEL3/q6pz6quxjP8u/7s/rUgsWAgEQ8ywzTJl4nnt60Dc77xCIryyrxOfGYSRckfuS64vEb55LLAs8UzWx6jlgklkodrHQwK5sa8RRxVNV0yhdyHquctzhr1Rpr3ZO/MFLQlzNcpzWMBBaRRAoSFNRQQRU2YrTrpFhI03ncxz/k+lPkUshVASPHPDagQXb94H/we7ZWcXLCS4rEge4Xx/kYAUK7QLPuON/HjtM8AYLPwJXe9m80gJlP0uttLXoE9G8DF9dtTdkDLneAwSdDNmVXCtISikXg/Yy+KQ8M3ALhVW9urXOcPgBZmtXSDXBwCIyWKHvN5909nXP7t6c1vx8dzXKFeWpUawAAAAZiS0dEAOwAEABqpSa6lwAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+MKCRQBJSKMeg0AAAGVSURBVDjLpZMxa9tQFIXPeaiyhxiZzKFjBme1JFfYgYAe9Bd0yA8JIaQhkJLBP6T/wh3qpZYzm2I8dyilJJMTW7yTIVGRFasE8uAt93K+d+5991IS8Ybj1SVIer24ty8Jk2wyl5S/GkDSi+O4s9PaOYOQh91wSHK2DeLViVut1pmkTwAQtAPUQcz/xCRBEpKOg3ZwEnbDDklvK6AQ+77fds4tSJbBcM7Nm83GbhXiVcXj8fiHpO/WWgfgHAAkXYxGoy8k/UG/nzxDnsqRxF7cO0iS5AhAQxKLm6bpVZqmn8sxAI3kQ2KjKDqQ9GRFEqDNfpQcukrMkDRF3ADAJJvM1+v1n0G/n5D0AcBaew3gFMCFtfbyuVT/cHCYrFarX1mWLQCgsAWSXtgNO81mY/ed7380xpyUn3XOXefr/Ntyufw9vZn+LL7zn21J+fRmOru/f/hrjNmThFLOGWPeV8UvBklSTnIWdsNh0A4g6RiAI/n17vZuWBVvncQNSBAYEK5OvNGDbSMdRdE+AJdl2aJumfjWdX4EIwDvDt7UjSEAAAAASUVORK5CYII=", - parameters => [] + icon => + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpVoqDmYQcchQnSyIijhKFYtgobQVWnUweekfNDEkKS6OgmvBwZ/FqoOLs64OroIg+APi4uqk6CIl3pcUWsR44fE+zrvn8N59gNCoMs3qGgc03TbTibiUy69IoVeE0QsRAYgys4xkZiEL3/q6pz6quxjP8u/7s/rUgsWAgEQ8ywzTJl4nnt60Dc77xCIryyrxOfGYSRckfuS64vEb55LLAs8UzWx6jlgklkodrHQwK5sa8RRxVNV0yhdyHquctzhr1Rpr3ZO/MFLQlzNcpzWMBBaRRAoSFNRQQRU2YrTrpFhI03ncxz/k+lPkUshVASPHPDagQXb94H/we7ZWcXLCS4rEge4Xx/kYAUK7QLPuON/HjtM8AYLPwJXe9m80gJlP0uttLXoE9G8DF9dtTdkDLneAwSdDNmVXCtISikXg/Yy+KQ8M3ALhVW9urXOcPgBZmtXSDXBwCIyWKHvN5909nXP7t6c1vx8dzXKFeWpUawAAAAZiS0dEAOwAEABqpSa6lwAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+MKCRQBJSKMeg0AAAGVSURBVDjLpZMxa9tQFIXPeaiyhxiZzKFjBme1JFfYgYAe9Bd0yA8JIaQhkJLBP6T/wh3qpZYzm2I8dyilJJMTW7yTIVGRFasE8uAt93K+d+5991IS8Ybj1SVIer24ty8Jk2wyl5S/GkDSi+O4s9PaOYOQh91wSHK2DeLViVut1pmkTwAQtAPUQcz/xCRBEpKOg3ZwEnbDDklvK6AQ+77fds4tSJbBcM7Nm83GbhXiVcXj8fiHpO/WWgfgHAAkXYxGoy8k/UG/nzxDnsqRxF7cO0iS5AhAQxKLm6bpVZqmn8sxAI3kQ2KjKDqQ9GRFEqDNfpQcukrMkDRF3ADAJJvM1+v1n0G/n5D0AcBaew3gFMCFtfbyuVT/cHCYrFarX1mWLQCgsAWSXtgNO81mY/ed7380xpyUn3XOXefr/Ntyufw9vZn+LL7zn21J+fRmOru/f/hrjNmThFLOGWPeV8UvBklSTnIWdsNh0A4g6RiAI/n17vZuWBVvncQNSBAYEK5OvNGDbSMdRdE+AJdl2aJumfjWdX4EIwDvDt7UjSEAAAAASUVORK5CYII=", + parameters => [] ); } @@ -33,7 +34,7 @@ sub plugin_info { sub get_tags { shift; - my $lrr_info = shift; # Global info hash + my $lrr_info = shift; # Global info hash my $logger = get_logger( "koromo", "plugins" ); my $file = $lrr_info->{file_path}; @@ -69,8 +70,7 @@ sub get_tags { $logger->info("Sending the following tags to LRR: $tags"); return ( tags => $tags ); - } - else { + } else { return ( error => "No koromo info.json file found in this archive!" ); } @@ -84,50 +84,50 @@ sub tags_from_koromo_json { my $hash = $_[0]; my $return = ""; - my $tags = $hash->{"Tags"}; + my $tags = $hash->{"Tags"}; my $characters = $hash->{"Characters"}; - my $series = $hash->{"Series"}; - my $groups = $hash->{"Groups"}; - my $artists = $hash->{"Artists"}; - my $type = $hash->{"Types"}; + my $series = $hash->{"Series"}; + my $groups = $hash->{"Groups"}; + my $artists = $hash->{"Artists"}; + my $type = $hash->{"Types"}; - foreach my $tag ( @$tags ) { + foreach my $tag (@$tags) { $return .= ", " unless $return eq ""; $return .= $tag; } - foreach my $tag ( @$characters ) { + foreach my $tag (@$characters) { $return .= ", " unless $return eq ""; $return .= "character:" . $tag; - + } - foreach my $tag ( @$series ) { + foreach my $tag (@$series) { $return .= ", " unless $return eq ""; $return .= "series:" . $tag; - + } - foreach my $tag ( @$groups ) { + foreach my $tag (@$groups) { $return .= ", " unless $return eq ""; $return .= "group:" . $tag; - + } - foreach my $tag ( @$artists ) { + foreach my $tag (@$artists) { $return .= ", " unless $return eq ""; $return .= "artist:" . $tag; - + } $return .= ", " unless $return eq ""; - $return .= ("category:" . $type) unless !$type; + $return .= ( "category:" . $type ) unless !$type; #Done-o return $return; diff --git a/lib/LANraragi/Plugin/Metadata/nHentai.pm b/lib/LANraragi/Plugin/Metadata/nHentai.pm index 324ea74df..517f1f146 100644 --- a/lib/LANraragi/Plugin/Metadata/nHentai.pm +++ b/lib/LANraragi/Plugin/Metadata/nHentai.pm @@ -25,10 +25,9 @@ sub plugin_info { author => "Difegue", version => "1.6", description => "Searches nHentai for tags matching your archive.", - 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 => [ - {type => "bool", desc => "Save archive title"} - ], + 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 => [ { type => "bool", desc => "Save archive title" } ], oneshot_arg => "nHentai Gallery URL (Will attach tags matching this exact gallery to your archive)" ); @@ -38,8 +37,8 @@ sub plugin_info { sub get_tags { shift; - my $lrr_info = shift; # Global info hash - my ($savetitle) = @_; # Plugin parameters + my $lrr_info = shift; # Global info hash + my ($savetitle) = @_; # Plugin parameters my $logger = get_logger( "nHentai", "plugins" ); @@ -49,17 +48,16 @@ sub get_tags { # Quick regex to get the nh gallery id from the provided url. if ( $lrr_info->{oneshot_param} =~ /.*\/g\/([0-9]*)\/.*/ ) { $galleryID = $1; - } - else { + } else { + #Get Gallery ID by hand if the user didn't specify a URL - $galleryID = get_gallery_id_from_title($lrr_info->{archive_title}); + $galleryID = get_gallery_id_from_title( $lrr_info->{archive_title} ); } # Did we detect a nHentai gallery? if ( defined $galleryID ) { $logger->debug("Detected nHentai gallery id is $galleryID"); - } - else { + } else { $logger->info("No matching nHentai Gallery Found!"); return ( error => "No matching nHentai Gallery Found!" ); } @@ -71,12 +69,11 @@ sub get_tags { return ( error => "No matching nHentai Gallery Found!" ); } - my ($newtags, $newtitle) = &get_tags_from_NH($galleryID); + my ( $newtags, $newtitle ) = &get_tags_from_NH($galleryID); #Return a hash containing the new metadata - it will be integrated in LRR. - if ($savetitle && $newtags ne "") - { return ( tags => $newtags, title => $newtitle ); } - else { return ( tags => $newtags ); } + if ( $savetitle && $newtags ne "" ) { return ( tags => $newtags, title => $newtitle ); } + else { return ( tags => $newtags ); } } ###### @@ -87,14 +84,13 @@ sub get_tags { #Uses the website's search to find a gallery and returns its gallery ID. sub get_gallery_id_from_title { - my $title = $_[0]; + my $title = $_[0]; my $logger = get_logger( "nHentai", "plugins" ); #Strip away hyphens and apostrophes as they apparently break search $title =~ s/-|'/ /g; - my $URL = - "https://nhentai.net/search/?q=" . uri_escape_utf8($title); + my $URL = "https://nhentai.net/search/?q=" . uri_escape_utf8($title); $logger->debug("Using URL $URL to search on nH."); my $ua = Mojo::UserAgent->new; @@ -105,7 +101,7 @@ sub get_gallery_id_from_title { my $dom = Mojo::DOM->new( $res->body ); # Get the first gallery url of the search results - my $gURL = ($dom->at('.cover')) ? $dom->at('.cover')->attr('href'): ""; + my $gURL = ( $dom->at('.cover') ) ? $dom->at('.cover')->attr('href') : ""; my $gallery = ""; if ( $gURL =~ /\/g\/(\d*)\//gm ) { @@ -159,7 +155,7 @@ sub get_tags_from_NH { $logger->info("Sending the following tags to LRR: $returned"); # Use NH's "pretty" names (romaji titles without extraneous data we already have like (Event)[Artist], etc) - return ($returned, $json->{"title"}->{"pretty"}); + return ( $returned, $json->{"title"}->{"pretty"} ); } diff --git a/lib/LANraragi/Plugin/Scripts/SourceFinder.pm b/lib/LANraragi/Plugin/Scripts/SourceFinder.pm index 814d7761f..6c62eb92a 100644 --- a/lib/LANraragi/Plugin/Scripts/SourceFinder.pm +++ b/lib/LANraragi/Plugin/Scripts/SourceFinder.pm @@ -19,7 +19,8 @@ sub plugin_info { author => "Difegue", version => "1.0", description => "Looks in the database if an archive has a 'source:' tag matching the given URL.", - icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABZSURBVDhPzY5JCgAhDATzSl+e/2irOUjQSFzQog5hhqIl3uBEHPxIXK7oFXwVE+Hj5IYX4lYVtN6MUW4tGw5jNdjdt5bLkwX1q2rFU0/EIJ9OUEm8xquYOQFEhr9vvu2U8gAAAABJRU5ErkJggg==", + icon => + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABZSURBVDhPzY5JCgAhDATzSl+e/2irOUjQSFzQog5hhqIl3uBEHPxIXK7oFXwVE+Hj5IYX4lYVtN6MUW4tGw5jNdjdt5bLkwX1q2rFU0/EIJ9OUEm8xquYOQFEhr9vvu2U8gAAAABJRU5ErkJggg==", oneshot_arg => "URL to search." ); @@ -28,32 +29,31 @@ sub plugin_info { # Mandatory function to be implemented by your script sub run_script { shift; - my $lrr_info = shift; # Global info hash + my $lrr_info = shift; # Global info hash my $logger = get_logger( "Source Finder", "plugins" ); # Only info we need is the URL to search my $url = $lrr_info->{oneshot_param}; - $logger->debug("Looking for URL " . $url ); + $logger->debug( "Looking for URL " . $url ); - if ($url eq "") { - return ( error => "No URL specified!", total => 0 ); + if ( $url eq "" ) { + return ( error => "No URL specified!", total => 0 ); } # Use the search engine to find archives with the source: tag. - my ($total, $filtered, @ids) = - LANraragi::Model::Search::do_search("source:".$url, "", 0, "title", "asc",0,0); + my ( $total, $filtered, @ids ) = LANraragi::Model::Search::do_search( "source:" . $url, "", 0, "title", "asc", 0, 0 ); - if ($filtered == 0) { - return ( error => "URL not found in database.", total => 0 ); + if ( $filtered == 0 ) { + return ( error => "URL not found in database.", total => 0 ); } # Since this script is rather dumb, it'll just return the total found IDs that have this source. return ( - total => $filtered, + total => $filtered, partial_ids => \@ids ); - + } -1; \ No newline at end of file +1; diff --git a/lib/LANraragi/Utils/Archive.pm b/lib/LANraragi/Utils/Archive.pm index ab34e6b7f..3272f2ad0 100644 --- a/lib/LANraragi/Utils/Archive.pm +++ b/lib/LANraragi/Utils/Archive.pm @@ -24,8 +24,8 @@ use LANraragi::Utils::Generic qw(is_image shasum); # Utilitary functions for handling Archives. # Relies on Libarchive and ImageMagick. -use Exporter 'import'; -our @EXPORT_OK = qw(is_file_in_archive extract_file_from_archive extract_archive extract_thumbnail generate_thumbnail); +use Exporter 'import'; +our @EXPORT_OK = qw(is_file_in_archive extract_file_from_archive extract_archive extract_thumbnail generate_thumbnail); # generate_thumbnail(original_image, thumbnail_location) # use ImageMagick to make a thumbnail, height = 500px (view in index is 280px tall) @@ -50,33 +50,37 @@ sub extract_archive { #Extract to $path. Report if it fails. my $ok = $ae->extract( to => $path ) or die $ae->error; - + #Rename files and folders to an encoded version my $cwd = getcwd(); - finddepth(sub { - unless ($_ eq '.') { - - my $filename = $_; - eval { - # Try a guess to regular japanese encodings first - $filename = decode ("Guess", $filename); - }; - # Fallback to utf8 - $filename = decode_utf8($filename) if $@; - - # Re-encode the result to ASCII and move the file to said result name. - # Use Encode's coderef feature to map non-ascii characters to their Unicode codepoint equivalent. - $filename = encode("ascii", $filename, sub{ sprintf "%04X", shift }); - - if (length $filename > 254) { - $filename = substr( $filename, 0, 254 ); + finddepth( + sub { + unless ( $_ eq '.' ) { + + my $filename = $_; + eval { + # Try a guess to regular japanese encodings first + $filename = decode( "Guess", $filename ); + }; + + # Fallback to utf8 + $filename = decode_utf8($filename) if $@; + + # Re-encode the result to ASCII and move the file to said result name. + # Use Encode's coderef feature to map non-ascii characters to their Unicode codepoint equivalent. + $filename = encode( "ascii", $filename, sub { sprintf "%04X", shift } ); + + if ( length $filename > 254 ) { + $filename = substr( $filename, 0, 254 ); + } + + move( $_, $filename ); } + }, + $ae->extract_path + ); - move($_, $filename); - } - }, $ae->extract_path); - # chdir back to the base cwd in case finddepth died midway chdir $cwd; @@ -95,14 +99,14 @@ sub extract_thumbnail { mkdir $dirname . "/thumb"; my $redis = LANraragi::Model::Config->get_redis; - my $file = $redis->hget( $id, "file" ); + my $file = $redis->hget( $id, "file" ); my $temppath = get_temp . "/thumb"; # Make sure the thumb temp dir exists mkdir $temppath; # Get all the files of the archive - my $peek = Archive::Peek::Libarchive->new( filename => $file ); + my $peek = Archive::Peek::Libarchive->new( filename => $file ); my @files = $peek->files(); my @extracted; @@ -143,8 +147,9 @@ sub extract_thumbnail { #Delete the previously extracted file. unlink $arcimg; + # Clean up safe foder - remove_tree( $temppath . "/$id"); + remove_tree( $temppath . "/$id" ); return $thumbname; } @@ -159,12 +164,12 @@ sub is_file_in_archive { $logger->debug("Iterating files of archive $archive, looking for '$wantedname'"); $Data::Dumper::Useqq = 1; - my $peek = Archive::Peek::Libarchive->new( filename => $archive ); + my $peek = Archive::Peek::Libarchive->new( filename => $archive ); my $found = 0; $peek->iterate( sub { my $name = $_[0]; - $logger->debug("Found file " . Dumper($name)); + $logger->debug( "Found file " . Dumper($name) ); if ( $name =~ /$wantedname$/ ) { $found = 1; @@ -183,14 +188,14 @@ sub extract_file_from_archive { my ( $archive, $filename ) = @_; - #Timestamp extractions in microseconds + #Timestamp extractions in microseconds my ( $seconds, $microseconds ) = gettimeofday; my $stamp = "$seconds-$microseconds"; my $path = get_temp . "/plugin/$stamp"; mkdir get_temp . "/plugin"; mkdir $path; - my $peek = Archive::Peek::Libarchive->new( filename => $archive ); + my $peek = Archive::Peek::Libarchive->new( filename => $archive ); my $contents = ""; $peek->iterate( sub { diff --git a/lib/LANraragi/Utils/Database.pm b/lib/LANraragi/Utils/Database.pm index 7f6589df9..a722659db 100644 --- a/lib/LANraragi/Utils/Database.pm +++ b/lib/LANraragi/Utils/Database.pm @@ -15,8 +15,8 @@ use LANraragi::Model::Plugins; use LANraragi::Utils::Logging qw(get_logger); # Functions for interacting with the DB Model. -use Exporter 'import'; -our @EXPORT_OK = qw(redis_decode invalidate_cache); +use Exporter 'import'; +our @EXPORT_OK = qw(redis_decode invalidate_cache); #add_archive_to_redis($id,$file,$redis) #Parses the name of a file for metadata, and matches that metadata to the SHA-1 hash of the file in our Redis database. @@ -72,8 +72,7 @@ sub build_archive_JSON { #It's not a new archive, but it might have never been clicked on yet, #so we'll grab the value for $isnew stored in redis. - my ( $name, $title, $tags, $file, $isnew ) = - @hash{qw(name title tags file isnew)}; + my ( $name, $title, $tags, $file, $isnew ) = @hash{qw(name title tags file isnew)}; #Parameters have been obtained, let's decode them. ( $_ = redis_decode($_) ) for ( $name, $title, $tags ); @@ -84,10 +83,10 @@ sub build_archive_JSON { } my $arcdata = { - arcid => $id, - title => $title, - tags => $tags, - isnew => $isnew + arcid => $id, + title => $title, + tags => $tags, + isnew => $isnew }; return $arcdata; @@ -96,8 +95,8 @@ sub build_archive_JSON { #Deletes the archive with the given id from redis, and the matching archive file. sub delete_archive { - my $id = $_[0]; - my $redis = LANraragi::Model::Config->get_redis; + my $id = $_[0]; + my $redis = LANraragi::Model::Config->get_redis; my $filename = $redis->hget( $id, "file" ); $redis->del($id); @@ -124,9 +123,9 @@ sub drop_database { # Remove entries from the database that don't have a matching archive on the filesystem. # Returns the number of entries deleted. sub clean_database { - my $redis = LANraragi::Model::Config->get_redis; + my $redis = LANraragi::Model::Config->get_redis; my $logger = get_logger( "Archive", "lanraragi" ); - + # Get the filemap from Shinobu for ID checks later down the line my %filemap = LANraragi::Utils::Generic::get_shinobu_filemap(); @@ -136,18 +135,18 @@ sub clean_database { my $deleted_arcs = 0; foreach my $id (@keys) { - my $file = $redis->hget($id, "file"); + my $file = $redis->hget( $id, "file" ); - unless (-e $file) { + unless ( -e $file ) { $redis->del($id); $deleted_arcs++; next; - } - - unless ($file eq "" || %filemap == 0 || exists $filemap{$id}) { + } + + unless ( $file eq "" || %filemap == 0 || exists $filemap{$id} ) { $logger->warn("File exists but its ID is no longer $id -- Removing file reference in its database entry."); - $redis->hset($id, "file", ""); - } + $redis->hset( $id, "file", "" ); + } } $redis->quit; @@ -160,7 +159,7 @@ sub add_tags { my ( $id, $newtags ) = @_; - my $redis = LANraragi::Model::Config->get_redis; + my $redis = LANraragi::Model::Config->get_redis; my $oldtags = $redis->hget( $id, "tags" ); $oldtags = redis_decode($oldtags); @@ -214,14 +213,13 @@ sub parse_name { if ( $artist ne "" ) { - #Special case for circle/artist sets: - #If the string contains parenthesis, what's inside those is the artist name - #the rest is the circle. + #Special case for circle/artist sets: + #If the string contains parenthesis, what's inside those is the artist name + #the rest is the circle. if ( $artist =~ /(.*) \((.*)\)/ ) { push @tags, "group:$1"; push @tags, "artist:$2"; - } - else { + } else { push @tags, "artist:$artist"; } } @@ -256,7 +254,7 @@ sub compute_id { $ctx->add($data); my $digest = $ctx->hexdigest; - if( $digest eq "da39a3ee5e6b4b0d3255bfef95601890afd80709" ) { + if ( $digest eq "da39a3ee5e6b4b0d3255bfef95601890afd80709" ) { die "Computed ID is for a null value, invalid source file."; } @@ -293,12 +291,12 @@ sub invalidate_isnew_cache { my $redis = LANraragi::Model::Config->get_redis; my %cache = $redis->hgetall("LRR_SEARCHCACHE"); - foreach my $cachekey (keys( %cache )) { - + foreach my $cachekey ( keys(%cache) ) { + # A cached search uses isNew if the second to last number is equal to 1 - # i.e, "--title-asc-1-0" has to be pruned - if ($cachekey =~ /.*-.*-.*-.*-1-\d?/) { - $redis->hdel("LRR_SEARCHCACHE", $cachekey); + # i.e, "--title-asc-1-0" has to be pruned + if ( $cachekey =~ /.*-.*-.*-.*-1-\d?/ ) { + $redis->hdel( "LRR_SEARCHCACHE", $cachekey ); } } $redis->quit(); diff --git a/lib/LANraragi/Utils/Generic.pm b/lib/LANraragi/Utils/Generic.pm index ac79e1b16..1434ae4f1 100644 --- a/lib/LANraragi/Utils/Generic.pm +++ b/lib/LANraragi/Utils/Generic.pm @@ -15,9 +15,9 @@ use Proc::Simple; use LANraragi::Utils::Logging qw(get_logger); # Generic Utility Functions. -use Exporter 'import'; -our @EXPORT_OK = qw(remove_spaces remove_newlines is_image get_tag_with_namespace shasum start_shinobu - get_css_list generate_themes_header generate_themes_selector); +use Exporter 'import'; +our @EXPORT_OK = qw(remove_spaces remove_newlines is_image get_tag_with_namespace shasum start_shinobu + get_css_list generate_themes_header generate_themes_selector); # Remove spaces before and after a word sub remove_spaces { @@ -37,15 +37,15 @@ sub is_image { # Find the first tag matching the given namespace, or return the default value. sub get_tag_with_namespace { - my ($namespace, $tags, $default) = @_; - my @values = split(',', $tags); + my ( $namespace, $tags, $default ) = @_; + my @values = split( ',', $tags ); foreach my $tag (@values) { - my ($namecheck, $value) = split(':', $tag); + my ( $namecheck, $value ) = split( ':', $tag ); remove_spaces($namecheck); remove_spaces($value); - if ($namecheck eq $namespace) { + if ( $namecheck eq $namespace ) { return $value; } } @@ -57,8 +57,8 @@ sub get_tag_with_namespace { sub start_shinobu { my $logger = get_logger( "Shinobu Boot", "lanraragi" ); - my $proc = Proc::Simple->new(); - $proc->start($^X, "./lib/Shinobu.pm"); + my $proc = Proc::Simple->new(); + $proc->start( $^X, "./lib/Shinobu.pm" ); $proc->kill_on_destroy(0); # Freeze the process object in the PID file @@ -68,8 +68,8 @@ sub start_shinobu { # Retrieve the Shinobu filemap, serialized to a file. sub get_shinobu_filemap { - if (-e "./.shinobu-filemap") { - return %{lock_retrieve("./.shinobu-filemap")}; + if ( -e "./.shinobu-filemap" ) { + return %{ lock_retrieve("./.shinobu-filemap") }; } else { return; } @@ -115,13 +115,13 @@ sub get_css_list { sub generate_themes_header { my $self = shift; - my @css = get_css_list; + my @css = get_css_list; #html that we'll insert in the header to declare all the available styles. my $html = ""; #Go through the css files - for ( my $i = 0 ; $i < $#css + 1 ; $i++ ) { + for ( my $i = 0; $i < $#css + 1; $i++ ) { my $css_name = css_default_names( $css[$i] ); @@ -131,18 +131,19 @@ sub generate_themes_header { $html = $html . ' '; - } - else { + . $css[$i] . '?' + . $self->LRR_VERSION . '"> '; + } else { $html = $html . ' '; + . $css[$i] . '?' + . $self->LRR_VERSION . '"> '; } } @@ -152,11 +153,11 @@ sub generate_themes_header { sub generate_themes_selector { - my @css = get_css_list; + my @css = get_css_list; my $CSSsel = '
    '; #Go through the css files - for ( my $i = 0 ; $i < $#css + 1 ; $i++ ) { + for ( my $i = 0; $i < $#css + 1; $i++ ) { #populate the div with buttons my $css_name = css_default_names( $css[$i] ); diff --git a/lib/LANraragi/Utils/Logging.pm b/lib/LANraragi/Utils/Logging.pm index 8160b6189..99647c05d 100644 --- a/lib/LANraragi/Utils/Logging.pm +++ b/lib/LANraragi/Utils/Logging.pm @@ -12,8 +12,8 @@ use Encode; use File::ReadBackwards; # Contains all functions related to logging. -use Exporter 'import'; -our @EXPORT_OK = qw(get_logger get_logdir get_lines_from_file); +use Exporter 'import'; +our @EXPORT_OK = qw(get_logger get_logdir get_lines_from_file); # Get the Log folder. sub get_logdir { @@ -21,7 +21,7 @@ sub get_logdir { my $log_folder = "$FindBin::Bin/../log"; # Folder location can be overriden by LRR_LOG_DIRECTORY - if ($ENV{LRR_LOG_DIRECTORY}) { + if ( $ENV{LRR_LOG_DIRECTORY} ) { $log_folder = $ENV{LRR_LOG_DIRECTORY}; } mkdir $log_folder; @@ -37,14 +37,17 @@ sub get_logger { my $logpath = get_logdir . "/$logfile.log"; - if (-e $logpath && -s $logpath > 1048576) { + if ( -e $logpath && -s $logpath > 1048576 ) { + # Rotate log if it's > 1MB say "Rotating logfile $logfile"; - new Logfile::Rotate(File => $logpath, Gzip => 'lib')->rotate(); + new Logfile::Rotate( File => $logpath, Gzip => 'lib' )->rotate(); } - my $log = Mojo::Log->new( path => $logpath, - level => 'info' ); + my $log = Mojo::Log->new( + path => $logpath, + level => 'info' + ); my $devmode = LANraragi::Model::Config->enable_devmode; @@ -58,8 +61,8 @@ sub get_logger { message => sub { my ( $time, $level, @lines ) = @_; - unless ( $devmode == 0 && $level eq 'debug' ) - { #Like with logging to file, debug logs are only printed in debug mode + #Like with logging to file, debug logs are only printed in debug mode + unless ( $devmode == 0 && $level eq 'debug' ) { print "[$pgname] [$level] "; say $lines[0]; } @@ -86,7 +89,7 @@ sub get_lines_from_file { if ( -e $file ) { my $bw = File::ReadBackwards->new($file); my $res = ""; - for ( my $i = 0 ; $i <= $lines ; $i++ ) { + for ( my $i = 0; $i <= $lines; $i++ ) { my $line = $bw->readline(); if ($line) { $res = $line . $res; @@ -101,4 +104,4 @@ sub get_lines_from_file { } -1; \ No newline at end of file +1; diff --git a/lib/LANraragi/Utils/Plugins.pm b/lib/LANraragi/Utils/Plugins.pm index b64b8fb8a..8bc7e982b 100644 --- a/lib/LANraragi/Utils/Plugins.pm +++ b/lib/LANraragi/Utils/Plugins.pm @@ -13,8 +13,8 @@ use Module::Pluggable require => 1, search_path => ['LANraragi::Plugin']; # Functions related to the Plugin system. # This mostly contains the glue for parameters w/ Redis, the meat of Plugin execution is in Model::Plugins. -use Exporter 'import'; -our @EXPORT_OK = qw(get_plugins get_plugin get_enabled_plugins get_plugin_parameters is_plugin_enabled); +use Exporter 'import'; +our @EXPORT_OK = qw(get_plugins get_plugin get_enabled_plugins get_plugin_parameters is_plugin_enabled); # Get metadata of all plugins with the defined type. Returns an array of hashes. sub get_plugins { @@ -23,11 +23,12 @@ sub get_plugins { my @plugins = plugins; my @validplugins; foreach my $plugin (@plugins) { + # Check that the metadata sub is there before invoking it - if ($plugin->can('plugin_info')) { + if ( $plugin->can('plugin_info') ) { my %pluginfo = $plugin->plugin_info(); - if ($pluginfo{type} eq $type || $type eq "all") { push (@validplugins, \%pluginfo);} - }; + if ( $pluginfo{type} eq $type || $type eq "all" ) { push( @validplugins, \%pluginfo ); } + } } return @validplugins; @@ -38,11 +39,11 @@ sub get_enabled_plugins { my $type = shift; my @plugins = get_plugins($type); my @enabled; - + foreach my $pluginfo (@plugins) { - if (is_plugin_enabled($pluginfo->{namespace})) { - push (@enabled, $pluginfo); + if ( is_plugin_enabled( $pluginfo->{namespace} ) ) { + push( @enabled, $pluginfo ); } } return @enabled; @@ -52,13 +53,14 @@ sub get_enabled_plugins { sub get_plugin { my $name = shift; + #Go through plugins to find one with a matching namespace my @plugins = plugins; foreach my $plugin (@plugins) { my $namespace = ""; eval { - my %pluginfo = $plugin->plugin_info(); + my %pluginfo = $plugin->plugin_info(); $namespace = $pluginfo{namespace}; }; @@ -75,10 +77,11 @@ sub get_plugin { sub get_plugin_parameters { my $namespace = shift; + #Get the matching argument JSON in Redis - my $redis = LANraragi::Model::Config->get_redis; - my $namerds = "LRR_PLUGIN_" . uc($namespace); - my @args = (); + my $redis = LANraragi::Model::Config->get_redis; + my $namerds = "LRR_PLUGIN_" . uc($namespace); + my @args = (); if ( $redis->hexists( $namerds, "enabled" ) ) { my $argsjson = $redis->hget( $namerds, "customargs" ); diff --git a/lib/LANraragi/Utils/Routing.pm b/lib/LANraragi/Utils/Routing.pm index 6480d4809..ad55de6fc 100644 --- a/lib/LANraragi/Utils/Routing.pm +++ b/lib/LANraragi/Utils/Routing.pm @@ -28,7 +28,7 @@ sub apply_routes { $logged_in->get('/')->to('index#index'); $logged_in->get('/index')->to('index#index'); $logged_in->get('/search')->to('search#handle_datatables'); - + $logged_in->get('/random')->to('index#random_archive'); $logged_in->get('/reader')->to('reader#index'); $logged_in->get('/stats')->to('stats#index'); @@ -43,8 +43,8 @@ sub apply_routes { $logged_in_api->get('/api/extract')->to('api#extract_archive'); $logged_in_api->get('/api/clear_new')->to('api#clear_new'); $logged_in_api->get('/api/search')->to('search#handle_api'); - } - else { + } else { + #Standard behaviour is to leave those routes loginless for all clients $r->get('/')->to('index#index'); $r->get('/index')->to('index#index'); @@ -85,7 +85,7 @@ sub apply_routes { $logged_in->get('/upload')->to('upload#index'); $logged_in->post('/upload')->to('upload#process_upload'); - # These API endpoints will always require the API Key or to be logged in + # These API endpoints will always require the API Key or to be logged in $logged_in_api->get('/api/use_plugin')->to('api#use_plugin'); $logged_in_api->post('/api/autoplugin')->to('api#use_enabled_plugins'); $logged_in_api->get('/api/clean_temp')->to('api#clean_tempfolder'); diff --git a/lib/LANraragi/Utils/TempFolder.pm b/lib/LANraragi/Utils/TempFolder.pm index 3003a3cfc..e2470934d 100644 --- a/lib/LANraragi/Utils/TempFolder.pm +++ b/lib/LANraragi/Utils/TempFolder.pm @@ -14,16 +14,16 @@ use LANraragi::Utils::Generic; use LANraragi::Utils::Logging qw(get_logger); #Contains all functions related to the temporary folder. -use Exporter 'import'; -our @EXPORT_OK = qw(get_temp get_tempsize clean_temp_full clean_temp_partial); +use Exporter 'import'; +our @EXPORT_OK = qw(get_temp get_tempsize clean_temp_full clean_temp_partial); #Get the current tempfolder. #This can be called from any process safely as it uses FindBin. sub get_temp { my $temp_folder = "$FindBin::Bin/../public/temp"; - + # Folder location can be overriden by LRR_TEMP_DIRECTORY - if ($ENV{LRR_TEMP_DIRECTORY}) { + if ( $ENV{LRR_TEMP_DIRECTORY} ) { $temp_folder = $ENV{LRR_TEMP_DIRECTORY}; } @@ -55,8 +55,7 @@ sub clean_temp_full { my ( $file, $message ) = %$diag; if ( $file eq '' ) { die "General error: $message\n"; - } - else { + } else { die "Problem unlinking $file: $message\n"; } } @@ -79,8 +78,7 @@ sub clean_temp_partial { my $maxsize = LANraragi::Model::Config->get_tempmaxsize; if ( $size > $maxsize ) { - $logger->info( "Current temporary folder size is $size MBs, " - . "Maximum size is $maxsize MBs. Cleaning." ); + $logger->info( "Current temporary folder size is $size MBs, " . "Maximum size is $maxsize MBs. Cleaning." ); #Wipe thumb temp folder first if ( -e $tempdir . "/thumb" ) { unlink( $tempdir . "/thumb" ); } @@ -114,8 +112,7 @@ sub clean_temp_partial { my ( $file, $message ) = %$diag; if ( $file eq '' ) { $logger->error("General error: $message\n"); - } - else { + } else { $logger->error("Problem unlinking $file: $message\n"); } } diff --git a/lib/Shinobu.pm b/lib/Shinobu.pm index a36ed37e6..f077603d3 100644 --- a/lib/Shinobu.pm +++ b/lib/Shinobu.pm @@ -34,9 +34,9 @@ use LANraragi::Utils::Database qw(invalidate_cache); use LANraragi::Utils::TempFolder qw(get_temp clean_temp_partial); use LANraragi::Utils::Logging qw(get_logger); -use LANraragi::Model::Config; +use LANraragi::Model::Config; use LANraragi::Model::Plugins; -use LANraragi::Utils::Plugins; # Needed here since Shinobu doesn't inherit from the main LRR package +use LANraragi::Utils::Plugins; # Needed here since Shinobu doesn't inherit from the main LRR package # Filemap hash, global to all subs and exposed to the server through IPC my %filemap; @@ -53,7 +53,7 @@ my $inotifysub = sub { $logger->debug("Received inotify event $type on $name"); if ( $type eq "create" || $type eq "modify" ) { - new_file_callback( $name ); + new_file_callback($name); } if ( $type eq "delete" ) { @@ -68,26 +68,23 @@ sub initialize_from_new_process { $logger->info("Shinobu Background Worker started."); $logger->info( "Working dir is " . cwd ); - + build_filemap(); $logger->info("Adding watcher to content folder $userdir"); # Add watcher to content directory - my $contentwatcher = - File::ChangeNotify->instantiate_watcher - ( directories => [ $userdir ], - filter => qr/\.(?:zip|rar|7z|tar|tar\.gz|lzma|xz|cbz|cbr)$/, - follow_symlinks => 1, - exclude => [ 'thumb', '.' ], #excluded subdirs - ); + my $contentwatcher = File::ChangeNotify->instantiate_watcher( + directories => [$userdir], + filter => qr/\.(?:zip|rar|7z|tar|tar\.gz|lzma|xz|cbz|cbr)$/, + follow_symlinks => 1, + exclude => [ 'thumb', '.' ], #excluded subdirs + ); my $class = ref($contentwatcher); $logger->debug("Watcher class is $class"); # Add watcher to tempfolder - my $tempwatcher = - File::ChangeNotify->instantiate_watcher - ( directories => [ get_temp() ] ); + my $tempwatcher = File::ChangeNotify->instantiate_watcher( directories => [ get_temp() ] ); # manual event loop $logger->info("All done! Now dutifully watching your files. "); @@ -121,10 +118,9 @@ sub build_filemap { # Get all files in content directory and subdirectories. find( - { - wanted => sub { - return if -d $_; #Directories are excluded on the spot - push @files, $_; #Push files to array + { wanted => sub { + return if -d $_; #Directories are excluded on the spot + push @files, $_; #Push files to array }, no_chdir => 1, follow_fast => 1 @@ -134,7 +130,7 @@ sub build_filemap { # Now that we have all files, process them...with multithreading! my $numCpus = Sys::CpuAffinity::getNumCpus(); - my $pl = Parallel::Loops->new($numCpus); + my $pl = Parallel::Loops->new($numCpus); $pl->share( \%filemap ); $logger->debug("Number of available cores for processing: $numCpus"); @@ -142,23 +138,26 @@ sub build_filemap { # Split the workload equally between all CPUs with an array of arrays my @sections; while (@files) { - foreach (0..$numCpus-1){ + foreach ( 0 .. $numCpus - 1 ) { if (@files) { - push @{$sections[$_]}, shift @files; + push @{ $sections[$_] }, shift @files; } } } - - $pl->foreach( \@sections, sub { - # This sub "magically" executed in parallel forked child - # processes - foreach my $file (@$_) { - add_to_filemap($file); + + $pl->foreach( + \@sections, + sub { + # This sub "magically" executed in parallel forked child + # processes + foreach my $file (@$_) { + add_to_filemap($file); + } } - }); + ); - # Done, serialize filemap for main process to consume - # The filemap hash has been modified into an object by Parallel::Loops... + # Done, serialize filemap for main process to consume + # The filemap hash has been modified into an object by Parallel::Loops... # It's better to make a clean hash copy and serialize that instead. my $copy = {%filemap}; lock_store $copy, '.shinobu-filemap'; @@ -175,7 +174,7 @@ sub add_to_filemap { #Freshly created files might not be complete yet. #We have to wait before doing any form of calculation. while (1) { - last unless -e $file; # Sanity check to avoid sticking in this loop if the file disappears + last unless -e $file; # Sanity check to avoid sticking in this loop if the file disappears last if open( my $handle, '<', $file ); $logger->debug("Waiting for file to be openable"); sleep(1); @@ -184,7 +183,7 @@ sub add_to_filemap { # Wait for file to be more than 512 KBs or bailout after 5s and assume that file is smaller my $cnt = 0; while (1) { - last if (((-s $file) >= 512000) || $cnt >= 5); + last if ( ( ( -s $file ) >= 512000 ) || $cnt >= 5 ); $logger->debug("Waiting for file to be fully written"); sleep(1); $cnt++; @@ -205,24 +204,24 @@ sub add_to_filemap { #If the hash already exists, throw a warning about duplicates if ( exists( $filemap{$id} ) ) { - if ($file eq $filemap{$id}) { - $logger->debug("$file was logged again but is already in the filemap, duplicate inotify events? Cleaning cache just to make sure"); + if ( $file eq $filemap{$id} ) { + $logger->debug( + "$file was logged again but is already in the filemap, duplicate inotify events? Cleaning cache just to make sure" + ); invalidate_cache(); } else { - $logger->warn( "$file is a duplicate of the existing file " - . $filemap{$id} - . ". You should delete it." ); + $logger->warn( "$file is a duplicate of the existing file " . $filemap{$id} . ". You should delete it." ); } return; - } - else { + } else { $filemap{$id} = $file; } # Filename sanity check if ( $redis->exists($id) ) { - my $filecheck = $redis->hget($id, "file"); + my $filecheck = $redis->hget( $id, "file" ); + #Update the real file path and title if they differ from the saved one #This is meant to always track the current filename for the OS. unless ( $file eq $filecheck ) { @@ -236,6 +235,7 @@ sub add_to_filemap { invalidate_cache(); } } else { + # Add to Redis if not present beforehand add_new_file( $id, $file ); invalidate_cache(); @@ -263,9 +263,8 @@ sub deleted_file_callback { #Lookup the file in the filemap and prune it #As it's a lookup by value it looks kinda ugly... - delete( $filemap{$_} ) - foreach grep { $filemap{$_} eq $name } keys %filemap; - + delete( $filemap{$_} ) foreach grep { $filemap{$_} eq $name } keys %filemap; + # Serialize filemap for main process to consume my $copy = {%filemap}; lock_store $copy, '.shinobu-filemap'; @@ -282,7 +281,7 @@ sub add_new_file { LANraragi::Utils::Database::add_archive_to_redis( $id, $file, $redis ); #AutoTagging using enabled plugins goes here! - if (LANraragi::Model::Config->enable_autotag) { + if ( LANraragi::Model::Config->enable_autotag ) { LANraragi::Model::Plugins::exec_enabled_plugins_on_file($id); } }; diff --git a/script/launcher.pl b/script/launcher.pl index cc8fcc8d6..c8b598b23 100644 --- a/script/launcher.pl +++ b/script/launcher.pl @@ -16,19 +16,19 @@ 'h|help' => \my $help, 'v|verbose' => \$ENV{MORBO_VERBOSE}; -if ($ENV{LRR_DATA_DIRECTORY}) { - make_path($ENV{LRR_DATA_DIRECTORY}); -} +if ( $ENV{LRR_DATA_DIRECTORY} ) { + make_path( $ENV{LRR_DATA_DIRECTORY} ); +} -if ($ENV{LRR_TEMP_DIRECTORY}) { - make_path($ENV{LRR_TEMP_DIRECTORY}); -} +if ( $ENV{LRR_TEMP_DIRECTORY} ) { + make_path( $ENV{LRR_TEMP_DIRECTORY} ); +} -die extract_usage if $help || !(my $app = shift || $ENV{HYPNOTOAD_APP}); +die extract_usage if $help || !( my $app = shift || $ENV{HYPNOTOAD_APP} ); my @listen; -if ($ENV{LRR_NETWORK}) { - @listen = [$ENV{LRR_NETWORK}]; +if ( $ENV{LRR_NETWORK} ) { + @listen = [ $ENV{LRR_NETWORK} ]; } else { @listen = ["http://*:3000"]; } diff --git a/tests/mocks.pl b/tests/mocks.pl index 071f4f092..f457b8cc0 100644 --- a/tests/mocks.pl +++ b/tests/mocks.pl @@ -12,13 +12,13 @@ sub setup_eze_mock { # Copy the eze sample json to a temporary directory as it's deleted once parsed my $cwd = getcwd; - my ($fh, $filename) = tempfile(); - cp( $cwd."/tests/eze_sample.json", $fh); + my ( $fh, $filename ) = tempfile(); + cp( $cwd . "/tests/eze_sample.json", $fh ); - # Mock LANraragi::Utils::Archive's subs to return the temporary sample JSON + # Mock LANraragi::Utils::Archive's subs to return the temporary sample JSON # Since we're using exports, the methods are under the plugin's namespace. - *LANraragi::Plugin::Metadata::Eze::extract_file_from_archive = sub {$filename}; - *LANraragi::Plugin::Metadata::Eze::is_file_in_archive = sub {1}; + *LANraragi::Plugin::Metadata::Eze::extract_file_from_archive = sub { $filename }; + *LANraragi::Plugin::Metadata::Eze::is_file_in_archive = sub { 1 }; } sub setup_redis_mock { @@ -26,7 +26,7 @@ sub setup_redis_mock { # DataModel for searches # files are set to package.json since the search engine checks for file existence and I ain't about to mock perl's -e call # Switch devmode to 1 for debug output in test - my %datamodel = %{decode_json qq( + my %datamodel = %{ decode_json qq( { "LRR_CONFIG": { "pagesize": "100", @@ -68,7 +68,8 @@ sub setup_redis_mock { "title": "Fate GO MEMO", "file": "package.json" } - })}; + }) + }; # Mock Redis object which uses the datamodel my $redis = Test::MockObject->new(); @@ -77,20 +78,20 @@ sub setup_redis_mock { $redis->mock( 'hexists', sub { 1 } ); $redis->mock( 'hset', sub { 1 } ); $redis->mock( 'quit', sub { 1 } ); - $redis->mock( 'select', sub { 1 } ); + $redis->mock( 'select', sub { 1 } ); - $redis->mock( 'hget', # $redis->hget => get key in datamodel + $redis->mock( + 'hget', # $redis->hget => get key in datamodel sub { my $self = shift; - my ($key, $hashkey) = @_; + my ( $key, $hashkey ) = @_; my $value = $datamodel{$key}{$hashkey}; return $value; - } ); + } + ); - $redis->fake_module( - "Redis", - new => sub {$redis}); + $redis->fake_module( "Redis", new => sub { $redis } ); } -1; \ No newline at end of file +1;