From 6f568623077a44a6fbf2400b881ea42152ee55d4 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 25 Jun 2016 17:09:48 -0700 Subject: [PATCH] Add vidme support (#568) --- package.json | 2 +- player/update.coffee | 1 + src/channel/mediarefresher.js | 60 +++++++++++++++++++++++++++++++++++ src/get-info.js | 15 +++++++++ www/js/player.js | 3 +- www/js/util.js | 7 ++++ 6 files changed, 86 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b530a4e0..634c35f9 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.17.1", + "version": "3.17.2", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/player/update.coffee b/player/update.coffee index b4bba248..0b4e959b 100644 --- a/player/update.coffee +++ b/player/update.coffee @@ -14,6 +14,7 @@ TYPE_MAP = hb: HitboxPlayer us: UstreamPlayer im: ImgurPlayer + vm: VideoJSPlayer window.loadMediaPlayer = (data) -> try diff --git a/src/channel/mediarefresher.js b/src/channel/mediarefresher.js index 411d0512..e662c954 100644 --- a/src/channel/mediarefresher.js +++ b/src/channel/mediarefresher.js @@ -39,6 +39,12 @@ MediaRefresherModule.prototype.onPreMediaChange = function (data, cb) { pl._refreshing = false; cb(null, ChannelModule.PASSTHROUGH); }); + case "vm": + pl._refreshing = true; + return this.initVidme(data, function () { + pl._refreshing = false; + cb(null, ChannelModule.PASSTHROUGH); + }); default: return cb(null, ChannelModule.PASSTHROUGH); } @@ -220,4 +226,58 @@ MediaRefresherModule.prototype.initGooglePlus = function (media, cb) { }); }; +MediaRefresherModule.prototype.initVidme = function (data, cb) { + var self = this; + self.refreshVidme(data, cb); + + /* + * Refresh every 55 minutes. + * The expiration is 1 hour, but refresh 5 minutes early to be safe + */ + self._interval = setInterval(function () { + self.refreshVidme(data); + }, 55 * 60 * 1000); +}; + +MediaRefresherModule.prototype.refreshVidme = function (media, cb) { + var self = this; + + if (self.dead || self.channel.dead) { + self.unload(); + return; + } + + self.channel.refCounter.ref("MediaRefresherModule::refreshVidme"); + InfoGetter.getMedia(media.id, "vm", function (err, data) { + if (self.dead || self.channel.dead) { + return; + } + + if (err) { + self.channel.logger.log("[mediarefresher] Vidme refresh failed: " + err); + self.channel.refCounter.unref("MediaRefresherModule::refreshVidme"); + if (cb) { + process.nextTick(cb); + } + return; + } + + if (media !== self._media) { + self.channel.refCounter.unref("MediaRefresherModule::refreshVidme"); + if (cb) { + process.nextTick(cb); + } + return; + } + + self.channel.logger.log("[mediarefresher] Refreshed Vidme video with ID " + + media.id); + media.meta = data.meta; + self.channel.refCounter.unref("MediaRefresherModule::refreshVidme"); + if (cb) { + process.nextTick(cb); + } + }); +} + module.exports = MediaRefresherModule; diff --git a/src/get-info.js b/src/get-info.js index 9e23f8b3..db007aad 100644 --- a/src/get-info.js +++ b/src/get-info.js @@ -10,6 +10,7 @@ var ffmpeg = require("./ffmpeg"); var mediaquery = require("cytube-mediaquery"); var YouTube = require("cytube-mediaquery/lib/provider/youtube"); var Vimeo = require("cytube-mediaquery/lib/provider/vimeo"); +var Vidme = require("cytube-mediaquery/lib/provider/vidme"); /* * Preference map of quality => youtube formats. @@ -547,6 +548,20 @@ var Getters = { var media = new Media(id, title, "--:--", "hb"); callback(false, media); }, + + /* vid.me */ + vm: function (id, callback) { + if (!/^[\w-]+$/.test(id)) { + process.nextTick(callback, "Invalid vid.me ID"); + return; + } + + Vidme.lookup(id).then(video => { + const media = new Media(video.id, video.title, video.duration, + "vm", video.meta); + process.nextTick(callback, false, media); + }); + } }; module.exports = { diff --git a/www/js/player.js b/www/js/player.js index b7f6ac24..516ef6f2 100644 --- a/www/js/player.js +++ b/www/js/player.js @@ -1272,7 +1272,8 @@ rt: RTMPPlayer, hb: HitboxPlayer, us: UstreamPlayer, - im: ImgurPlayer + im: ImgurPlayer, + vm: VideoJSPlayer }; window.loadMediaPlayer = function(data) { diff --git a/www/js/util.js b/www/js/util.js index 345722c0..4ab45405 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -1354,6 +1354,13 @@ function parseMediaLink(url) { }; } + if((m = url.match(/vid\.me\/([\w-]+)/))) { + return { + id: m[1], + type: "vm" + }; + } + /* Shorthand URIs */ // To catch Google Plus by ID alone if ((m = url.match(/^(?:gp:)?(\d{21}_\d{19}_\d{19})/))) {