-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsongs.lua
More file actions
74 lines (61 loc) · 2.81 KB
/
songs.lua
File metadata and controls
74 lines (61 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-----------------------------------------------------
-- ----------------------------------------------- --
-- ▄ ▄ ▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄ ▄ --
-- ▐░▌ ▐░▌ ▐░▌▐░█▀▀▀▀▀ ▀▀█░█▀▀ ▐░▌ ▐░▌ --
-- ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░█ █░▌ --
-- ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░░░░░░░▌ --
-- ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▀▀▀▀▀█░▌ --
-- ▐░█▄▄▄▄▄ ▐░█▄▄▄█░▌▐░█▄▄▄▄▄ ▄▄█░█▄▄ ▐░▌ --
-- ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀ --
-- ----------------------------------------------- --
-- ------- Luci4 util print Ampache stats -------- --
-- -------- https://github.com/icefields --------- --
-----------------------------------------------------
-- setting the local path so the script can find dependencies
local script_path = debug.getinfo(1, "S").source:match("(.*/)") or ""
script_path = script_path:sub(2) -- Removes the '@' at the beginning if it exists
local script_dir = script_path:match("(.+)/") -- Get everything before the last '/'
script_dir = script_dir or "" -- If no directory, make it an empty string
package.path = script_dir .. "/?.lua;" .. package.path
local ampache = require("ampache-common")
local ampacheHttp = require("ampache-http")
if (ampache.shouldPrintHelp()) then
ampache.printHelp("songs.lua")
return
end
local server_url, username, password, limit, filter_value, is_json_output =
ampache.parseArgs(arg)
local res, code, response_headers, status, json_response, data = ampacheHttp.makeRequest({
serverUrl = server_url,
action = "songs",
username = username,
password = password,
limit = limit,
filterValue = filter_value
})
-- Check if the request was successful
if code == 200 then
-- if the -j option is passed, just print the json file
if is_json_output == true then
print(json_response)
return
end
for _, item in ipairs(data["song"]) do
-- Print name if valid
-- safePrint("title", string.format("%s (id: %s)", item.title, item.id))
ampache.safePrint(item.artist.name, item.title)
if item.url then
print(item.url)
end
if item.album.name then
print(item.album.name)
end
if item.art and item.has_art then
print(item.art)
end
print("\n") -- Add a blank line between items
end
else
-- Print an error message if the request fails
print("HTTP request failed with status: " .. status)
end