-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate-playlist.lua
More file actions
80 lines (68 loc) · 2.97 KB
/
generate-playlist.lua
File metadata and controls
80 lines (68 loc) · 2.97 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
74
75
76
77
78
79
80
----------------------------------------------------
-- ----------------------------------------------- --
-- ▄ ▄ ▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄ ▄ --
-- ▐░▌ ▐░▌ ▐░▌▐░█▀▀▀▀▀ ▀▀█░█▀▀ ▐░▌ ▐░▌ --
-- ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░█ █░▌ --
-- ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░░░░░░░▌ --
-- ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▀▀▀▀▀█░▌ --
-- ▐░█▄▄▄▄▄ ▐░█▄▄▄█░▌▐░█▄▄▄▄▄ ▄▄█░█▄▄ ▐░▌ --
-- ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀ ▀ --
-- ----------------------------------------------- --
-- ----- Luci4 util print Ampache playlists ------ --
-- -------- 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")
local function read_credentials()
local home = os.getenv("HOME")
local filepath = home .. "/.config/ampache_credentials"
local file = io.open(filepath, "r")
if not file then
error("Could not open credentials file: " .. filepath)
end
local server = file:read("*l") -- first line
local username = file:read("*l") -- second line
local password = file:read("*l") -- third line
file:close()
return server, username, password
end
local server, username, password = read_credentials()
local res, code, response_headers, status, jsonResponse, data =
ampacheHttp.makeRequest({
serverUrl = server,
action = "playlists",
username = username,
password = password,
limit = 10,
filterValue = nil, --ampache.urlencode(arg[1]),
include = "song"
}, false)
local token = ampacheHttp.authToken
function playlists()
str = ''
for _, item in ipairs(data["playlist"]) do
print(item.name)
--str = (item.name).."\n"..str
end
--print(str)
end
function songUrls()
for _, item in ipairs(data["playlist"]) do
if item.name == arg[1] then
for _, item in ipairs(item.items) do
print(ampacheHttp.streamUrl(server, username, password, item.id, token))
end
end
end
end
if arg[2] == "-p" then
playlists()
else
songUrls()
end