plex implement ok

This commit is contained in:
janson 2022-11-07 11:06:12 +08:00
parent ecc05ae671
commit b536df07a2
6 changed files with 83 additions and 10 deletions

View File

@ -1,7 +1,7 @@
module("luci.controller.heimdall", package.seeall)
module("luci.controller.plex", package.seeall)
function index()
entry({"admin", "services", "heimdall"}, alias("admin", "services", "heimdall", "config"), _("Heimdall"), 30).dependent = true
entry({"admin", "services", "heimdall", "config"}, cbi("heimdall"))
entry({"admin", "services", "plex"}, alias("admin", "services", "plex", "config"), _("Plex"), 30).dependent = true
entry({"admin", "services", "plex", "config"}, cbi("plex"))
end

View File

@ -3,6 +3,7 @@ LuCI - Lua Configuration Interface
]]--
local taskd = require "luci.model.tasks"
local plex_model = require "luci.model.plex"
local m, s, o
m = taskd.docker_map("plex", "plex", "/usr/libexec/istorec/plex.sh",
@ -31,14 +32,36 @@ o.default = "32400"
o.datatype = "port"
o:depends("hostnet", 0)
o = s:option(Value, "image_name", translate("Image").."<b>*</b>")
o.rmempty = false
o.datatype = "string"
o:value("plexinc/pms-docker:latest", "plexinc/pms-docker:latest")
o:value("plexinc/pms-docker:1.29.1.6316-f4cdfea9c", "plexinc/pms-docker:1.29.1.6316-f4cdfea9c")
o.default = "plexinc/pms-docker:latest"
local blocks = plex_model.blocks()
local home = plex_model.home()
o = s:option(Value, "config_path", translate("Config path").."<b>*</b>")
o.rmempty = false
o.datatype = "string"
local paths, default_path = plex_model.find_paths(blocks, home, "config")
for _, val in pairs(paths) do
o:value(val, val)
end
o.default = default_path
o = s:option(Value, "media_path", translate("Media path"))
o.datatype = "string"
o.default = plex_model.media_path(home)
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 = plex_model.find_paths(blocks, home, "transcodes")
for _, val in pairs(paths) do
o:value(val, val)
end
o.default = default_path
return m

View File

@ -1,9 +1,9 @@
local util = require "luci.util"
local jsonc = require "luci.jsonc"
local plex_model = {}
local plex = {}
plex_model.blocks = function()
plex.blocks = function()
local f = io.popen("lsblk -s -f -b -o NAME,FSSIZE,MOUNTPOINT --json", "r")
local vals = {}
if f then
@ -21,3 +21,34 @@ plex_model.blocks = function()
return vals
end
plex.home = function()
local uci = require "luci.model.uci".cursor()
local data = uci:get_first("linkease", "linkease", "local_home", "/root")
return data
end
plex.find_paths = function(blocks, home, path_name)
local default_path = ''
local configs = {}
if #blocks == 0 then
default_path = home .. "/Programs/plex/" .. path_name
table.insert(configs, default_path)
else
for _, val in pairs(blocks) do
table.insert(configs, val .. "/Programs/plex/" .. path_name)
end
default_path = configs[1]
end
return configs, default_path
end
plex.media_path = function(home)
if home == "/root" then
return ""
else
return home .. "/Downloads"
end
end
return plex

View File

@ -1,4 +1,7 @@
config heimdall
option 'http_port' '8088'
option 'https_port' '8089'
option 'config_path' '/root/heimdall/config'
config plex
option 'hostnet' '0'
option 'claim_token' ''
option 'port' '32400'
option 'image_name' 'plexinc/pms-docker:latest'
option 'config_path' ''

View File

@ -13,7 +13,7 @@ do_install() {
local media=`uci get plex.@plex[0].media_path 2>/dev/null`
local cache=`uci get plex.@plex[0].cache_path 2>/dev/null`
[-z "$image_name" ] && image_name="plexinc/pms-docker:latest"
[ -z "$image_name" ] && image_name="plexinc/pms-docker:latest"
echo "docker pull ${image_name}"
docker pull ${image_name}
docker rm -f plex

View File

@ -0,0 +1,16 @@
#!/bin/sh
# run in router
APPNAME=$1
if [ -z "${APPNAME}" ]; then
APPNAME=plex
fi
mkdir -p /usr/lib/lua/luci/view/${APPNAME}
cp ./luasrc/controller/${APPNAME}.lua /usr/lib/lua/luci/controller/
cp ./luasrc/view/${APPNAME}/* /usr/lib/lua/luci/view/${APPNAME}/
cp -rf ./luasrc/model/* /usr/lib/lua/luci/model/
cp -rf ./root/* /
rm -rf /tmp/luci-*