-
-
Save alecwbr/c84381559ded9ed8553dc53dc251b416 to your computer and use it in GitHub Desktop.
mpv script that logs metadata from Icecast streams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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