@@ -6887,40 +6887,32 @@ var nulls = [
6887
6887
'I could not find such a video' ,
6888
6888
'The Lords of YouTube did not find your query favorable' ] ;
6889
6889
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 ) ;
6901
6892
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 ( ) ) ;
6921
6904
}
6922
6905
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 ) ;
6924
6916
}
6925
6917
}
6926
6918
}
0 commit comments