-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyoutube.py
executable file
·71 lines (56 loc) · 1.57 KB
/
youtube.py
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
#!/bin/env python3
from sys import argv
from helpers import mbrofi
# user variables
# application variables
# launcher variables
msg = "Search on youtube."
prompt = "youtube:"
answer=""
sel=""
filt=""
index=0
bindings=[]
# run correct launcher with prompt and help message
launcher_args = {}
launcher_args['prompt'] = prompt
launcher_args['mesg'] = msg
launcher_args['filter'] = filt
launcher_args['bindings'] = bindings
launcher_args['index'] = index
def list_entries():
"""Return entries to be displayed in rofi."""
return([''])
def youtube(query):
"""Generate youtube search url from query"""
query.replace(" ", "+")
if query:
url = "https://www.youtube.com/results?search_query=" + query.strip()
print("Opening url in browser: " + query)
mbrofi.xdg_open(url)
else:
print("Empty query.")
def main(launcher_args):
"""Main function."""
while True:
answer, exit = mbrofi.rofi(list_entries(), launcher_args)
if exit == 1:
break
index, filt, sel = answer.strip().split(';')
launcher_args['filter'] = filt
launcher_args['index'] = index
if (exit == 0):
# this is the case where enter is pressed
youtube(filt)
break
elif (exit == 1):
# this is the case where rofi is escaped (should exit)
break
else:
break
if __name__ == "__main__":
if ( len(argv) > 1):
query = ''.join(str(e) + ' ' for e in argv[1:]).strip()
youtube(query)
else:
main(launcher_args)