I commit this code in the name of Pinkie Pie.

This commit is contained in:
Xaekai 2015-02-13 05:11:28 -08:00
parent 4ec61da811
commit 26a9446d3d
3 changed files with 29 additions and 49 deletions

View File

@ -138,6 +138,9 @@ MediaRefresherModule.prototype.initGooglePlus = function (media, cb) {
case "HTTP 302":
case "Video not found":
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.":
self.channel.logger.log("[mediarefresher] Google+ refresh failed: " +
err);

View File

@ -1,5 +1,6 @@
var http = require("http");
var https = require("https");
var cheerio = require('cheerio');
var Logger = require("./logger.js");
var Media = require("./media");
var CustomEmbedFilter = require("./customembed").filter;
@ -794,8 +795,8 @@ var Getters = {
/*
* Google+ videos
*
* This is quite possibly the hackiest video metadata retrieval function
* in CyTube.
* Also known as Picasa Web Albums.
*
*/
gp: function (id, cb) {
var idparts = id.split("_");
@ -804,8 +805,8 @@ var Getters = {
}
var options = {
host: "plus.google.com",
path: "/photos/" + idparts[0] + "/albums/" + idparts[1] + "/" + idparts[2],
host: "picasaweb.google.com",
path: '/data/feed/api/user/'+idparts[0]+'/albumid/'+idparts[1]+'/photoid/'+idparts[2]+'?kind=tag',
port: 443
};
@ -827,54 +828,29 @@ var Getters = {
}
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 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(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])
$('media\\:content[medium="video"]').each(function(index, element){
var url = $(this).attr("url")
var type = url.match(/itag=(\d\d)/)[1]
videos[type] = {
format: type,
link: url
};
}).forEach(function (video) {
videos[video.format] = video;
});
$ = null;
var direct = {};

View File

@ -9,6 +9,7 @@
"dependencies": {
"bcrypt": "^0.8.1",
"body-parser": "^1.10.2",
"cheerio" : "^0.18.0",
"compression": "^1.3.0",
"cookie-parser": "^1.3.3",
"cytubefilters": "git://github.com/calzoneman/cytubefilters#89f56fee",