-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicecast-logger.lua
47 lines (40 loc) · 1.22 KB
/
icecast-logger.lua
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
-- mpv script that logs metadata from Icecast streams.
-- script adapted from here: https://gist.github.com/alecwbr/c84381559ded9ed8553dc53dc251b416
local CONFIG_DIR = (os.getenv("APPDATA") or os.getenv("HOME").."/.config");
local HISTFILE = CONFIG_DIR.."/mpv/icyhistory.log";
local function append_to_file(file, val)
local logfile;
if val == nil then
title = "No title available"
name = "No name"
artist = "Uknown artist"
end
if val ~= nil then
if val["icy-title"] then
name = val["icy-name"]
title = val["icy-title"]
artist = ""
end
if val["title"] then
name = val["icy-name"]
title = val["title"]
artist = val["artist"]
end
if val["Title"] then
name = val["icy-name"]
title = val["Title"]
artist = val["Artist"]
end
if val["TITLE"] then
name = val["icy-name"]
title = val["TITLE"]
artist = val["ARTIST"]
end
end
logfile = io.open(file, "a+");
logfile:write(("%s | %s - %s | %s\n"):format(os.date("%Y-%m-%d | %H:%M:%S"), title, artist, name));
logfile:close();
end
mp.observe_property("metadata", "native", function(name, val)
append_to_file(HISTFILE, val);
end)