Косметические доработки интерфейса.
[mpd-lua.git] / mpd.lua
diff --git a/mpd.lua b/mpd.lua
index b5e180d5adf38465a3e284af0f766d1a310a12f2..8935c9a605af940fa108e19c62424f8bee5ce26e 100755 (executable)
--- 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