-
-
Save guixxx/a349d27d271ca100685c3ce5fb1d5c9f to your computer and use it in GitHub Desktop.
-- 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) |
Sorry for the late response, I didn't get any notifications about comments on this.
why are is necessary to set the property to nothing when mpv ends streaming the file?
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 the sub-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!
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.
damn it's
sub-files
,sub-file
andsub-files-append
didn't work..here's my code:
why are is necessary to set the property to nothing when mpv ends streaming the file?