- video_info = json.loads(respdata)
-
- title = video_info['entry']['title']["$t"]
- author = video_info['entry']['author'][0]['name']['$t']
-
- return "Youtube: %s (%s)" % (title, author)
+ v = json.loads(respdata)
+ v = v['items'][0]
+
+ return unescape(lib.parent.cfg.get('urls', 'yt_format', "\002%(author)s\002: \037%(title)s\037 [%(duration)s, uploaded %(uploaded)s, %(views)s v/%(likes)s l/%(dislikes)s d]") % {
+ 'title': v['snippet']['title'],
+ 'author': v['snippet']['channelTitle'],
+ 'duration': _yt_duration(v['contentDetails']['duration']),
+ 'uploaded': _yt_date(v['snippet']['publishedAt'], lib.parent.cfg.get('urls', 'yt_date_format', '%b %d %Y')),
+ 'views': _yt_round(v['statistics']['viewCount']),
+ 'likes': _yt_round(v['statistics']['likeCount']),
+ 'dislikes': _yt_round(v['statistics']['dislikeCount']),
+ })
+ except urllib2.HTTPError as e:
+ if e.getcode() == 403:
+ return 'API limit exceeded'
+ else:
+ return str(e)
+ except IndexError:
+ return 'no results'
+ except Exception as e:
+ return str(e)
+
+def gottwitch(uri):
+ url = 'https://api.twitch.tv/helix/streams?user_login=%s' % uri.split('/')[0]
+ opener = urllib2.build_opener()
+ opener.addheaders = [('Client-ID', lib.parent.cfg.get('urls', 'twitch_api_key'))]
+ respdata = opener.open(url).read()
+ twitch = json.loads(respdata)['data']
+ try:
+ # TODO: add current game.
+ return unescape('\037%s\037 is %s (%s)' % (twitch[0]['user_name'], twitch[0]['type'], twitch[0]['title']))