minidlna.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. -- Copyright 2012 Gabor Juhos <juhosg@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. module("luci.controller.minidlna", package.seeall)
  4. function index()
  5. if not nixio.fs.access("/etc/config/minidlna") then
  6. return
  7. end
  8. local page
  9. page = entry({"admin", "services", "minidlna"}, cbi("minidlna"), _("miniDLNA"))
  10. page.dependent = true
  11. entry({"admin", "services", "minidlna_status"}, call("minidlna_status"))
  12. end
  13. function minidlna_status()
  14. local sys = require "luci.sys"
  15. local uci = require "luci.model.uci".cursor()
  16. local port = tonumber(uci:get_first("minidlna", "minidlna", "port"))
  17. local status = {
  18. running = (sys.call("pidof minidlna >/dev/null") == 0),
  19. audio = 0,
  20. video = 0,
  21. image = 0
  22. }
  23. if status.running then
  24. local fd = sys.httpget("http://127.0.0.1:%d/" % (port or 8200), true)
  25. if fd then
  26. local html = fd:read("*a")
  27. if html then
  28. status.audio = (tonumber(html:match("Audio files</td><td>(%d+)")) or 0)
  29. status.video = (tonumber(html:match("Video files</td><td>(%d+)")) or 0)
  30. status.image = (tonumber(html:match("Image files</td><td>(%d+)")) or 0)
  31. end
  32. fd:close()
  33. end
  34. end
  35. luci.http.prepare_content("application/json")
  36. luci.http.write_json(status)
  37. end