@hook.command('youtime', 'ytime')
def youtime(text):
 if (not dev_key):
  return 'This command requires a Google Developers Console API key.'
 json = requests.get(search_api_url, params={'q': text, 'key': dev_key, 'type': 'video'}).json()
 if json.get('error'):
  if (json['error']['code'] == 403):
   return err_no_api
  else:
   return 'Error performing search.'
 if (json['pageInfo']['totalResults'] == 0):
  return 'No results found.'
 video_id = json['items'][0]['id']['videoId']
 json = requests.get(api_url.format(video_id, dev_key)).json()
 if json.get('error'):
  return
 data = json['items']
 snippet = data[0]['snippet']
 content_details = data[0]['contentDetails']
 statistics = data[0]['statistics']
 if (not content_details.get('duration')):
  return
 length = isodate.parse_duration(content_details['duration'])
 l_sec = int(length.total_seconds())
 views = int(statistics['viewCount'])
 total = int((l_sec * views))
 length_text = timeformat.format_time(l_sec, simple=True)
 total_text = timeformat.format_time(total, accuracy=8)
 return 'The video \x02{}\x02 has a length of {} and has been viewed {:,} times for a total run time of {}!'.format(snippet['title'], length_text, views, total_text)

@ hook . command ( 'youtime' , 'ytime' ) def youtime ( text ) : if ( not dev_key ) : return 'This command requires a Google Developers Console API key.' json = requests . get ( search_api_url , params = { 'q' : text , 'key' : dev_key , 'type' : 'video' } ) . json ( ) if json . get ( 'error' ) : if ( json [ 'error' ] [ 'code' ] == 403 ) : return err_no_api else : return 'Error performing search.' if ( json [ 'pageInfo' ] [ 'totalResults' ] == 0 ) : return 'No results found.' video_id = json [ 'items' ] [ 0 ] [ 'id' ] [ 'videoId' ] json = requests . get ( api_url . format ( video_id , dev_key ) ) . json ( ) if json . get ( 'error' ) : return data = json [ 'items' ] snippet = data [ 0 ] [ 'snippet' ] content_details = data [ 0 ] [ 'contentDetails' ] statistics = data [ 0 ] [ 'statistics' ] if ( not content_details . get ( 'duration' ) ) : return length = isodate . parse_duration ( content_details [ 'duration' ] ) l_sec = int ( length . total_seconds ( ) ) views = int ( statistics [ 'viewCount' ] ) total = int ( ( l_sec * views ) ) length_text = timeformat . format_time ( l_sec , simple = True ) total_text = timeformat . format_time ( total , accuracy = 8 ) return 'The video \x02{}\x02 has a length of {} and has been viewed {:,} times for a total run time of {}!' . format ( snippet [ 'title' ] , length_text , views , total_text )
youtime <query> -- gets the total run time of the first youtube search result for <query> .