aboutsummaryrefslogtreecommitdiffstats
path: root/dotfiles/mpv/.config
diff options
context:
space:
mode:
authorshu <nvcsadjkojf@outlook.com>2026-10-27 15:35:47 +0800
committershu <nvcsadjkojf@outlook.com>2026-10-27 15:35:47 +0800
commit44d1af8b4e51d7c0fe9d9ecbb2f20d64cb34f095 (patch)
tree1ea732b5016001660113c3a0782c0ecb82f23689 /dotfiles/mpv/.config
parentafa43622a2b0d6322f5ade9fc8231e5540a96736 (diff)
按照需求梳理脚本功能
Diffstat (limited to 'dotfiles/mpv/.config')
-rw-r--r--dotfiles/mpv/.config/haruna/custom-commands.conf7
-rw-r--r--dotfiles/mpv/.config/mpv/scripts/embedded-lyrics.lua28
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)