Skip to content

Instantly share code, notes, and snippets.

@guixxx
Last active December 1, 2019 22:22
Show Gist options
  • Save guixxx/a349d27d271ca100685c3ce5fb1d5c9f to your computer and use it in GitHub Desktop.
Save guixxx/a349d27d271ca100685c3ce5fb1d5c9f to your computer and use it in GitHub Desktop.
(DEPRECATED) Automatically loads lyric (.lrc) files to mpv if they're found
-- NOTE: This script is no longer necessary as of mpv 0.30.0!
loaded = false
function search_and_load_lrc()
local lrc_path = ext2lrc(mp.get_property("path"))
local file = io.open(lrc_path, "r")
if file ~= nil then
io.close(file)
mp.set_property("sub-files", lrc_path)
loaded = true
end
end
function unload_lrc()
if loaded == true then
mp.set_property("sub-files", "")
loaded = false
end
end
function ext2lrc(path)
-- strip the old extension with an empty string, then add the ".lrc" later,
-- otherwise this will fail on files with no extension
local name = path:gsub("(%..+)$", "")
return name .. ".lrc"
end
mp.register_event("start-file", search_and_load_lrc)
mp.register_event("end-file", unload_lrc)
@guidocella
Copy link

In case you haven't noticed, mpv 0.30 loads .lrc files correctly, so this script is no longer necessary. :)

@guixxx
Copy link
Author

guixxx commented Dec 1, 2019

Thanks for the heads up! I've changed the script title and I've added a note in the script too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment