Skip to content

Commit

Permalink
Feat: Add stats home widget
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Sep 25, 2024
1 parent f9b5a7c commit 11896e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
18 changes: 15 additions & 3 deletions HomeWidgets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This scripts can be used as the backend for widgets on the home screen. They return a http response with html content that is displayed in the widget.

## AlbumsWidget
## WidgetAlbums

Lists newest or random albums.

Expand All @@ -11,15 +11,27 @@ Lists newest or random albums.
| entries | Number of albums to list. |
| view | `random` or `newest` |

## BatteryIndicatorWidget
## WidgetBatteryIndicator

Reads the battery capacity from the sys filesystem.

| ARGUMENT | DESCRIPTION |
| -------- | ----------- |
| battery | The battery sys folder, e.g. `BAT0` |

## SongsWidget
## WidgetPlaylists

Lists newest playlists.

| ARGUMENT | DESCRIPTION |
| -------- | ----------- |
| entries | Number of playlists to list. |

## WidgetStats

Show MPD database statistics.

## WidgetSongs

Lists newest or random songs.

Expand Down
16 changes: 16 additions & 0 deletions HomeWidgets/WidgetStats.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- {"name": "WidgetStats", "file": "HomeWidgets/WidgetStats.lua", "version": 1, "desc": "Home widget for MPD DB stats.", "order":0,"arguments":[]}
local headers = "Content-type: text/html\r\n"

local rc, result = mympd.api("MYMPD_API_STATS", {})
local rows = {}
if rc == 0 then
table.insert(rows, "<tr><th>Artists</th><td>" .. mympd.htmlencode(result.artists) .. "</td></tr>")
table.insert(rows, "<tr><th>Albums</th><td>" .. mympd.htmlencode(result.albums) .. "</td></tr>")
table.insert(rows, "<tr><th>Songs</th><td>" .. mympd.htmlencode(result.songs) .. "</td></tr>")
end

local body = "<table class=\"table\">" ..
table.concat(rows) ..
"</table>"

return mympd.http_reply("200", headers, body)

0 comments on commit 11896e7

Please sign in to comment.