forked from GauravSingh9356/J.A.R.V.I.S
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube.py
29 lines (21 loc) · 762 Bytes
/
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
from urllib.request import urlopen
import urllib.parse
import webbrowser
from sys import platform
import os
if platform == "linux" or platform == "linux2":
chrome_path = '/usr/bin/google-chrome'
elif platform == "darwin":
chrome_path = 'open -a /Applications/Google\ Chrome.app'
elif platform == "win32":
chrome_path = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
else:
print('Unsupported OS')
exit(1)
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path))
def youtube(textToSearch):
query = urllib.parse.quote(textToSearch)
url = "https://www.youtube.com/results?search_query=" + query
webbrowser.get('chrome').open_new_tab(url)
if __name__ == '__main__':
youtube('any text')