Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit a926e26

Browse files
author
Zirak
committed
Fixed Youtube command (fixes #234)
/youtube now delegates to /google
1 parent c503d17 commit a926e26

File tree

3 files changed

+46
-62
lines changed

3 files changed

+46
-62
lines changed

master.js

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6887,40 +6887,32 @@ var nulls = [
68876887
'I could not find such a video',
68886888
'The Lords of YouTube did not find your query favorable' ];
68896889
function youtube ( args, cb ) {
6890-
IO.jsonp({
6891-
url : 'https://gdata.youtube.com/feeds/api/videos',
6892-
jsonpName : 'callback',
6893-
data : {
6894-
q : args.toString(),
6895-
'max-results' : 1,
6896-
v : 2,
6897-
alt : 'json'
6898-
},
6899-
fun : finish
6900-
});
6890+
IO.jsonp.google(
6891+
args.toString() + ' site:youtube.com', finishCall );
69016892

6902-
//the response looks something like this:
6903-
/*
6904-
{
6905-
tons of crap
6906-
"entry" : [{
6907-
lots of crap
6908-
"link" : [{
6909-
some crap
6910-
"href" : what we care about
6911-
}]
6912-
some more crap
6913-
}]
6914-
and then some more
6915-
}
6916-
*/
6917-
function finish ( resp ) {
6918-
var entry = resp.feed.entry;
6919-
if ( !entry || !entry.length ) {
6920-
args.reply( nulls.random() );
6893+
function finishCall ( resp ) {
6894+
if ( resp.responseStatus !== 200 ) {
6895+
finish( 'Something went on fire; status ' + resp.responseStatus );
6896+
return;
6897+
}
6898+
6899+
var result = resp.responseData.results[ 0 ];
6900+
bot.log( result, '/youtube result' );
6901+
6902+
if ( !result ) {
6903+
finish( nulls.random() );
69216904
}
69226905
else {
6923-
args.send( entry[0].link[0].href );
6906+
finish( decodeURIComponent(result.url) );
6907+
}
6908+
}
6909+
6910+
function finish ( res ) {
6911+
if ( cb && cb.call ) {
6912+
cb( res );
6913+
}
6914+
else {
6915+
args.directreply( res );
69246916
}
69256917
}
69266918
}

0 commit comments

Comments
 (0)