#!/usr/bin/lua
-require "uci"
+local hasuci,uci = pcall(require,"uci")
+
require("socket")
json=require("json")
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
if song then
res['current_playing']=pl[song]['name']
- else
- res['song']="--"
+ else
res['current_playing']="---"
end