Last active
October 26, 2023 18:46
-
-
Save ipcjs/e568793fc7f06155e5db7320c7ca328d to your computer and use it in GitHub Desktop.
支持通过快捷键,装载滤镜型次字幕的mpv脚本
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
--[[ | |
SOURCE_ https://github.com/mpv-player/mpv/blob/master/TOOLS/lua/autoload.lua | |
COMMIT_ 3ba446d0b065f867ca262a2e05e4e8d24c7c0783 | |
SOURCE_ https://github.com/rossy/mpv-open-file-dialog/blob/master/open-file-dialog.lua | |
COMMIT_ 04fe818fc703d8c5dcc3a6aabe1caeed8286bdbb | |
文档_ https://github.com/hooke007/MPV_lazy/discussions/106 | |
示例:在 input.conf 中另起写入下列内容 | |
Ctrl+Alt+1 script-binding vf_sub/append_vfSub # 装载次字幕(滤镜型) | |
Ctrl+Alt+2 script-binding vf_sub/append_vfSub_2 # 装载文件中的第2个字幕(滤镜型) | |
Ctrl+Alt+3 script-binding vf_sub/append_vfSub_3 # 装载文件中的第3个字幕(滤镜型) | |
Ctrl+Alt+9 script-binding vf_sub/append_vfSub_9 # 装载文件中的第9个字幕(滤镜型) | |
E script-binding vf_sub/toggle_vfSub # 隐藏/显示 当前的次字幕(滤镜型) | |
CTRL+e script-binding vf_sub/remove_vfSub # 移除次字幕(滤镜型) | |
]] | |
local msg = require "mp.msg" | |
local options = require "mp.options" | |
local utils = require "mp.utils" | |
function append_vfSub(index) | |
local was_ontop = mp.get_property_native("ontop") | |
if was_ontop then mp.set_property_native("ontop", false) end | |
local res = utils.subprocess({ | |
args = { 'powershell', '-NoProfile', '-Command', [[& { | |
Trap { | |
Write-Error -ErrorRecord $_ | |
Exit 1 | |
} | |
Add-Type -AssemblyName PresentationFramework | |
$u8 = [System.Text.Encoding]::UTF8 | |
$out = [Console]::OpenStandardOutput() | |
$ofd = New-Object -TypeName Microsoft.Win32.OpenFileDialog | |
$ofd.Multiselect = $false | |
If ($ofd.ShowDialog() -eq $true) { | |
ForEach ($filename in $ofd.FileNames) { | |
$u8filename = $u8.GetBytes("$filename") | |
$out.Write($u8filename, 0, $u8filename.Length) | |
} | |
} | |
}]] }, | |
cancellable = false, | |
}) | |
if was_ontop then mp.set_property_native("ontop", true) end | |
if (res.status ~= 0) then return end | |
for filename in string.gmatch(res.stdout, '[^\n]+') do | |
local vfSub | |
if index then | |
vfSub = "vf append ``@LUA-load_plus:subtitles=filename=\"" .. res.stdout .. "\":stream_index=" .. index .. "``" | |
else | |
vfSub = "vf append ``@LUA-load_plus:subtitles=filename=\"" .. res.stdout .. "\"``" | |
end | |
mp.command(vfSub) | |
end | |
end | |
function filter_state(label, key, value) | |
local filters = mp.get_property_native("vf") | |
for _, filter in pairs(filters) do | |
if filter["label"] == label and (not key or key and filter[key] == value) then | |
return true | |
end | |
end | |
return false | |
end | |
function toggle_vfSub() | |
local vfSub = "vf toggle @LUA-load_plus" | |
if filter_state("LUA-load_plus") then mp.command(vfSub) end | |
end | |
function remove_vfSub() | |
local vfSub = "vf remove @LUA-load_plus" | |
if filter_state("LUA-load_plus") then mp.command(vfSub) end | |
end | |
mp.register_event("end-file", remove_vfSub) | |
mp.add_key_binding(nil, "append_vfSub", append_vfSub) | |
mp.add_key_binding(nil, "append_vfSub_2", function () append_vfSub(2) end) | |
mp.add_key_binding(nil, "append_vfSub_3", function () append_vfSub(3) end) | |
mp.add_key_binding(nil, "append_vfSub_9", function () append_vfSub(9) end) | |
mp.add_key_binding(nil, "toggle_vfSub", toggle_vfSub) | |
mp.add_key_binding(nil, "remove_vfSub", remove_vfSub) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment