From 0f0877f27a2757bbcf9a61e4790f4c1ef95cc16d Mon Sep 17 00:00:00 2001 From: Scritches Date: Thu, 26 Apr 2018 16:50:21 -0400 Subject: [PATCH] Fixed YouTube video duration reporting --- modules/youtube/youtube.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/youtube/youtube.js b/modules/youtube/youtube.js index a661fe5..94a1d5c 100644 --- a/modules/youtube/youtube.js +++ b/modules/youtube/youtube.js @@ -23,20 +23,21 @@ var youtube = function(dbot) { }, 'json': true }, function(error, response, body) { - callback(body); + callback(body); }.bind(this)); } }; this.internalAPI = { 'formatLink': function(v) { - var time = v.contentDetails.duration.match(/^PT(\d+)?M?(\d+)S$/); + var time = v.contentDetails.duration.match(/^PT(?:(\d+)M)?(\d+)S$/); + if(time) { if(time[1]) { var seconds =((time[2]%60 < 10) ? "0"+time[2]%60 : time[2]%60), minutes = time[1]; } else { - var seconds =((time[1]%60 < 10) ? "0"+time[1]%60 : time[1]%60), + var seconds =((time[2]%60 < 10) ? "0"+time[2]%60 : time[2]%60), minutes = 0; } } else { @@ -61,18 +62,18 @@ var youtube = function(dbot) { return res; }.bind(this), - + 'formatPlaylistLink': function(v) { var res = dbot.t('yt_playlist', { 'title': v.snippet.title, 'author': v.snippet.channelTitle, 'videos': v.contentDetails.itemCount }); - + if (v.id) { res += " - https://www.youtube.com/playlist?list=" + v.id; } - + return res; } }; @@ -101,7 +102,7 @@ var youtube = function(dbot) { } }.bind(this), "video"); }, - + // search for a youtube playlist '~ytpl': function(event) { this.api.search(event.input[1], function(body) {