mirror of
https://github.com/reality/dbot.git
synced 2025-01-11 12:32:36 +01:00
youtube link handle thing [#534]
This commit is contained in:
parent
d9d7d9bff7
commit
9dea85730d
3
modules/youtube/config.json
Normal file
3
modules/youtube/config.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"outputPrefix": "\u000305youtube\u000f"
|
||||
}
|
5
modules/youtube/strings.json
Normal file
5
modules/youtube/strings.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"yt_video": {
|
||||
"en": "[{title} by {author} — \u000312▶\u000f{plays} (\u00039▲{likes}\u000f|\u000312{dislikes}▼\u000f)]"
|
||||
}
|
||||
}
|
40
modules/youtube/youtube.js
Normal file
40
modules/youtube/youtube.js
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Module Name: youtube
|
||||
* Description: Various Youtube functionality
|
||||
*/
|
||||
var _ = require('underscore')._,
|
||||
request = require('request');
|
||||
|
||||
var youtube = function(dbot) {
|
||||
this.ApiRoot = 'https://gdata.youtube.com/feeds/api';
|
||||
this.params = {
|
||||
'alt': 'json',
|
||||
'v': 2
|
||||
};
|
||||
|
||||
this.onLoad = function() {
|
||||
dbot.api.link.addHandler(this.name,
|
||||
/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/,
|
||||
function(event, match, name) {
|
||||
request.get(this.ApiRoot + '/videos/' + match[2], {
|
||||
'qs': this.params,
|
||||
'json': true
|
||||
}, function(error, response, body) {
|
||||
if(_.isObject(body) && _.has(body, 'entry')) {
|
||||
var v = body.entry;
|
||||
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
|
||||
}));
|
||||
}
|
||||
});
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return new youtube(dbot);
|
||||
};
|
Loading…
Reference in New Issue
Block a user