Last active
August 1, 2020 08:12
-
-
Save 505e06b2/d4e5576c642acfe7abe75fc118373b4f to your computer and use it in GitHub Desktop.
Create text files for the currently played media in MPV
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
folder_dir = "/tmp/" --must have a slash proceding the location - lua doesn't have a pathing stdlib | |
--[[ | |
This is specifically for OBS, but can be altered pretty easily for other uses | |
It's mostly useful for documenting the MPV metadata grabbing functions, as they are a little bit of a hassle to find | |
Just to note, if a tag is not found, it will create a blank file - this should never happen with the title though | |
]]-- | |
function save_file(filename, metadata) | |
if not metadata then --metadata can be str or null | |
metadata = "" | |
end | |
f = io.open(folder_dir .. filename .. ".txt", "w") | |
metadata = metadata:gsub(" %[NCS Release%]", "") --Remove unnecessary info from Youtube title | |
f:write(metadata) --No newline, since OBS doesn't seem to like it | |
f:close() | |
end | |
function save_metadata() | |
local metadata = mp.get_property_native("metadata") | |
local x = {} | |
for key, value in pairs(metadata) do --keys can be in any case, or even mixed, so to make it more consistent, turn them all lowercase | |
x[key:lower()] = value | |
end | |
save_file("np_title", mp.get_property("media-title")) | |
save_file("np_artist", x["artist"]) | |
save_file("np_album", x["album"]) | |
end | |
mp.register_event("playback-restart", save_metadata) --this event is fired whenever "play" is - essentially (re)start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment