mirror of https://github.com/calzoneman/sync.git
Merge pull request #386 from calzoneman/plusvideo
Google+ video support
This commit is contained in:
commit
89de33031c
|
@ -426,7 +426,8 @@ module.exports = {
|
|||
|
||||
var meta = JSON.stringify({
|
||||
bitrate: media.meta.bitrate,
|
||||
codec: media.meta.codec
|
||||
codec: media.meta.codec,
|
||||
gpdirect: media.meta.gpdirect
|
||||
});
|
||||
|
||||
db.query("INSERT INTO `channel_libraries` " +
|
||||
|
|
131
lib/get-info.js
131
lib/get-info.js
|
@ -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,132 @@ var Getters = {
|
|||
});
|
||||
cb(null, m);
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
* Google+ videos
|
||||
*
|
||||
* This is quite possibly the hackiest video metadata retrieval function
|
||||
* in CyTube.
|
||||
*/
|
||||
gp: function (id, cb) {
|
||||
var idparts = id.split("_");
|
||||
if (idparts.length !== 3) {
|
||||
return cb("Invalid Google+ video ID");
|
||||
}
|
||||
|
||||
var options = {
|
||||
host: "plus.google.com",
|
||||
path: "/photos/" + idparts[0] + "/albums/" + idparts[1] + "/" + idparts[2],
|
||||
port: 443
|
||||
};
|
||||
|
||||
urlRetrieve(https, options, function (status, res) {
|
||||
switch (status) {
|
||||
case 200:
|
||||
break; /* Request is OK, skip to handling data */
|
||||
case 400:
|
||||
return cb("Invalid request", null);
|
||||
case 403:
|
||||
return cb("Private video", null);
|
||||
case 404:
|
||||
return cb("Video not found", null);
|
||||
case 500:
|
||||
case 503:
|
||||
return cb("Service unavailable", null);
|
||||
default:
|
||||
return cb("HTTP " + status, null);
|
||||
}
|
||||
|
||||
try {
|
||||
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+),("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;
|
||||
});
|
||||
|
||||
/*
|
||||
* Preference map of quality => youtube formats.
|
||||
* see https://en.wikipedia.org/wiki/Youtube#Quality_and_codecs
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(direct).length === 0) {
|
||||
return cb("Unable to retrieve video data from Google+. Check that " +
|
||||
"the album exists and is shared publicly.");
|
||||
} else if (!title) {
|
||||
return cb("Unable to retrieve title from Google+. Check that " +
|
||||
"the album exists and is shared publicly.");
|
||||
} else if (!duration) {
|
||||
return cb("Unable to retreive duration from Google+. This might be " +
|
||||
"because the video is still processing.");
|
||||
}
|
||||
|
||||
var media = new Media(id, title, duration, "gp", { gpdirect: direct });
|
||||
cb(null, media);
|
||||
} catch (e) {
|
||||
cb("Unknown error");
|
||||
Logger.errlog.log("Unknown error for Google+ ID " + id + ": " + e.stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ Media.prototype = {
|
|||
object: this.meta.object,
|
||||
params: this.meta.params,
|
||||
direct: this.meta.direct,
|
||||
gpdirect: this.meta.gpdirect,
|
||||
restricted: this.meta.restricted,
|
||||
codec: this.meta.codec,
|
||||
bitrate: this.meta.bitrate
|
||||
|
|
|
@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
const VERSION = "3.3.1";
|
||||
const VERSION = "3.3.2";
|
||||
var singleton = null;
|
||||
var Config = require("./config");
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"author": "Calvin Montgomery",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "3.3.1",
|
||||
"version": "3.3.2",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
|
|
|
@ -878,6 +878,10 @@ Callbacks = {
|
|||
data = vimeoSimulator2014(data);
|
||||
}
|
||||
|
||||
if (data.type === "gp") {
|
||||
data = googlePlusSimulator2014(data);
|
||||
}
|
||||
|
||||
/* RTMP player has been replaced with the general flash player */
|
||||
if (data.type === "rt") {
|
||||
data.url = data.id;
|
||||
|
|
|
@ -1082,6 +1082,9 @@ function FilePlayer(data) {
|
|||
|
||||
self.initFlash = function (data) {
|
||||
waitUntilDefined(window, "swfobject", function () {
|
||||
if (!data.url) {
|
||||
return;
|
||||
}
|
||||
self.volume = VOLUME;
|
||||
self.videoId = data.id;
|
||||
self.videoURL = data.url;
|
||||
|
@ -1161,6 +1164,9 @@ function FilePlayer(data) {
|
|||
};
|
||||
|
||||
self.init = function (data) {
|
||||
if (!data.url) {
|
||||
return;
|
||||
}
|
||||
self.videoId = data.id;
|
||||
self.videoURL = data.url;
|
||||
var isAudio = data.meta.codec && data.meta.codec.match(/^mp3$|^vorbis$/);
|
||||
|
|
|
@ -1280,6 +1280,13 @@ function parseMediaLink(url) {
|
|||
};
|
||||
}
|
||||
|
||||
if ((m = url.match(/plus\.google\.com\/(?:u\/\d+\/)?photos\/(\d+)\/albums\/(\d+)\/(\d+)/))) {
|
||||
return {
|
||||
id: m[1] + "_" + m[2] + "_" + m[3],
|
||||
type: "gp"
|
||||
};
|
||||
}
|
||||
|
||||
/* Raw file */
|
||||
var tmp = url.split("?")[0];
|
||||
if (tmp.match(/^https?:\/\//)) {
|
||||
|
@ -2725,3 +2732,38 @@ function vimeoSimulator2014(data) {
|
|||
data.url = data.meta.direct[q].url;
|
||||
return data;
|
||||
}
|
||||
|
||||
function googlePlusSimulator2014(data) {
|
||||
/* Google+ Simulator uses the raw file player */
|
||||
data.type = "fi";
|
||||
|
||||
/* For browsers that don't support native h264 playback */
|
||||
if (USEROPTS.no_h264) {
|
||||
data.forceFlash = true;
|
||||
}
|
||||
|
||||
if (!data.meta.gpdirect) {
|
||||
data.url = "";
|
||||
return data;
|
||||
}
|
||||
|
||||
/* Convert youtube-style quality key to vimeo workaround quality */
|
||||
var q = USEROPTS.default_quality || "auto";
|
||||
|
||||
var fallbacks = ["hd1080", "hd720", "large", "medium", "small"];
|
||||
var i = fallbacks.indexOf(q);
|
||||
if (i < 0) {
|
||||
// Default to 360p because 480p is Flash
|
||||
i = fallbacks.indexOf("medium");
|
||||
}
|
||||
|
||||
while (!(q in data.meta.gpdirect) && i < fallbacks.length) {
|
||||
q = fallbacks[i++];
|
||||
}
|
||||
if (i === fallbacks.length) {
|
||||
q = "medium";
|
||||
}
|
||||
|
||||
data.url = data.meta.gpdirect[q];
|
||||
return data;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue