- video_info = json.loads(respdata)
-
- title = video_info['entry']['title']["$t"]
- author = video_info['entry']['author'][0]['name']['$t']
-
- return unescape("Youtube: %s (%s)" % (title, author))
- except:
- pass
+ 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)