mirror of https://github.com/calzoneman/sync.git
Merge pull request #439 from Xaekai/3.0
Google+ metadata retrieval overhaul
This commit is contained in:
commit
8c33818b36
|
@ -138,6 +138,9 @@ MediaRefresherModule.prototype.initGooglePlus = function (media, cb) {
|
||||||
case "HTTP 302":
|
case "HTTP 302":
|
||||||
case "Video not found":
|
case "Video not found":
|
||||||
case "Private video":
|
case "Private video":
|
||||||
|
case "The video is still being processed.":
|
||||||
|
case "A processing error has occured and the video should be deleted.":
|
||||||
|
case "The video has been processed but still needs a thumbnail.":
|
||||||
case "Unable to retreive duration from Google+. This might be because the video is still processing.":
|
case "Unable to retreive duration from Google+. This might be because the video is still processing.":
|
||||||
self.channel.logger.log("[mediarefresher] Google+ refresh failed: " +
|
self.channel.logger.log("[mediarefresher] Google+ refresh failed: " +
|
||||||
err);
|
err);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
var https = require("https");
|
var https = require("https");
|
||||||
|
var cheerio = require('cheerio');
|
||||||
var Logger = require("./logger.js");
|
var Logger = require("./logger.js");
|
||||||
var Media = require("./media");
|
var Media = require("./media");
|
||||||
var CustomEmbedFilter = require("./customembed").filter;
|
var CustomEmbedFilter = require("./customembed").filter;
|
||||||
|
@ -794,8 +795,8 @@ var Getters = {
|
||||||
/*
|
/*
|
||||||
* Google+ videos
|
* Google+ videos
|
||||||
*
|
*
|
||||||
* This is quite possibly the hackiest video metadata retrieval function
|
* Also known as Picasa Web Albums.
|
||||||
* in CyTube.
|
*
|
||||||
*/
|
*/
|
||||||
gp: function (id, cb) {
|
gp: function (id, cb) {
|
||||||
var idparts = id.split("_");
|
var idparts = id.split("_");
|
||||||
|
@ -804,8 +805,8 @@ var Getters = {
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
host: "plus.google.com",
|
host: "picasaweb.google.com",
|
||||||
path: "/photos/" + idparts[0] + "/albums/" + idparts[1] + "/" + idparts[2],
|
path: '/data/feed/api/user/'+idparts[0]+'/albumid/'+idparts[1]+'/photoid/'+idparts[2]+'?kind=tag',
|
||||||
port: 443
|
port: 443
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -827,54 +828,29 @@ var Getters = {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
var $ = cheerio.load(res, { xmlMode: true });
|
||||||
|
switch ($("gphoto\\:videostatus").text()) {
|
||||||
|
case "final":
|
||||||
|
break; /* Incoming Fun. */
|
||||||
|
case "pending":
|
||||||
|
return cb("The video is still being processed.", null);
|
||||||
|
case "failed":
|
||||||
|
return cb("A processing error has occured and the video should be deleted.", null);
|
||||||
|
case "ready":
|
||||||
|
return cb("The video has been processed but still needs a thumbnail.", null);
|
||||||
|
}
|
||||||
|
var duration = parseInt($("gphoto\\:originalvideo").attr("duration"),10);
|
||||||
|
var title = $("media\\:title").text();
|
||||||
var videos = {};
|
var videos = {};
|
||||||
var duration;
|
$('media\\:content[medium="video"]').each(function(index, element){
|
||||||
var title;
|
var url = $(this).attr("url")
|
||||||
var startReading = false;
|
var type = url.match(/itag=(\d\d)/)[1]
|
||||||
var startReadingSentinel = new RegExp('"' + idparts[2] + '"');
|
videos[type] = {
|
||||||
res.split("\n").filter(function (line) {
|
format: type,
|
||||||
/* Once the duration has been set, no more lines are relevant */
|
link: url
|
||||||
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(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+),("https?:\/\/redirector.*?")\]/);
|
|
||||||
if (!parts) {
|
|
||||||
return cb("Video entry did not match expected format: " + line, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
|
$ = null;
|
||||||
|
|
||||||
var direct = {};
|
var direct = {};
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcrypt": "^0.8.1",
|
"bcrypt": "^0.8.1",
|
||||||
"body-parser": "^1.10.2",
|
"body-parser": "^1.10.2",
|
||||||
|
"cheerio" : "^0.18.0",
|
||||||
"compression": "^1.3.0",
|
"compression": "^1.3.0",
|
||||||
"cookie-parser": "^1.3.3",
|
"cookie-parser": "^1.3.3",
|
||||||
"cytubefilters": "git://github.com/calzoneman/cytubefilters#33b7693c",
|
"cytubefilters": "git://github.com/calzoneman/cytubefilters#33b7693c",
|
||||||
|
|
Loading…
Reference in New Issue