-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
powershell.lua
100 lines (94 loc) · 2.64 KB
/
powershell.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
---Launch a dialog for opening files or URLs (PowerShell)
---@author ObserverOfTime
---@license 0BSD
local utils = require 'mp.utils'
local MULTIMEDIA = table.concat({
'*.aac',
'*.avi',
'*.flac',
'*.flv',
'*.m3u',
'*.m3u8',
'*.m4v',
'*.mkv',
'*.mov',
'*.mp3',
'*.mp4',
'*.mpeg',
'*.mpg',
'*.oga',
'*.ogg',
'*.ogv',
'*.opus',
'*.wav',
'*.webm',
'*.wmv',
}, ';')
local SUBTITLES = table.concat({
'*.ass',
'*.srt',
'*.ssa',
'*.sub',
'*.txt',
}, ';')
---@class PSOpts
---@field title string
---@field text string
---@field args string[]
---@field template? string
---@param opts PSOpts
---@return fun()
local function PowerShell(opts)
return function()
local template = opts.template or [[& {
Add-Type -AssemblyName System.Windows.Forms;
[Windows.Forms.Application]::EnableVisualStyles();
$dialog = New-Object Windows.Forms.OpenFileDialog;
$dialog.Filter = %q;
$dialog.Title = %q;
$dialog.InitialDirectory = %q;
$dialog.Multiselect = $true;
$dialog.ShowHelp = $true;
$dialog.ShowDialog() > $null;
Write-Output $dialog.FileNames;
$dialog.Dispose();
}]]
local path = mp.get_property('path')
path = path == nil and '' or utils.split_path(
utils.join_path(utils.getcwd(), path)
)
local ontop = mp.get_property_native('ontop')
mp.set_property_native('ontop', false)
local powershell = utils.subprocess {
args = {
'powershell', '-NoProfile', '-Command',
template:format(opts.text, opts.title, path)
}, cancellable = false
}
mp.set_property_native('ontop', ontop)
if powershell.status ~= 0 then return end
for file in powershell.stdout:gmatch('[^\r\n]+') do
mp.commandv(opts.args[1], file, opts.args[2])
end
end
end
mp.add_key_binding('Ctrl+f', 'open-files', PowerShell {
title = 'Select Files',
text = 'Multimedia Files|'..MULTIMEDIA,
args = {'loadfile', 'append-play'},
})
mp.add_key_binding('Ctrl+F', 'open-url', PowerShell {
title = 'Open URL',
text = 'Enter the URL to open:',
args = {'loadfile', 'replace'},
template = [[& {
Add-Type -AssemblyName Microsoft.VisualBasic;
$url = [Microsoft.VisualBasic.Interaction]::InputBox(%q, %q);
Write-Output $url;
}]],
})
mp.add_key_binding('Alt+f', 'open-subs', PowerShell {
title = 'Select Subs',
text = 'Subtitle Files|'..SUBTITLES,
args = {'sub-add', 'select'},
})