-
Notifications
You must be signed in to change notification settings - Fork 1
/
youtube-search.lua
41 lines (36 loc) · 1.03 KB
/
youtube-search.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
--
-- Based on 'mpv-zenity-open-files'(https://github.com/alifarazz/mpv-zenity-open-files)
--
-- Default keybindings:
-- CTRL+SHIFT+s: search video in youtube.
--
table.unpack = table.unpack or unpack
utils = require 'mp.utils'
limit = 5
function get_focus_using_xdotool()
return utils.subprocess({
args = { 'xdotool', 'getwindowfocus' }
})
end
function invoke_zenity(args)
-- local focus = get_focus_using_xdotool()
return utils.subprocess({
args = { 'zenity', table.unpack(args) },
cancellable = false,
})
end
function search_youtube()
local url_select = invoke_zenity({
'--entry',
'--title=Search Youtube',
'--window-icon=mpv',
'--text=Enter Search Text:'
})
if (url_select.status ~= 0) then
return
end
for filename in string.gmatch(url_select.stdout, '[^\n]+') do
mp.commandv('loadfile', "ytdl://ytsearch" .. limit .. ":" .. filename, 'replace')
end
end
mp.add_key_binding("CTRL+SHIFT+s", "search_youtube", search_youtube)