Giter Site home page Giter Site logo

thebluekinglp / luarenamer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mik1ll/luarenamer

0.0 0.0 0.0 762 KB

Lua file renaming and moving plugin for Shoko. Uses Lua 5.4.

License: Creative Commons Zero v1.0 Universal

Lua 33.30% C# 66.70%

luarenamer's Introduction

LuaRenamer

Lua file renaming and moving plugin for Shoko. Uses Lua 5.4.

Installation

  1. Download the latest release
  2. Unzip the files into C:\ProgramData\ShokoServer\plugins (Windows) or /home/.shoko/Shoko.CLI/plugins (Linux/Docker)
  3. (Optional) You may COPY (not move) the lua sub-directory to a convenient location for script editing
  4. It is strongly recommened to install VS Code and the Lua extension to edit your script. The extension uses EmmyLua for annotations
  5. Follow instructions in the next section to add your script

Usage

  1. Open the lua folder under the directory you extracted, in VS Code
  2. Look at the sample script and the bottom of defs.lua to get an idea of available variables
  3. Create a new file or modify the sample script to fit your needs. NOTE: 'sample script.lua' is not read by the renamer, you must save it as a script within shoko, see next steps
  4. Open Shoko Desktop
  5. Navigate to Utilities/File Renaming
  6. Use the Default script or create a new one and set the type of the script to LuaRenamer in the drop-down menu
  7. Copy your script and paste it in the text box
  8. Test your script by adding files and clicking preview in the utility under the text box until you are satisfied
  9. Check run on import, and save the script (next to the script type drop-down)
  10. You may manually rename and move the files (if checked) of your collection in the utility

Important Notes for File Moving

Destination defaults to the first destination folder it can find.
If destination is set, it must be set to the name(in shoko) of an import folder, or an import folder table, which are found in the importfolders array or file.importfolder for the current file's folder
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.

Script Environment

The lua environment is sandboxed, removing operations from standard libraries such as io, and os. See BaseEnv in NLuaSingleton.
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.

Sample Script

function rm_empty_str(table) return from(table):where(function (a) return a ~= "" end):toArray() end

local group = file.anidb and file.anidb.releasegroup and "[" .. (file.anidb.releasegroup.shortname or file.anidb.releasegroup.name) .. "]" or ""

local animename = anime:getname(Language.English) or anime:getname(Language.Romaji) or anime.preferredname
animename = string.gsub(string.sub(animename, 0, 35), "%s+$", "") .. (#animename > 35 and "..." or "")

local episodename = episode:getname(Language.English) or ""
episodename = string.gsub(string.sub(episodename, 0, 35), "%s+$", "") .. (#episodename > 35 and "..." or "")

local episodenumber = ""
if anime.type ~= AnimeType.Movie or not string.find(episodename, "Complete Movie") then
  episodenumber = episode_numbers(2) .. (file.anidb and file.anidb.version > 1 and "v" .. file.anidb.version or "")
  if #episodes > 1 or string.find(episodename, "Episode") then
    episodename = ""
  end
else
  episodename = ""
end

local res = file.media.video.res or ""
local codec = file.media.video.codec or ""
local bitdepth = file.media.video.bitdepth and file.media.video.bitdepth ~= 8 and file.media.video.bitdepth .. "bit" or ""
local source = file.anidb and file.anidb.source or ""

local fileinfo = "(" .. table.concat(rm_empty_str{res, codec, bitdepth, source}, " ") .. ")"

local dublangs = from(file.anidb and file.anidb.media.dublanguages or from(file.media.audio):select("language"))
local sublangs = from(file.anidb and file.anidb.media.sublanguages or file.media.sublanguages)
local audiotag = dublangs:contains(Language.English) and (dublangs:contains(Language.Japanese) and "[DUAL-AUDIO]" or "[DUB]") or ""
local subtag = audiotag == "" and not sublangs:contains(Language.English) and "[RAW]" or ""

local centag = anime.restricted and file.anidb and (file.anidb.censored and "[CEN]" or "[UNCEN]") or ""
local hashtag = "[" .. file.hashes.crc .. "]"

local nametable = rm_empty_str{group, animename, episodenumber, episodename, fileinfo, audiotag, subtag, centag, hashtag}
filename = string.sub(table.concat(nametable, " "), 0, 120)

Snippets

WIP

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.