root/luci/trunk/applications/luci-minidlna/luasrc/controller/minidlna.lua @ 8658

Revision 8658, 1.4 KB (checked in by jow, 13 months ago)

applications/luci-minidlna: fix status parsing

Line 
1--[[
2LuCI - Lua Configuration Interface - miniDLNA support
3
4Copyright 2012 Gabor Juhos <juhosg@openwrt.org>
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12$Id$
13]]--
14
15module("luci.controller.minidlna", package.seeall)
16
17function index()
18    if not nixio.fs.access("/etc/config/minidlna") then
19        return
20    end
21
22    local page
23
24    page = entry({"admin", "services", "minidlna"}, cbi("minidlna"), _("miniDLNA"))
25    page.i18n = "minidlna"
26    page.dependent = true
27
28    entry({"admin", "services", "minidlna_status"}, call("minidlna_status"))
29end
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 html = fd:read("*a")
47            if html then
48                status.audio = (tonumber(html:match("Audio files: (%d+)")) or 0)
49                status.video = (tonumber(html:match("Video files: (%d+)")) or 0)
50                status.image = (tonumber(html:match("Image files: (%d+)")) or 0)
51            end
52            fd:close()
53        end
54    end
55
56    luci.http.prepare_content("application/json")
57    luci.http.write_json(status)
58end
Note: See TracBrowser for help on using the browser.