From 26a9446d3d6a4590128df8e12dc3881779faeed1 Mon Sep 17 00:00:00 2001 From: Xaekai Date: Fri, 13 Feb 2015 05:11:28 -0800 Subject: [PATCH] I commit this code in the name of Pinkie Pie. --- lib/channel/mediarefresher.js | 3 ++ lib/get-info.js | 74 ++++++++++++----------------------- package.json | 1 + 3 files changed, 29 insertions(+), 49 deletions(-) diff --git a/lib/channel/mediarefresher.js b/lib/channel/mediarefresher.js index a79c4141..bb3def8a 100644 --- a/lib/channel/mediarefresher.js +++ b/lib/channel/mediarefresher.js @@ -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); diff --git a/lib/get-info.js b/lib/get-info.js index da3b44ac..9e8ab002 100644 --- a/lib/get-info.js +++ b/lib/get-info.js @@ -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 = {}; diff --git a/package.json b/package.json index 2a7e2745..bbff2a41 100644 --- a/package.json +++ b/package.json @@ -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",