@@ -80,10 +80,10 @@ def youtube(text):
8080 json = requests .get (search_api_url , params = {"q" : text , "key" : dev_key }).json ()
8181
8282 if 'error' in json :
83- return 'error performing search'
83+ return 'Error performing search. '
8484
8585 if json ['pageInfo' ]['totalResults' ] == 0 :
86- return 'no results found'
86+ return 'No results found. '
8787
8888 video_id = json ['items' ][0 ]['id' ]['videoId' ]
8989
@@ -93,16 +93,16 @@ def youtube(text):
9393@hook .command ("youtime" , "ytime" )
9494def youtime (text ):
9595 """youtime <query> -- Gets the total run time of the first YouTube search result for <query>."""
96- json = requests .get (search_api_url , params = {"q" : text }).json ()
96+ json = requests .get (search_api_url , params = {"q" : text , "key" : dev_key }).json ()
9797
9898 if 'error' in json :
99- return 'error performing search'
99+ return 'Error performing search. '
100100
101- if json ['data ' ]['totalItems ' ] == 0 :
102- return 'no results found'
101+ if json ['pageInfo ' ]['totalResults ' ] == 0 :
102+ return 'No results found. '
103103
104- video_id = json ['data' ][ ' items' ][0 ]['id' ]
105- json = requests .get (api_url .format (video_id )).json ()
104+ video_id = json ['items' ][0 ]['id' ][ 'videoId ' ]
105+ json = requests .get (api_url .format (video_id , dev_key )).json ()
106106
107107 if json .get ('error' ):
108108 return
0 commit comments