mirror of https://github.com/calzoneman/sync.git
Implement serverside Google+ retrieval
This commit is contained in:
parent
052afaf2f6
commit
c522516b88
|
@ -2,7 +2,7 @@ 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");
|
||||
var id = link.replace(/https:\/\/plus\.google\.com\/photos\/(\d+)\/albums\/(\d+)\/(\d+)/, "$1_$2_$3");
|
||||
|
||||
gp(id, function (err, data) {
|
||||
if (err) console.error(err)
|
||||
|
|
|
@ -787,16 +787,21 @@ var Getters = {
|
|||
});
|
||||
},
|
||||
|
||||
/* google+ photo videos */
|
||||
/*
|
||||
* Google+ videos
|
||||
*
|
||||
* This is quite possibly the hackiest video metadata retrieval function
|
||||
* in CyTube.
|
||||
*/
|
||||
gp: function (id, cb) {
|
||||
id = id.split("_");
|
||||
if (id.length !== 2) {
|
||||
var idparts = id.split("_");
|
||||
if (idparts.length !== 3) {
|
||||
return cb("Invalid Google+ video ID");
|
||||
}
|
||||
|
||||
var options = {
|
||||
host: "plus.google.com",
|
||||
path: "/photos/" + id[0] + "/albums/" + id[1],
|
||||
path: "/photos/" + idparts[0] + "/albums/" + idparts[1] + "/" + idparts[2],
|
||||
port: 443
|
||||
};
|
||||
|
||||
|
@ -817,27 +822,38 @@ var Getters = {
|
|||
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 = {};
|
||||
var duration;
|
||||
var title;
|
||||
var startReading = false;
|
||||
var startReadingSentinel = new RegExp('"' + idparts[2] + '"');
|
||||
res.split("\n").filter(function (line) {
|
||||
/* Once the duration has been set, no more lines are relevant */
|
||||
if (duration) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var m = line.match(/"og:image" content="([^"]+)"/);
|
||||
if (m) {
|
||||
var parts = m[1].replace(/%25/g, "%")
|
||||
.replace(/%2B/ig, "%20").split("/");
|
||||
title = decodeURIComponent(parts[parts.length - 1]);
|
||||
}
|
||||
|
||||
/* Hack for only reading relevant video data */
|
||||
if (line.match(new RegExp(startReadingSentinel))) {
|
||||
startReading = true;
|
||||
}
|
||||
|
||||
if (!startReading) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m = line.match(/,(\d+),,"https:\/\/video\.googleusercontent/);
|
||||
if (m) {
|
||||
duration = parseInt(parseInt(m[1]) / 1000);
|
||||
}
|
||||
|
||||
return line.match(/videoplayback/);
|
||||
}).map(function (line) {
|
||||
var parts = line.match(/\[(\d+),(\d+),(\d+),("http:\/\/redirector.*?")\]/);
|
||||
|
@ -850,13 +866,11 @@ var Getters = {
|
|||
}).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);
|
||||
});
|
||||
|
||||
/*
|
||||
* Preference map of quality => youtube formats.
|
||||
* see https://en.wikipedia.org/wiki/Youtube#Quality_and_codecs
|
||||
*/
|
||||
const preference = {
|
||||
"hd1080": [46, 37],
|
||||
"hd720": [22, 45],
|
||||
|
@ -878,7 +892,8 @@ var Getters = {
|
|||
}
|
||||
}
|
||||
|
||||
cb(null, direct);
|
||||
var media = new Media(id, title, duration, "gp", { direct: direct });
|
||||
cb(null, media);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue