Metadata Plugins
Metadata plugins are the bread-n-butter of LRR plugins: For a given archive, they can look for tags in a remote service or a local file and return this info so it can be integrated into LRR's database.
Required subroutines
Only one subroutine needs to be implemented for the module to be recognized: get_tags
, which contains your working code. You're free to implement other subroutines for cleaner code, of course.
Expected Input
The following section deals with writing the get_tags
subroutine. When executing your Plugin, LRR will call this subroutine and pass it the following variables:
The variables match the parameters you've entered in the plugin_info
subroutine. (Example here is for E-H. )
The $lrr_info
hash contains various variables you can use in your plugin:
$lrr_info->{archive_id}: The internal ID of the archive.
$lrr_info->{archive_title}: The title of the archive, as entered by the User.
$lrr_info->{existing_tags}: The tags that are already in LRR for this archive, if there are any.
$lrr_info->{thumbnail_hash}: A SHA-1 hash of the first image of the archive.
$lrr_info->{file_path}: The filesystem path to the archive.
$lrr_info->{oneshot_param}: Value of your one-shot argument, if it's been set by the User. See below.
$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.
The $params
hash contains the values of the user defined parameters.
One-Shot Arguments
The One-Shot Argument can be set by the user every time he uses your Plugin on a specific file, through LRR's Edit Menu. It's more meant for special overrides you'd want to use for this specific file: For example, in E-Hentai and nHentai plugins, it can be used to set a specific Gallery URL you want to pull tags from.
If you want the user to be able to enter this override, the oneshot_arg
field must be present in plugin_info
, and contain a brief description of what your argument is for.
One-Shot Arguments can only be strings.
Expected Output
Once you're done and obtained your tags, all that's needed for LRR to handle them is to return a hash containg said tags. Tags are expected to be separated by commas, like this:
return ( tags => "my:new, tags:here, look ma no namespace" );
Plugins can also modify the title or the summary of the archive: return ( tags => "some:tags", title=>"My new epic archive title", summary=>"Phenomenal! Wheres that David Lynch clip where he says phenomenal" );
Those two parameters are completely optional. (The tags one isn't, but it can very well be empty.) If the Plugin's user has disabled "Plugins can modify archive titles" in their settings, you can still pass a new title - It'll simply do nothing.
If you couldn't obtain tags for some reason, you can tell LRR that an error occurred by throwing an exception:
die "my error :(\n";
The old error handling still exists, but it's deprecated:
return ( error => "my error :(" );
If you do this, no tags will be added for this archive, and the error will be logged/displayed to the user.
Plugin Template
Converting existing plugins to named parameters
With the release of version 0.9.3 of LANraragi, named parameters for plugins have been introduced.
Compared to previous versions, where plugin parameters were based on an ordered array, named parameters should make it easier to understand the source code and write new plugins, especially if they make use of many parameters.
For the time being LANraragi will continue to support the plugins based on ordered array parameters so there is no need to rush to update your plugin. But if you still want to upgrade, the following information should help you.
If you have a plugin that you want to convert to using named parameters without losing the existing configuration, you can add a new key called to_named_params
to the plugin_info
hash. The new key must contain an array of the names assigned to the old parameters in the exact sequence in which they were present before the conversion. If you have added new parameters in the meantime, you don't have to specify them in the to_named_params
key.
The following example shows how to convert from the old parameter structure:
to the new structure:
Note that salvation
is not included in the conversion and the order of the items inside to_named_params
corresponds to the sequence of the parameters in the old format.
The to_named_params
key must be present the first time you load the plugin with the new parameter structure, otherwise the existing configuration will be lost. After the first use, however, it is no longer needed and you can remove it from a future version of the plugin.
Last updated