3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-24 11:42:36 +01:00

fix youtube search [#543]

This commit is contained in:
reality 2013-07-25 17:07:00 +00:00
parent 55d8e9257e
commit 26eebdab98

View File

@ -16,13 +16,12 @@ var youtube = function(dbot) {
'~youtube': function(event) {
request.get(this.ApiRoot + '/videos', {
'qs': _.extend(this.params, {
'q': encodeURIComponent(event.input[1]),
'q': event.input[1],
'max-results': 1
}),
'json': true
}, function(error, response, body) {
if(_.isObject(body) && _.has(body, 'feed') && _.has(body.feed,
'entry') && _.has(body.feed.entry[0], 'yt$statistics')) {
if(_.isObject(body) && _.has(body, 'feed') && _.has(body.feed, 'entry')) {
var v = body.feed.entry[0];
if(!_.has(v, 'yt$rating')) {
v['yt$rating'] = {
@ -30,6 +29,9 @@ var youtube = function(dbot) {
'numDislikes': 0
};
}
if(!_.has(v, 'yt$statistics')) {
v['yt$statistics'] = { 'viewCount': 0 };
}
event.reply(dbot.t('yt_video', {
'title': v.title['$t'],
'plays': v['yt$statistics'].viewCount,