From 44d1af8b4e51d7c0fe9d9ecbb2f20d64cb34f095 Mon Sep 17 00:00:00 2001 From: shu Date: Tue, 27 Oct 2026 15:35:47 +0800 Subject: 按照需求梳理脚本功能 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dotfiles/mpv/.config/haruna/custom-commands.conf | 7 ++++++ .../mpv/.config/mpv/scripts/embedded-lyrics.lua | 28 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 dotfiles/mpv/.config/haruna/custom-commands.conf create mode 100644 dotfiles/mpv/.config/mpv/scripts/embedded-lyrics.lua (limited to 'dotfiles/mpv') 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) -- cgit v1.2.3