Add support for youtube api v2 keys because v3 is a butt

This commit is contained in:
calzoneman 2013-08-03 16:13:19 -04:00
parent a26df3c92c
commit 2efd3f0db2
2 changed files with 25 additions and 4 deletions

View File

@ -36,7 +36,9 @@ var defaults = {
},
"mail-from" : "some.user@gmail.com",
"domain" : "http://localhost",
"ytapikey" : ""
"ytv3apikey" : "",
"enable-ytv3" : false,
"ytv2devkey" : ""
}
function save(cfg, file) {

View File

@ -34,7 +34,7 @@ module.exports = function (Server) {
var Getters = {
/* youtube.com */
yt: function (id, callback) {
if(Server.cfg["ytapikey"]) {
if(Server.cfg["enable-ytv3"] && Server.cfg["ytv3apikey"]) {
Getters["ytv3"](id, callback);
return;
}
@ -48,12 +48,18 @@ module.exports = function (Server) {
timeout: 1000
};
if(Server.cfg["ytv2devkey"]) {
options.headers = {
"X-Gdata-Key": "key=" + Server.cfg["ytv2devkey"]
};
}
urlRetrieve(https, options, function (status, data) {
if(status === 404) {
callback("Video not found", null);
return;
} else if(status === 403) {
callbacK("Private video", null);
callback("Private video", null);
return;
} else if(status !== 200) {
callback(true, null);
@ -154,11 +160,18 @@ module.exports = function (Server) {
timeout: 1000
};
if(Server.cfg["ytv2devkey"]) {
options.headers = {
"X-Gdata-Key": "key=" + Server.cfg["ytv2devkey"]
};
}
urlRetrieve(https, options, function (status, data) {
if(status === 404) {
callback("Playlist not found", null);
return;
} else if(status === 403) {
console.log(options.path);
callback("Playlist is private", null);
return;
} else if(status !== 200) {
@ -209,6 +222,12 @@ module.exports = function (Server) {
timeout: 1000
};
if(Server.cfg["ytv2devkey"]) {
options.headers = {
"X-Gdata-Key": "key=" + Server.cfg["ytv2devkey"]
};
}
urlRetrieve(https, options, function (status, data) {
if(status !== 200) {
callback(true, null);
@ -254,7 +273,7 @@ module.exports = function (Server) {
callback("Video not found", null);
return;
} else if(status === 403) {
callbacK("Private video", null);
callback("Private video", null);
return;
} else if(status !== 200) {
callback(true, null);