-
Notifications
You must be signed in to change notification settings - Fork 158
/
open_dialog.lua
190 lines (175 loc) · 6.27 KB
/
open_dialog.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
--[[
SOURCE_ https://github.com/rossy/mpv-open-file-dialog
COMMIT_ 20160310 04fe818
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty. See
<https://creativecommons.org/publicdomain/zero/1.0/> for a copy of the CC0
Public Domain Dedication, which applies to this software.
自定义快捷键 在mpv中唤起一个打开文件的窗口用于快速加载文件/网址
示例:在 input.conf 中另起写入下列内容
w script-binding open_dialog/import_files # 打开文件
W script-binding open_dialog/import_url # 载入网址
CTRL+w script-binding open_dialog/append_aid # 加载其它音轨(不切换)
ALT+w script-binding open_dialog/append_sid # 加载其它字幕(切换)
e script-binding open_dialog/append_vfSub # 装载次字幕(滤镜型)
E script-binding open_dialog/toggle_vfSub # 隐藏/显示 当前的次字幕
CTRL+e script-binding open_dialog/remove_vfSub # 移除次字幕
]]--
utils = require 'mp.utils'
function import_files()
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 = $true
If ($ofd.ShowDialog() -eq $true) {
ForEach ($filename in $ofd.FileNames) {
$u8filename = $u8.GetBytes("$filename`n")
$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
local first_file = true
for filename in string.gmatch(res.stdout, '[^\n]+') do
mp.commandv('loadfile', filename, first_file and 'replace' or 'append')
first_file = false
end
end
function import_url()
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 Microsoft.VisualBasic
$u8 = [System.Text.Encoding]::UTF8
$out = [Console]::OpenStandardOutput()
$urlname = [Microsoft.VisualBasic.Interaction]::InputBox("输入地址", "打开", "https://")
$u8urlname = $u8.GetBytes("$urlname")
$out.Write($u8urlname, 0, $u8urlname.Length)
}]]},
cancellable = false,
})
if was_ontop then mp.set_property_native("ontop", true) end
if (res.status ~= 0) then return end
mp.commandv('loadfile', res.stdout)
end
function append_aid()
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
mp.commandv('audio-add', filename, 'auto')
end
end
function append_sid()
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
mp.commandv('sub-add', filename, 'cached')
end
end
function append_vfSub()
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 = "vf append ``@LUA-open_dialog:subtitles=filename=\"" .. res.stdout .. "\"``"
mp.command(vfSub)
end
end
function toggle_vfSub()
local vfSub = "vf toggle @LUA-open_dialog"
mp.command(vfSub)
end
function remove_vfSub()
local vfSub = "vf remove @LUA-open_dialog"
mp.command(vfSub)
end
mp.add_key_binding(nil, 'import_files', import_files)
mp.add_key_binding(nil, 'import_url', import_url)
mp.add_key_binding(nil, 'append_aid', append_aid)
mp.add_key_binding(nil, 'append_sid', append_sid)
mp.add_key_binding(nil, 'append_vfSub', append_vfSub)
mp.add_key_binding(nil, 'toggle_vfSub', toggle_vfSub)
mp.add_key_binding(nil, 'remove_vfSub', remove_vfSub)