From 26eebdab98a0488af1e42e6aa73a0a68fb396f37 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 25 Jul 2013 17:07:00 +0000 Subject: [PATCH] fix youtube search [#543] --- modules/youtube/youtube.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/youtube/youtube.js b/modules/youtube/youtube.js index 30bc33f..8de3c8d 100644 --- a/modules/youtube/youtube.js +++ b/modules/youtube/youtube.js @@ -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,