From ce8ac4591e39564c33a29c0a9f33ca5de3995554 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Fri, 15 May 2015 01:19:08 -0500 Subject: [PATCH] Use VideoJS for google+ --- lib/get-info.js | 118 ++++++------------------------------------- player/update.coffee | 6 +-- www/js/player-new.js | 7 +-- 3 files changed, 22 insertions(+), 109 deletions(-) diff --git a/lib/get-info.js b/lib/get-info.js index f610afe4..684deb21 100644 --- a/lib/get-info.js +++ b/lib/get-info.js @@ -530,6 +530,21 @@ var Getters = { }); }, + /* Google+ videos */ + gp: function (id, callback) { + var data = { + type: "google+", + kind: "single", + id: id + }; + + mediaquery.lookup(data).then(function (video) { + callback(null, convertMedia(video)); + }).catch(function (err) { + callback(err.message || err); + }); + }, + /* ffmpeg for raw files */ fi: function (id, cb) { ffmpeg.query(id, function (err, data) { @@ -545,109 +560,6 @@ var Getters = { }); }, - /* - * Google+ videos - * - * Also known as Picasa Web Albums. - * - */ - gp: function (id, cb) { - var idparts = id.split("_"); - if (idparts.length !== 3) { - return cb("Invalid Google+ video ID"); - } - - var options = { - host: "picasaweb.google.com", - path: '/data/feed/api/user/'+idparts[0]+'/albumid/'+idparts[1]+'/photoid/'+idparts[2]+'?kind=tag', - 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 $ = 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 = {}; - $('media\\:content[medium="video"]').each(function(index, element){ - var url = $(this).attr("url"); - var match = url.match(/itag=(\d+)/) - if (!match) { - match = url.match(/googleusercontent.*=m(\d+)$/); - } - - if (match && match[1]) { - var type = match[1]; - videos[type] = { - format: type, - link: url - }; - } - }); - $ = null; - - var direct = {}; - - for (var key in GOOGLE_PREFERENCE) { - for (var i = 0; i < GOOGLE_PREFERENCE[key].length; i++) { - var format = GOOGLE_PREFERENCE[key][i]; - - if (format in videos) { - direct[key] = { - url: videos[format].link, - contentType: CONTENT_TYPES[format] - }; - break; - } - } - } - - if (Object.keys(direct).length === 0) { - return cb("Unable to retrieve video data from Google+. The videos " + - "may have not finished processing yet."); - } 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); - } - }); - }, - /* hitbox.tv */ hb: function (id, callback) { var m = id.match(/([\w-]+)/); diff --git a/player/update.coffee b/player/update.coffee index 2f8a5cfc..912d7e87 100644 --- a/player/update.coffee +++ b/player/update.coffee @@ -3,6 +3,7 @@ TYPE_MAP = vi: VimeoPlayer dm: DailymotionPlayer gd: VideoJSPlayer + gp: VideoJSPlayer window.loadMediaPlayer = (data) -> if data.type of TYPE_MAP @@ -63,10 +64,9 @@ window.handleMediaUpdate = (data) -> # Dailymotion can't seek very accurately in Flash due to keyframe # placement. Accuracy should not be set lower than 5 or the video # may be very choppy. - if PLAYER.mediaType is 'dm' # TODO: instanceof DailymotionPlayer + if PLAYER instanceof DailymotionPlayer accuracy = Math.max(accuracy, 5) - if diff > accuracy # The player is behind the correct time PLAYER.seekTo(time) @@ -75,7 +75,7 @@ window.handleMediaUpdate = (data) -> # Don't seek all the way back, to account for possible buffering. # However, do seek all the way back for Dailymotion due to the # keyframe issue mentioned above. - if PLAYER.mediaType isnt 'dm' # TODO: instanceof DailymotionPlayer + if not (PLAYER instanceof DailymotionPlayer) time += 1 PLAYER.seekTo(time) ) diff --git a/www/js/player-new.js b/www/js/player-new.js index b07aea11..f991b912 100644 --- a/www/js/player-new.js +++ b/www/js/player-new.js @@ -597,7 +597,8 @@ yt: YouTubePlayer, vi: VimeoPlayer, dm: DailymotionPlayer, - gd: VideoJSPlayer + gd: VideoJSPlayer, + gp: VideoJSPlayer }; window.loadMediaPlayer = function(data) { @@ -651,13 +652,13 @@ time = data.currentTime; diff = (time - seconds) || time; accuracy = USEROPTS.sync_accuracy; - if (PLAYER.mediaType === 'dm') { + if (PLAYER instanceof DailymotionPlayer) { accuracy = Math.max(accuracy, 5); } if (diff > accuracy) { return PLAYER.seekTo(time); } else if (diff < -accuracy) { - if (PLAYER.mediaType !== 'dm') { + if (!(PLAYER instanceof DailymotionPlayer)) { time += 1; } return PLAYER.seekTo(time);