-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathkdialog.lua
More file actions
100 lines (92 loc) · 2.45 KB
/
kdialog.lua
File metadata and controls
100 lines (92 loc) · 2.45 KB
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 (KDialog)
---@author ObserverOfTime
---@license 0BSD
local utils = require 'mp.utils'
local xorg = os.getenv('XDG_SESSION_TYPE') == 'x11'
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',
}, ' ')
local ICON = 'mpv'
---@class KDOpts
---@field title string
---@field text string
---@field default? string
---@field type? string
---@field args string[]
---@param opts KDOpts
---@return fun()
local function KDialog(opts)
return function()
local path = mp.get_property('path')
path = path == nil and '' or utils.split_path(
utils.join_path(utils.getcwd(), path)
)
local args = {
'kdialog', opts.default or path,
'--title', opts.title,
'--icon', ICON,
'--multiple', '--separate-output',
opts.type or '--getopenfilename', opts.text,
}
local ontop = mp.get_property_native('ontop')
if xorg then
local focus = utils.subprocess {
args = {'xdotool', 'getwindowfocus'}
}.stdout:gsub('\n$', '')
table.insert(args, 5, '--attach')
table.insert(args, 6, focus)
end
mp.set_property_native('ontop', false)
local kdialog = utils.subprocess {
args = args, cancellable = false
}
mp.set_property_native('ontop', ontop)
if kdialog.status ~= 0 then return end
for file in kdialog.stdout:gmatch('[^\n]+') do
mp.commandv(opts.args[1], file, opts.args[2])
end
end
end
mp.add_key_binding('Ctrl+f', 'open-files', KDialog {
title = 'Select Files',
text = 'Multimedia Files ('..MULTIMEDIA..')',
args = {'loadfile', 'append-play'},
})
mp.add_key_binding('Ctrl+F', 'open-url', KDialog {
title = 'Open URL',
text = 'Enter the URL to open:',
default = '',
type = '--inputbox',
args = {'loadfile', 'replace'},
})
mp.add_key_binding('Alt+f', 'open-subs', KDialog {
title = 'Select Subs',
text = 'Subtitle Files ('..SUBTITLES..')',
args = {'sub-add', 'select'},
})