forked from GitHub/dbot
fix youtube search [#543]
This commit is contained in:
parent
55d8e9257e
commit
26eebdab98
@ -16,13 +16,12 @@ var youtube = function(dbot) {
|
|||||||
'~youtube': function(event) {
|
'~youtube': function(event) {
|
||||||
request.get(this.ApiRoot + '/videos', {
|
request.get(this.ApiRoot + '/videos', {
|
||||||
'qs': _.extend(this.params, {
|
'qs': _.extend(this.params, {
|
||||||
'q': encodeURIComponent(event.input[1]),
|
'q': event.input[1],
|
||||||
'max-results': 1
|
'max-results': 1
|
||||||
}),
|
}),
|
||||||
'json': true
|
'json': true
|
||||||
}, function(error, response, body) {
|
}, function(error, response, body) {
|
||||||
if(_.isObject(body) && _.has(body, 'feed') && _.has(body.feed,
|
if(_.isObject(body) && _.has(body, 'feed') && _.has(body.feed, 'entry')) {
|
||||||
'entry') && _.has(body.feed.entry[0], 'yt$statistics')) {
|
|
||||||
var v = body.feed.entry[0];
|
var v = body.feed.entry[0];
|
||||||
if(!_.has(v, 'yt$rating')) {
|
if(!_.has(v, 'yt$rating')) {
|
||||||
v['yt$rating'] = {
|
v['yt$rating'] = {
|
||||||
@ -30,6 +29,9 @@ var youtube = function(dbot) {
|
|||||||
'numDislikes': 0
|
'numDislikes': 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if(!_.has(v, 'yt$statistics')) {
|
||||||
|
v['yt$statistics'] = { 'viewCount': 0 };
|
||||||
|
}
|
||||||
event.reply(dbot.t('yt_video', {
|
event.reply(dbot.t('yt_video', {
|
||||||
'title': v.title['$t'],
|
'title': v.title['$t'],
|
||||||
'plays': v['yt$statistics'].viewCount,
|
'plays': v['yt$statistics'].viewCount,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user