Changeset 8526

Show
Ignore:
Timestamp:
04/08/12 00:38:53 (14 months ago)
Author:
jow
Message:

applications/luci-minidlna: add status output

Location:
luci/trunk/applications/luci-minidlna/luasrc
Files:
5 added
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/applications/luci-minidlna/luasrc/controller/minidlna.lua

    r8516 r8526  
    2525    page.i18n = "minidlna" 
    2626    page.dependent = true 
     27 
     28    entry({"admin", "services", "minidlna_status"}, call("minidlna_status")) 
    2729end 
     30 
     31function minidlna_status() 
     32    local sys  = require "luci.sys" 
     33    local uci  = require "luci.model.uci".cursor() 
     34    local port = tonumber(uci:get_first("minidlna", "minidlna", "port")) 
     35 
     36    local status = { 
     37        running = (sys.call("pidof minidlna >/dev/null") == 0), 
     38        audio   = 0, 
     39        video   = 0, 
     40        image   = 0 
     41    } 
     42 
     43    if status.running then 
     44        local fd = sys.httpget("http://127.0.0.1:%d/" % (port or 8200), true) 
     45        if fd then 
     46            local ln 
     47            repeat 
     48                ln = fd:read("*l") 
     49                if ln and ln:match("files:") then 
     50                    local ftype, fcount = ln:match("(.+) files: (%d+)") 
     51                    status[ftype:lower()] = tonumber(fcount) or 0 
     52                end 
     53            until not ln 
     54            fd:close() 
     55        end 
     56    end 
     57 
     58    luci.http.prepare_content("application/json") 
     59    luci.http.write_json(status) 
     60end