mirror of
https://github.com/reality/dbot.git
synced 2024-12-24 03:33:07 +01:00
youtube search
This commit is contained in:
parent
cd93987919
commit
f2d93d2f18
@ -1,5 +1,8 @@
|
||||
{
|
||||
"yt_video": {
|
||||
"en": "[{title} by {author} — \u000312▶\u000f{plays} (\u00039▲{likes}\u000f|\u000312{dislikes}▼\u000f)]"
|
||||
},
|
||||
"yt_noresults": {
|
||||
"en": "No results found."
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,32 @@ var youtube = function(dbot) {
|
||||
'v': 2
|
||||
};
|
||||
|
||||
this.commands = {
|
||||
'~youtube': function(event) {
|
||||
request.get(this.ApiRoot + '/videos', {
|
||||
'qs': _.extend(this.params, {
|
||||
'q': encodeURIComponent(event.input[1]),
|
||||
'max-results': 1
|
||||
}),
|
||||
'json': true
|
||||
}, function(error, response, body) {
|
||||
if(_.isObject(body) && _.has(body, 'feed') && _.has(body.feed, 'entry')) {
|
||||
var v = body.feed.entry[0];
|
||||
event.reply(dbot.t('yt_video', {
|
||||
'title': v.title['$t'],
|
||||
'plays': v['yt$statistics'].viewCount,
|
||||
'author': v.author[0].name['$t'],
|
||||
'likes': v['yt$rating'].numLikes,
|
||||
'dislikes': v['yt$rating'].numDislikes
|
||||
}));
|
||||
} else {
|
||||
event.reply(dbot.t('yt_noresults'));
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
this.commands['~youtube'].regex = [/^~youtube (.+)$/, 2];
|
||||
|
||||
this.onLoad = function() {
|
||||
dbot.api.link.addHandler(this.name,
|
||||
/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/,
|
||||
|
Loading…
Reference in New Issue
Block a user