Skip to content

Commit

Permalink
Feat: Add widget script for newest playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Sep 4, 2024
1 parent f7e5068 commit ee5a069
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions HomeWidgets/WidgetPlaylists.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- {"name": "WidgetPlaylists", "file": "HomeWidgets/WidgetPlaylists.lua", "version": 1, "desc": "Home widget for playlists.", "order":0,"arguments":["entries"]}
local headers = "Content-type: text/html\r\n"
local entries
if mympd_arguments.entries ~= nil then
entries = tonumber(mympd_arguments.entries)
else
entries = 10
end

local method = "MYMPD_API_PLAYLIST_LIST"
local options = {
searchstr = "",
sort = "Last-Modified",
sortdesc = false,
fields = {
"Name",
"Last-Modified"
},
type = 0,
offset = 0,
limit = entries
}

local rows = {}
local rc, result = mympd.api(method, options)
if rc == 0 then
for _,data in ipairs(result.data)
do
table.insert(rows, "<div class=\"list-group-item list-group-item-action clickable\" data-href='{\"cmd\":\"gotoPlaylist\",\"options\":[" ..
json.encode(mympd.htmlencode(data.Name)) .. "]}'>" .. mympd.htmlencode(data.Name) .. "</div>")
end
end

local body = "<div class=\"list-group list-group-flush\">" ..
table.concat(rows) ..
"</div>"

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

0 comments on commit ee5a069

Please sign in to comment.