@@ -61,22 +61,24 @@ def tell_me_about(cls, voice_transcript, skill):
61
61
def open_in_youtube (cls , voice_transcript , skill ):
62
62
"""
63
63
Open a video in youtube.
64
- :param voice_transcript: string (e.g 'about google ')
64
+ :param voice_transcript: string (e.g 'play mozart ')
65
65
:param skill: dict (e.g
66
66
"""
67
67
68
68
tags = cls .extract_tags (voice_transcript , skill ['tags' ])
69
69
for tag in tags :
70
- reg_ex = re .search (tag + ' ([a-zA-Z]+)' , voice_transcript )
70
+ reg_ex = re .search (tag + ' (.*)' , voice_transcript )
71
+
71
72
try :
72
73
if reg_ex :
73
74
search_text = reg_ex .group (1 )
74
- base = "https://www.youtube.com/results?search_query=" + " &orderby=viewCount"
75
- r = requests .get (base + search_text .replace (' ' , '+' ))
75
+ base = "https://www.youtube.com/results?search_query={0} &orderby=viewCount"
76
+ r = requests .get (base . format ( search_text .replace (' ' , '+' ) ))
76
77
page = r .text
77
78
soup = bs (page , 'html.parser' )
78
79
vids = soup .findAll ('a' , attrs = {'class' : 'yt-uix-tile-link' })
79
- video = 'https://www.youtube.com' + vids [0 ]['href' ]
80
+ video = 'https://www.youtube.com' + vids [0 ]['href' ] + "&autoplay=1"
81
+ cls .console (info_log = "Play Youtube video: {0}" .format (video ))
80
82
subprocess .Popen (["python" , "-m" , "webbrowser" , "-t" , video ], stdout = subprocess .PIPE , shell = False )
81
83
except Exception as e :
82
84
cls .console (error_log = "Error with the execution of skill with message {0}" .format (e ))
0 commit comments