Skip to content

Instantly share code, notes, and snippets.

@christosangelopoulos
Forked from alecwbr/icylogger.lua
Last active November 16, 2023 07:54
Show Gist options
  • Save christosangelopoulos/e7f532264b9340ca666be91a53c927ec to your computer and use it in GitHub Desktop.
Save christosangelopoulos/e7f532264b9340ca666be91a53c927ec to your computer and use it in GitHub Desktop.
mpv script that logs metadata from Icecast streams
-- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment