forked from GitHub/dbot
Fixed YouTube video duration reporting
This commit is contained in:
parent
f7b83e98b7
commit
0f0877f27a
@ -23,20 +23,21 @@ var youtube = function(dbot) {
|
|||||||
},
|
},
|
||||||
'json': true
|
'json': true
|
||||||
}, function(error, response, body) {
|
}, function(error, response, body) {
|
||||||
callback(body);
|
callback(body);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.internalAPI = {
|
this.internalAPI = {
|
||||||
'formatLink': function(v) {
|
'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) {
|
||||||
if(time[1]) {
|
if(time[1]) {
|
||||||
var seconds =((time[2]%60 < 10) ? "0"+time[2]%60 : time[2]%60),
|
var seconds =((time[2]%60 < 10) ? "0"+time[2]%60 : time[2]%60),
|
||||||
minutes = time[1];
|
minutes = time[1];
|
||||||
} else {
|
} 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;
|
minutes = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -61,18 +62,18 @@ var youtube = function(dbot) {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
|
|
||||||
'formatPlaylistLink': function(v) {
|
'formatPlaylistLink': function(v) {
|
||||||
var res = dbot.t('yt_playlist', {
|
var res = dbot.t('yt_playlist', {
|
||||||
'title': v.snippet.title,
|
'title': v.snippet.title,
|
||||||
'author': v.snippet.channelTitle,
|
'author': v.snippet.channelTitle,
|
||||||
'videos': v.contentDetails.itemCount
|
'videos': v.contentDetails.itemCount
|
||||||
});
|
});
|
||||||
|
|
||||||
if (v.id) {
|
if (v.id) {
|
||||||
res += " - https://www.youtube.com/playlist?list=" + v.id;
|
res += " - https://www.youtube.com/playlist?list=" + v.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -101,7 +102,7 @@ var youtube = function(dbot) {
|
|||||||
}
|
}
|
||||||
}.bind(this), "video");
|
}.bind(this), "video");
|
||||||
},
|
},
|
||||||
|
|
||||||
// search for a youtube playlist
|
// search for a youtube playlist
|
||||||
'~ytpl': function(event) {
|
'~ytpl': function(event) {
|
||||||
this.api.search(event.input[1], function(body) {
|
this.api.search(event.input[1], function(body) {
|
||||||
|
Loading…
Reference in New Issue
Block a user