From b37c092f7ad8a7d4ec03f712138710465b25bce0 Mon Sep 17 00:00:00 2001 From: janson Date: Thu, 10 Nov 2022 16:17:00 +0800 Subject: [PATCH] jellyfin ok --- applications/luci-app-jellyfin/Makefile | 2 +- .../luasrc/model/cbi/jellyfin.lua | 21 ++++++-- .../luasrc/model/jellyfin.lua | 54 +++++++++++++++++++ .../luci-app-jellyfin/po/zh-cn/jellyfin.po | 3 ++ .../root/etc/config/jellyfin | 2 +- 5 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 applications/luci-app-jellyfin/luasrc/model/jellyfin.lua diff --git a/applications/luci-app-jellyfin/Makefile b/applications/luci-app-jellyfin/Makefile index 80ee6ac..a4f2038 100644 --- a/applications/luci-app-jellyfin/Makefile +++ b/applications/luci-app-jellyfin/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk -PKG_VERSION:=1.1.5-20220729 +PKG_VERSION:=1.1.5-20221110 PKG_RELEASE:= LUCI_TITLE:=LuCI support for jellyfin diff --git a/applications/luci-app-jellyfin/luasrc/model/cbi/jellyfin.lua b/applications/luci-app-jellyfin/luasrc/model/cbi/jellyfin.lua index 8bb0110..8fbb7f7 100644 --- a/applications/luci-app-jellyfin/luasrc/model/cbi/jellyfin.lua +++ b/applications/luci-app-jellyfin/luasrc/model/cbi/jellyfin.lua @@ -3,6 +3,7 @@ LuCI - Lua Configuration Interface ]]-- local taskd = require "luci.model.tasks" +local jellyfin_model = require "luci.model.jellyfin" local m, s, o m = taskd.docker_map("jellyfin", "jellyfin", "/usr/share/jellyfin/install.sh", @@ -26,14 +27,28 @@ o.default = "8096" o.datatype = "port" o:depends("hostnet", 0) -o = s:option(Value, "media_path", translate("Media path")) -o.datatype = "string" +local blocks = jellyfin_model.blocks() +local home = jellyfin_model.home() o = s:option(Value, "config_path", translate("Config path").."*") o.rmempty = false o.datatype = "string" -o = s:option(Value, "cache_path", translate("Transcode cache path"), translate("Default use 'transcodes' in 'config path' if not set, please make sure there has enough space")) +local paths, default_path = jellyfin_model.find_paths(blocks, home, "Configs") +for _, val in pairs(paths) do + o:value(val, val) +end +o.default = default_path + +o = s:option(Value, "media_path", translate("Media path"), translate("Not required, all disk is mounted in") .. " /mnt") o.datatype = "string" +o = s:option(Value, "cache_path", translate("Transcode cache path"), translate("Default use 'transcodes' in 'config path' if not set, please make sure there has enough space")) +o.datatype = "string" +local paths, default_path = jellyfin_model.find_paths(blocks, home, "Caches") +for _, val in pairs(paths) do + o:value(val, val) +end +o.default = default_path + return m diff --git a/applications/luci-app-jellyfin/luasrc/model/jellyfin.lua b/applications/luci-app-jellyfin/luasrc/model/jellyfin.lua new file mode 100644 index 0000000..519a9f5 --- /dev/null +++ b/applications/luci-app-jellyfin/luasrc/model/jellyfin.lua @@ -0,0 +1,54 @@ +local util = require "luci.util" +local jsonc = require "luci.jsonc" + +local jellyfin = {} + +jellyfin.blocks = function() + local f = io.popen("lsblk -s -f -b -o NAME,FSSIZE,MOUNTPOINT --json", "r") + local vals = {} + if f then + local ret = f:read("*all") + f:close() + local obj = jsonc.parse(ret) + for _, val in pairs(obj["blockdevices"]) do + local fsize = val["fssize"] + if fsize ~= nil and string.len(fsize) > 10 and val["mountpoint"] then + -- fsize > 1G + vals[#vals+1] = val["mountpoint"] + end + end + end + return vals +end + +jellyfin.home = function() + local uci = require "luci.model.uci".cursor() + local home_dirs = {} + home_dirs["main_dir"] = uci:get_first("quickstart", "main", "main_dir", "/root") + home_dirs["Configs"] = uci:get_first("quickstart", "main", "conf_dir", home_dirs["main_dir"].."/Configs") + home_dirs["Downloads"] = uci:get_first("quickstart", "main", "dl_dir", home_dirs["main_dir"].."/Downloads") + home_dirs["Caches"] = uci:get_first("quickstart", "main", "tmp_dir", home_dirs["main_dir"].."/Caches") + return home_dirs +end + +jellyfin.find_paths = function(blocks, home_dirs, path_name) + local default_path = '' + local configs = {} + + default_path = home_dirs[path_name] .. "/Jellyfin" + if #blocks == 0 then + table.insert(configs, default_path) + else + for _, val in pairs(blocks) do + table.insert(configs, val .. "/" .. path_name .. "/Jellyfin") + end + local without_conf_dir = "/root/" .. path_name .. "/Jellyfin" + if default_path == without_conf_dir then + default_path = configs[1] + end + end + + return configs, default_path +end + +return jellyfin diff --git a/applications/luci-app-jellyfin/po/zh-cn/jellyfin.po b/applications/luci-app-jellyfin/po/zh-cn/jellyfin.po index 6642763..a769e1b 100644 --- a/applications/luci-app-jellyfin/po/zh-cn/jellyfin.po +++ b/applications/luci-app-jellyfin/po/zh-cn/jellyfin.po @@ -51,3 +51,6 @@ msgstr "Jellyfin 未运行" msgid "Open Jellyfin" msgstr "打开 Jellyfin" + +msgid "Not required, all disk is mounted in" +msgstr "可不填,所有硬盘都在" diff --git a/applications/luci-app-jellyfin/root/etc/config/jellyfin b/applications/luci-app-jellyfin/root/etc/config/jellyfin index 7a3360a..fb3c345 100644 --- a/applications/luci-app-jellyfin/root/etc/config/jellyfin +++ b/applications/luci-app-jellyfin/root/etc/config/jellyfin @@ -3,5 +3,5 @@ config jellyfin option 'port' '8096' option 'image' 'default' option 'media_path' '' - option 'config_path' '/root/jellyfin/config' + option 'config_path' '/root/Config/Jellyfin' option 'cache_path' ''