Last active
December 1, 2019 22:22
-
-
Save guixxx/a349d27d271ca100685c3ce5fb1d5c9f to your computer and use it in GitHub Desktop.
(DEPRECATED) Automatically loads lyric (.lrc) files to mpv if they're found
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
-- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the heads up! I've changed the script title and I've added a note in the script too.