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) |
In case you haven't noticed, mpv 0.30 loads .lrc files correctly, so this script is no longer necessary. :)
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
Sorry for the late response, I didn't get any notifications about comments on this.
Let's say you open multiple files (or a directory) with mpv, if one of those files has
.lrc
counterpart, this subtitle will be added in all subsequent files. However, my solution is more of a workaround, though. Because while setting thesub-files
option to an empty string will make the subtitles disappear, mpv will actually try to load a subtitle file named "" (an empty string), but will fail to do so, displaying an error in the terminal. I don't know what is the correct approach to unload the subtitles, but so far it works.Thanks for sharing your script!