diff options
Diffstat (limited to 'dotfiles/mpv/.config')
| -rw-r--r-- | dotfiles/mpv/.config/haruna/custom-commands.conf | 7 | ||||
| -rw-r--r-- | dotfiles/mpv/.config/mpv/scripts/embedded-lyrics.lua | 28 |
2 files changed, 35 insertions, 0 deletions
diff --git a/dotfiles/mpv/.config/haruna/custom-commands.conf b/dotfiles/mpv/.config/haruna/custom-commands.conf new file mode 100644 index 0000000..bc4890d --- /dev/null +++ b/dotfiles/mpv/.config/haruna/custom-commands.conf @@ -0,0 +1,7 @@ +Counter=1 + +[Command_0] +Command=load-script "~/.config/mpv/scripts/embedded-lyrics.lua" +Order=0 +OsdMessage= +Type=startup diff --git a/dotfiles/mpv/.config/mpv/scripts/embedded-lyrics.lua b/dotfiles/mpv/.config/mpv/scripts/embedded-lyrics.lua new file mode 100644 index 0000000..9b9a705 --- /dev/null +++ b/dotfiles/mpv/.config/mpv/scripts/embedded-lyrics.lua @@ -0,0 +1,28 @@ +-- embedded-lyrics.lua +-- 尝试将音频文件内嵌的 LYRICS 标签作为字幕加载 + +local function load_embedded_lyrics() + local lyrics = mp.get_property("metadata/by-key/LYRICS") + + if not lyrics or lyrics == "" then + mp.msg.warn("未找到内嵌的 LYRICS 标签") + return + end + + -- 创建一个临时文件来存放歌词 + local tmp_path = os.tmpname() .. ".lrc" + local file = io.open(tmp_path, "w") + if not file then + mp.msg.error("无法创建临时文件") + return + end + file:write(lyrics) + file:close() + + -- 加载为字幕 + mp.commandv("sub-add", tmp_path, "select") + mp.msg.info("已从元数据加载内嵌歌词") +end + +-- 当文件加载完成时触发 +mp.register_event("file-loaded", load_embedded_lyrics) |
