Downloader Plugins

Downloader Plugins are used as part of LANraragi's built-in downloading feature.

Required subroutines

Only one subroutine needs to be implemented for the module to be recognized: provide_url, which contains your working code. You're free to implement other subroutines for cleaner code, of course.

Your plugin also needs an extra field in its metadata: url_regex, which contains a Regular Expression that'll be used by LANraragi to know if your Downloader should be used. For example, if your regex is https?:\/\/example.com.*, LANraragi will invoke your plugin if the user wants to download an URL that comes from example.com.

In case of multiple Downloaders matching the given URL, the server will invoke the first plugin that matches.

Expected Input

The following section deals with writing the provide_url subroutine. When executing your Plugin, LRR will call this subroutine and pass it the following variables:

sub provide_url {

    #First lines you should have in the subroutine
    shift;
    my $lrr_info = shift; # Global info hash
    my ($param1, $param2) = @_; # Plugin parameters

The variables match the parameters you've entered in the plugin_info subroutine.

The $lrr_info hash contains three variables you can use in your plugin:

  • $lrr_info->{url}: The URL that needs to be downloaded.

  • $lrr_info->{user_agent}: Mojo::UserAgent object you can use for web requests. If this plugin depends on a Login plugin, this UserAgent will be pre-configured with the cookies from the Login.

  • $lrr_info->{tempdir}: A temporary directory path where you can store files. This is useful when you need to download and process multiple images, and are assembling the archive locally.

Expected Output

LRR expects Downloaders to return a hash containing either a new URL that can be downloaded directly, or a path to a file that has already been downloaded.

For returning a URL to download:

return ( download_url => "http://my.remote.service/download/secret-archive.zip" );

Said URL should directly point to a file -- Any form of HTML will trigger a failed download.

For returning a local file path (that you've already downloaded/created):

return ( file_path => "/path/to/downloaded/file.zip" );

If your script errored out, you can immediately stop the plugin execution and tell LRR that an error occurred by throwing an exception:

die "my error :(\n";

or by returning a hash containing an "error" field (this method is deprecated):

return ( error => "my error :(" );

If you do this, the error will be logged/displayed to the user.

Plugin Template

Last updated

Was this helpful?