LANraragi
GithubDemoDocker HubDiscord Server
Nightly Release
Nightly Release
  • LANraragi Documentation
  • Installing LANraragi
    • ❓Which installation method is best for me?
    • 🪟LRR for Windows (Win10)
    • 🍎Homebrew (macOS)
    • 🐳Docker (All platforms)
    • 🛠️Source Code (Linux/macOS)
    • 🐧Community (Linux)
    • 👿Jail (FreeBSD)
  • Basic Operations
    • 🚀Getting Started
    • 📚Reading Archives
    • ✒️Adding Metadata
    • 🔎Searching the Archive Index
    • 📈Statistics and Logs
    • 🖌️Themes
  • Advanced Usage
    • 🦇Batch Operations
    • 📂Categories
    • ⬇️Downloading Archives
    • 💾Backup and Restore
    • 📱Using External Readers
    • 🌐Network Interface Setup
    • 🕵️Proxy Setup
    • 📏Tag Rules
  • Developer Guide
    • 🏗️Setup a Development Environment
    • 🏛️Architecture & Style
    • 🈁Translating LANraragi to other languages
  • API Documentation
    • 🔑Getting started
    • Search API
    • Archive API
    • Database API
    • Category API
    • Tankoubon API
    • Shinobu API
    • Minion API
    • Miscellaneous other API
  • Writing Plugins
    • 🧩Getting started
    • Login Plugins
    • Metadata Plugins
    • Downloader Plugins
    • Generic Plugins ("Scripts")
    • Code Examples
Powered by GitBook
On this page
  • Write messages to the Plugin Log
  • Make requests to a remote WebService
  • Read values in the LRR Database
  • Extract files from the archive being examined

Was this helpful?

  1. Writing Plugins

Code Examples

PreviousGeneric Plugins ("Scripts")

Last updated 8 months ago

Was this helpful?

This section contains a few bits of code for things you might want to do with Plugins.

Write messages to the Plugin Log

# Import the LRR logging module
use LANraragi::Utils::Logging qw(get_plugin_logger);
# Use the logger to output status - they'll be passed to a specialized logfile and written to STDOUT.
my $logger = get_plugin_logger();

$plugin->debug("This message will only show if LRR is in Debug Mode")
$plugin->info("You know me the fighting freak Knuckles and we're at Pumpkin Hill");
$plugin->warn("You ready?");
$plugin->error("Oh no");

The logger is a preconfigured object.

Make requests to a remote WebService

is a full-featured HTTP client coming with LRR you can use.

use Mojo::UserAgent;

my $ua = $lrr_info->{user_agent};

#Get HTML from a simple GET request
$ua->get("http://example.com")->result->body;

#Make a POST request and get the JSON result
my $rep = $ua->post(
        "https://jsonplaceholder.typicode.com/" => json => {
            stage  => "Meteor Herd",
            location   => [ [ "space", "colony" ] ],
            emeralds => 3
        }
    )->result;

#JSON decoded to a perl object
my $jsonresponse = $rep->json;

#JSON decoded to a string
my $textrep      = $rep->body;

Read values in the LRR Database

my $redis = LANraragi::Model::Config->get_redis;

my $value = $redis->get("key");

Extract files from the archive being examined

If you're running 0.5.2 or later:

use LANraragi::Utils::Archive qw(is_file_in_archive extract_file_from_archive);

# Check if info.json is in the archive located at $file and get its precise path
my $info_path = is_file_in_archive($file, "info.json");
if ($info_path) {

        #Extract info.json
        my $filepath = extract_file_from_archive($file, $info_path);

        #Do whatever you need with the extracted file
        open( my $fh, '<:encoding(UTF-8)', $filepath )
          or die "Could not open $filepath!\n";

        while ( my $row = <$fh> ) {
            #...
        }

        #Delete it
        unlink $filepath;
}

This uses the excellent for Redis.

Mojo::Log
Mojo::UserAgent
Perl binding library