|
| 1 | +utils = require 'mp.utils' |
| 2 | + |
| 3 | +MULTIMEDIA = table.concat({ |
| 4 | + '*.aac', |
| 5 | + '*.avi', |
| 6 | + '*.flac', |
| 7 | + '*.flv', |
| 8 | + '*.m3u', |
| 9 | + '*.m3u8', |
| 10 | + '*.m4v', |
| 11 | + '*.mkv', |
| 12 | + '*.mov', |
| 13 | + '*.mp3', |
| 14 | + '*.mp4', |
| 15 | + '*.mpeg', |
| 16 | + '*.mpg', |
| 17 | + '*.oga', |
| 18 | + '*.ogg', |
| 19 | + '*.ogv', |
| 20 | + '*.opus', |
| 21 | + '*.wav', |
| 22 | + '*.webm', |
| 23 | + '*.wmv', |
| 24 | +}, ' ') |
| 25 | + |
| 26 | +SUBTITLES = table.concat({ |
| 27 | + '*.ass', |
| 28 | + '*.srt', |
| 29 | + '*.ssa', |
| 30 | + '*.sub', |
| 31 | + '*.txt', |
| 32 | +}, ' ') |
| 33 | + |
| 34 | +ICON = 'mpv' |
| 35 | + |
| 36 | +function KDialog(opts) |
| 37 | + return function() |
| 38 | + local path = mp.get_property('path') |
| 39 | + path = path == nil and '' or utils.split_path( |
| 40 | + utils.join_path(mp.getcwd(), path) |
| 41 | + ) |
| 42 | + local ontop = mp.get_property_native('ontop') |
| 43 | + local focus = utils.subprocess { |
| 44 | + args = {'xdotool', 'getwindowfocus'} |
| 45 | + }.stdout:gsub('\n$', '') |
| 46 | + mp.set_property_native('ontop', false) |
| 47 | + local kdialog = utils.subprocess { |
| 48 | + args = { |
| 49 | + 'kdialog', opts.default or path, |
| 50 | + '--title', opts.title, |
| 51 | + '--attach', focus, |
| 52 | + '--icon', ICON, |
| 53 | + '--multiple', '--separate-output', |
| 54 | + opts.type or '--getopenfilename', opts.text, |
| 55 | + }, cancellable = false, |
| 56 | + } |
| 57 | + mp.set_property_native('ontop', ontop) |
| 58 | + if kdialog.status ~= 0 then return end |
| 59 | + for file in string.gmatch(kdialog.stdout, '[^\n]+') do |
| 60 | + mp.commandv(opts.args[1], file, opts.args[2]) |
| 61 | + end |
| 62 | + end |
| 63 | +end |
| 64 | + |
| 65 | +mp.add_key_binding('Ctrl+f', 'open-files', KDialog { |
| 66 | + title = 'Select Files', |
| 67 | + text = 'Multimedia Files ('..MULTIMEDIA..')', |
| 68 | + args = {'loadfile', 'append-play'}, |
| 69 | +}) |
| 70 | +mp.add_key_binding('Ctrl+F', 'open-url', KDialog { |
| 71 | + title = 'Open URL', |
| 72 | + text = 'Enter the URL to open:', |
| 73 | + default = '', |
| 74 | + type = '--inputbox', |
| 75 | + args = {'loadfile', 'replace'}, |
| 76 | +}) |
| 77 | +mp.add_key_binding('Alt+f', 'open-subs', KDialog { |
| 78 | + title = 'Select Subs', |
| 79 | + text = 'Subtitle Files ('..SUBTITLES..')', |
| 80 | + args = {'sub-add', 'select'}, |
| 81 | +}) |
0 commit comments