Skip to content

Instantly share code, notes, and snippets.

@alecwbr
Forked from garoto/mpvhistory.lua
Last active November 16, 2023 07:53
Show Gist options
  • Save alecwbr/c84381559ded9ed8553dc53dc251b416 to your computer and use it in GitHub Desktop.
Save alecwbr/c84381559ded9ed8553dc53dc251b416 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.
-- Also adds a key binding to add an explicit current playing item to a favorite file.
-- Other changes are the string format and date format written to the log files
local CONFIG_DIR = (os.getenv("APPDATA") or os.getenv("HOME").."/.config");
local HISTFILE = CONFIG_DIR.."/mpv/icyhistory.log";
local FAVFILE = CONFIG_DIR.."/mpv/icyfavorites.log";
local function append_to_file(file, val)
local logfile;
if val ~= nil and val["icy-title"] then
logfile = io.open(file, "a+");
logfile:write(("%s | %s | %s\n"):format(os.date("%Y-%m-%d | %H:%M:%S"), val["icy-title"], val["icy-name"]));
logfile:close();
end
end
mp.observe_property("metadata", "native", function(name, val)
append_to_file(HISTFILE, val);
end)
mp.add_key_binding("h", "save_icy_title", function()
local val;
val = mp.get_property_native("metadata");
append_to_file(FAVFILE, val);
print(("saved '%s' to %s"):format(val["icy-title"], FAVFILE));
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment