Lua file renaming and moving plugin for Shoko. Uses Lua 5.4.
- Download the latest release
- Unzip the files into destination
- (Windows)
C:\ProgramData\ShokoServer\plugins
- (Docker) wherever the container location
/home/shoko/.shoko/Shoko.CLI/plugins
is mounted
- (Windows)
- Restart Shoko Server
- (Optional) Install VS Code and the Lua extension to edit your script. The extension uses EmmyLua for annotations
- Follow instructions in the next section to add your script
- Open Shoko Desktop
- Navigate to Utilities/File Renaming
- Use the Default script or create a new one and set the type of the script to LuaRenamer in the drop-down menu
- (Optional) Open the lua subfolder of the extracted plugin in VS Code
- Look at the example script and the bottom of defs.lua to get an idea of available variables
- (Optional) Check out The lualinq docs for info on uses of 'from()'
- Create a script or copy and edit the example script
- Paste the script in the text box in Shoko Desktop
- Test your script by adding files and clicking preview in the utility under the text box until you are satisfied
- Check run on import, and save the script (next to the script type drop-down)
- You may manually rename and move the files (if checked) of your collection in the utility
- Copy/download the linux scripts
- (Optional) Open the lua subfolder of the extracted plugin in VS Code
- Look at the example script and the bottom of defs.lua to get an idea of available variables
- (Optional) Check out The lualinq docs for info on uses of 'from()'
- Create a script or copy and edit the example script
- Preview the results with the preview script
./preview_rename_script.sh <script filename> [# results]
- Add your script to Shoko with the add script
./add_rename_script.sh <script filename>
- If you want to rename and move all existing files use the rename script
./rename_and_move_all.sh <script name>
Destination defaults to the nearest (longest matching prefix) destination folder it can find.
If destination is set, it must be set to an existing import folder using the name or path (string), or an import folder table.
If destination set to a path, it is compared to import folder path with converted directory seperators but no other special handling (relative path or expansion).
The only destination folders settable by the renamer are import folders with Drop Type of Destination or Both.
Subfolder defaults to your preferred language anime title.
If subfolder is set, it must be set to an array-table of path segments e.g. subfolder = {"parent dir name", "subdir name", "..."}
If 'use_existing_anime_location' is set to true, the last added file's location from the same anime will be used if it exists.
The lua environment is sandboxed, removing operations from standard libraries such as io, and os. See BaseEnv in LuaContext.
Additionally, a modified version of lualinq from xanathar, licensed under the BSD 3 clause, has
been included for convenience. Original Documentation
See defs.lua for all exposed data definitions/structure available from shoko.
Choosing a destination (picks folders by name, or folder path of existing import folder)
if anime.restricted then
destination = "hentai"
else
destination = "anime"
end
Choosing a destination by table (complex), edit second line to add conditions
destination = from(importfolders):where(function (importfld) ---@param importfld ImportFolder
return importfld.type == ImportFolderType.Destination or importfld.type == ImportFolderType.Both
end):first()
Adding Shoko group name to subfolder path when there are multiple series in group.
Warning: adding new series to a group with one entry will not move the old series into a subfolder, so you should probably use it when batch renaming/moving existing series
if #groups == 1 and #groups[1].seriesids > 1 then
subfolder = {groups[1].name, anime.preferredname}
end