X-Git-Url: https://git.rvb.name/mpd-lua.git/blobdiff_plain/bf3bf92221cb7c06bcd93683db53b54b28ec31b5..759671cb4bae0c5a209dc4406f5e5c3b46316375:/mpd.lua diff --git a/mpd.lua b/mpd.lua index b5e180d..8935c9a 100755 --- a/mpd.lua +++ b/mpd.lua @@ -1,6 +1,7 @@ #!/usr/bin/lua -require "uci" +local hasuci,uci = pcall(require,"uci") + require("socket") json=require("json") @@ -160,16 +161,44 @@ function mpd_send(mpd,action,raw) return values end -x = uci.cursor() +if hasuci then + + x = uci.cursor() + + settings = {} + settings['host'] = x.get("mpd","server","host") or "localhost" + settings['port'] = x.get("mpd","server","port") or 6600 + settings['timeout'] = x.get("mpd","server","timeout") or 1 + + volstep = x.get("mpd","control","volume_step") or 3 -settings = {} -settings['host'] = x.get("mpd","server","host") or "localhost" -settings['port'] = x.get("mpd","server","port") or 6600 -settings['timeout'] = x.get("mpd","server","timeout") or 1 + password = x.get("mpd","server","password") -volstep = x.get("mpd","control","volume_step") or 3 +else + + config = arg[1] + if not config then + config="/etc/mpd-lua.json" + end -password = x.get("mpd","server","password") + settings={} + local open = io.open + local file = open(config, "r") + if file then + local content = file:read "*a" + file:close() + settings=json.decode(content) + end + + settings['host'] = settings['host'] or "localhost" + settings['port'] = settings["port"] or 6600 + settings['timeout'] = settings["timeout"] or 1 + + volstep = settings["volstep"] or 3 + +end + + if password then settings["password"] = password end @@ -290,8 +319,7 @@ elseif command=="status" then if song then res['current_playing']=pl[song]['name'] - else - res['song']="--" + else res['current_playing']="---" end