Lua Renamer is a plugin for Shoko Server. It allows users to rename their collection via an Lua 5.4 interface.
This renamer is fitting for users with more advanced collection renaming/organization requirements.
Limitations: The Lua environment is sandboxed such that interaction with the operating system/file system/networking is unavailable.
For support/questions join the Shoko Discord server and message mikill.
C:\ProgramData\ShokoServer\plugins
/home/shoko/.shoko/Shoko.CLI/plugins
is mounted.If you wish to rename/move your files on import you must do two things:
Check out This short guide if you are new to Lua.
File -> Open Folder...
default.lua
(editing default.lua will not change existing scripts on the server, but will be used when new scripts are created)The lua environment is sandboxed, removing operations from standard libraries such as io
, and os
. See BaseEnv in LuaContext.
The script is run in a fresh environment for every file.
Only the output variables defined in env.lua will have any effect outside of the script.
* This file is not executed, it serves as documentation/annotations
In addition to the filename
, destination
and subfolder
output variables, these variables affect the result of your script.
use_existing_anime_location
If true, the subfolder with the most files of the same anime is reused if one exists. This takes precedence over the subfolder set in the script (default: false)replace_illegal_chars
If true, replaces all illegal path characters in subfolder and file name with alternatives. See ReplaceMap in Utils.cs (default: false)remove_illegal_chars
If true, removes all illegal path characters in subfolder and file name. If false, illegal characters are replaced with underscores or replaced if replace_illegal_chars
is true. (default: false)skip_rename
If true, the result of running the script is discarded when renaming. (default: false)skip_move
If true, the result of running the script is discarded when moving. (default: false)Destination
or Both
Drop Type.
[!NOTE] Using
use_existing_anime_location
may bypass this restriction, allowingNone
but notSource
. This may change in the future.
Destination defaults to the nearest (to the file) valid import folder.
Destination is set via one of:
importfolders
array or file.importfolder
)If destination set via path, it is matched to import folder path with converted directory seperators but no other special handling (relative path or expansion).
Subfolder defaults to the anime title in your preferred language.
Subfolder is set via one of:
{"parent dir name", "subdir name", "..."}
)If set via a string subfolder name, directory separators within the string are ignored or replaced depending on preference.
Also see use_existing_anime_location
in Script Settings
The easiest option is to set the destination by import folder name. Keep in mind the import folder must have the Destination or Both drop type. You may also specify the destination by the full path of the import folder on the server or by referencing it directly via importfolders
.
if anime.restricted then
destination = "hentai"
else
destination = "anime"
end
if anime.type == AnimeType.Movie then
subfolder = { "Anime Movies", anime.preferredname }
else
subfolder = { "Anime", anime.preferredname }
end
Adding Shoko group name to subfolder path when there are multiple series in group.
if #groups == 1 and #groups[1].animes > 1 then
subfolder = {groups[1].name, anime.preferredname}
end
AniDB, Shoko's metadata provider does not have the concept of seasons. Therefore the metadata available cannot be cleanly mapped. I recommend using Shoko Metadata for Plex or Shokofin for Jellyfin as your client instead of depending on other metadata providing plugins.
Neither Shoko nor this plugin has the ability to create file links. I recommend creating any links before the file is processed by Shoko. Usually download clients have the option to run a script on download completion. You can create a script to link files to a Shoko drop source folder. Feel free to contact me if you need help with this.
Note: If you hard link your files you will need to create an import folder for each file system/volume used.