Start working on google+ support

This commit is contained in:
Calvin Montgomery 2014-07-09 20:41:11 -07:00
parent b28fd9e4a8
commit 052afaf2f6
3 changed files with 119 additions and 0 deletions

8
gdocstest.js Normal file
View file

@ -0,0 +1,8 @@
var gi = require('./lib/get-info');
var gd = gi.Getters.gd;
gd(process.argv[2], function (err, data) {
if (err) console.error(err)
else console.log(data.meta.params.map(function (p) { return decodeURIComponent(p.value); }));
process.exit(0);
});

11
gptest.js Normal file
View file

@ -0,0 +1,11 @@
var gi = require('./lib/get-info');
var gp = gi.Getters.gp;
var link = process.argv[2];
var id = link.replace(/https:\/\/plus\.google\.com\/photos\/(\d+)\/albums\/(\d+)/, "$1_$2");
gp(id, function (err, data) {
if (err) console.error(err)
else console.log(data);
process.exit(0);
});

View file

@ -715,6 +715,11 @@ var Getters = {
});
data = "[" + data + "]";
var js = JSON.parse(data);
if (js[1].videoplay.status === "QUOTA_DENIED") {
return callback("Google Docs error: Video has exceeded quota", null);
}
var title = js[0].title;
var seconds = js[1].videodetails.duration / 1000;
var meta = {};
@ -780,6 +785,101 @@ var Getters = {
});
cb(null, m);
});
},
/* google+ photo videos */
gp: function (id, cb) {
id = id.split("_");
if (id.length !== 2) {
return cb("Invalid Google+ video ID");
}
var options = {
host: "plus.google.com",
path: "/photos/" + id[0] + "/albums/" + id[1],
port: 443
};
urlRetrieve(https, options, function (status, res) {
switch (status) {
case 200:
break; /* Request is OK, skip to handling data */
case 400:
return callback("Invalid request", null);
case 403:
return callback("Private video", null);
case 404:
return callback("Video not found", null);
case 500:
case 503:
return callback("Service unavailable", null);
default:
return callback("HTTP " + status, null);
}
res = res.replace(/\s/g, "");
var results = res.match(/<script>(.*?)<\/script>/g);
var data = results.filter(function (script) {
return script.match(/key:'126'/);
})[0];
data = JSON.parse(
data.replace(/<\/?script>/g, "")
.replace(/'/g, '"')
.replace(/^[^d]*data:/g, "")
.replace(/\}\);$/, "")
.replace(/,+/g, ",")
.replace(/\[,/g, "[")
);
var title = data[2][1];
return;
var videos = {};
res.split("\n").filter(function (line) {
return line.match(/videoplayback/);
}).map(function (line) {
var parts = line.match(/\[(\d+),(\d+),(\d+),("http:\/\/redirector.*?")\]/);
return {
format: parseInt(parts[1]),
width: parseInt(parts[2]),
height: parseInt(parts[3]),
link: JSON.parse(parts[4])
};
}).forEach(function (video) {
videos[video.format] = video;
});
res.split("\n").filter(function (line) {
return line.match(/video\.googleusercontent\.com/);
}).forEach(function (line) {
console.log(line);
});
const preference = {
"hd1080": [46, 37],
"hd720": [22, 45],
"large": [44, 35],
"medium": [43, 18],
"small": [5]
};
var direct = {};
for (var key in preference) {
for (var i = 0; i < preference[key].length; i++) {
var format = preference[key][i];
if (format in videos) {
direct[key] = videos[format].link;
break;
}
}
}
cb(null, direct);
});
}
};