unblockneteasemusic.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. -- This is a free software, use it under GNU General Public License v3.0.
  2. -- Created By [CTCGFW]Project OpenWRT
  3. -- https://github.com/project-openwrt
  4. module("luci.controller.unblockneteasemusic", package.seeall)
  5. function index()
  6. if not nixio.fs.access("/etc/config/unblockneteasemusic") then
  7. return
  8. end
  9. entry({"admin", "services", "unblockneteasemusic"},firstchild(), _("解除网易云音乐播放限制"), 50).dependent = false
  10. entry({"admin", "services", "unblockneteasemusic", "general"},cbi("unblockneteasemusic"), _("基本设定"), 1)
  11. entry({"admin", "services", "unblockneteasemusic", "update_core"},form("unblockneteasemusic_upcore"), _("更新核心"), 2).leaf = true
  12. entry({"admin", "services", "unblockneteasemusic", "log"},form("unblockneteasemusiclog"), _("日志"), 3)
  13. entry({"admin", "services", "unblockneteasemusic", "status"},call("act_status")).leaf=true
  14. entry({"admin", "services", "unblockneteasemusic", "upgrade_core"},call("act_update_core"))
  15. end
  16. function act_status()
  17. local e={}
  18. e.running=luci.sys.call("ps |grep unblockneteasemusic |grep app.js |grep -v grep >/dev/null")==0
  19. luci.http.prepare_content("application/json")
  20. luci.http.write_json(e)
  21. end
  22. function update_core()
  23. cloud_ver=luci.sys.exec("curl -s 'https://github.com/nondanee/UnblockNeteaseMusic/commits/master' |tr -d '\n' |grep -Eo 'commit\/[0-9a-z]+' |sed -n 1p |sed 's#commit/##g'")
  24. cloud_ver_mini=luci.sys.exec("curl -s 'https://github.com/nondanee/UnblockNeteaseMusic/commits/master' |tr -d '\n' |grep -Eo 'BtnGroup-item.> [0-9a-z]+' |sed -n 1p |sed 's#BtnGroup-item.> ##g'")
  25. if not cloud_ver or not cloud_ver_mini then
  26. return "1"
  27. else
  28. local_ver=luci.sys.exec("cat '/usr/share/unblockneteasemusic/local_ver'")
  29. if not local_ver or (local_ver ~= cloud_ver) then
  30. luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_successfully")
  31. luci.sys.call("/bin/bash /usr/share/unblockneteasemusic/update_core.sh luci_update")
  32. if not nixio.fs.access("/usr/share/unblockneteasemusic/update_successfully") then
  33. return "2"
  34. else
  35. luci.sys.call("rm -f /usr/share/unblockneteasemusic/update_successfully")
  36. return cloud_ver_mini
  37. end
  38. else
  39. return "0"
  40. end
  41. end
  42. end
  43. function act_update_core()
  44. luci.http.prepare_content("application/json")
  45. luci.http.write_json({
  46. ret = update_core();
  47. })
  48. end