From c1c3e4c47f89016784271aa0893f6d07d412f768 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Tue, 14 May 2013 17:22:47 -0400 Subject: [PATCH] Add ustream support --- README.md | 1 + channel.js | 11 ++++++++++- get-info.js | 34 ++++++++++++++++++++++++++++++++-- package.json | 2 +- server.js | 2 +- www/assets/js/functions.js | 10 ++++++++++ www/assets/js/media.js | 28 ++++++++++++++++++++++++++++ www/help.html | 1 + 8 files changed, 84 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c2800252..402ee4dd 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ The following media sources are currently supported: - Soundcloud - Livestream.com - Twitch.tv +- Ustream - RTMP livestreams Installing diff --git a/channel.js b/channel.js index f4ed7aee..b81f8367 100644 --- a/channel.js +++ b/channel.js @@ -686,7 +686,8 @@ function isLive(type) { return type == "li" || type == "tw" || type == "rt" - || type == "jw"; + || type == "jw" + || type == "us"; } Channel.prototype.queueAdd = function(media, idx) { @@ -749,6 +750,14 @@ Channel.prototype.enqueue = function(data, user) { this.autoTemp(media, user); this.queueAdd(media, idx); break; + case "us": + InfoGetter.getUstream(data.id, function(id) { + var media = new Media(id, "Ustream - " + data.id, "--:--", "us"); + media.queueby = user ? user.name : ""; + this.autoTemp(media, user); + this.queueAdd(media, idx); + }.bind(this)); + break; case "rt": var media = new Media(data.id, "Livestream", "--:--", "rt"); media.queueby = user ? user.name : ""; diff --git a/get-info.js b/get-info.js index 6e4bfdf7..0d6ae74e 100644 --- a/get-info.js +++ b/get-info.js @@ -29,8 +29,7 @@ function getJSON(options, callback) { } catch(e) { Logger.errlog.log("JSON fail: " + options.path); - return; - } + return; } callback(res.statusCode, data); }); }); @@ -190,6 +189,37 @@ exports.getDMInfo = function(id, callback) { timeout: 1000}, callback); } +// Ustream requires a developer key for their API, and on top of that +// I couldn't figure out how to use it. +// I'm regexing the stream ID out of the HTML +// So sue me +exports.getUstream = function(name, callback) { + var opts = { + host: "www.ustream.tv", + port: 80, + path: "/" + name + }; + http.get(opts, function(res) { + var html = ""; + res.on("data", function(cnk) { + html += cnk; + }); + res.on("end", function() { + var lines = html.split("\n"); + const re = /cid":([0-9]+)/; + for(var i = 0; i < lines.length; i++) { + var m = lines[i].match(re); + if(m) { + callback(m[1]); + return; + } + } + }); + }).on("error", function(err) { + Logger.errlog.log(err.message); + }); +} + exports.getMedia = function(id, type, callback) { switch(type) { case "yt": diff --git a/package.json b/package.json index 4b3dc379..c5b7469a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "1.7.3", + "version": "1.7.4", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/server.js b/server.js index 31799092..e8b4697b 100644 --- a/server.js +++ b/server.js @@ -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 = "1.7.3"; +const VERSION = "1.7.4"; var fs = require("fs"); var Logger = require("./logger.js"); diff --git a/www/assets/js/functions.js b/www/assets/js/functions.js index dc4d93c9..af3fee22 100644 --- a/www/assets/js/functions.js +++ b/www/assets/js/functions.js @@ -502,6 +502,8 @@ function parseVideoURL(url){ return [parseTwitch(url), "tw"]; else if(url.indexOf("livestream.com") != -1) return [parseLivestream(url), "li"]; + else if(url.indexOf("ustream.tv") != -1) + return [parseUstream(url), "us"]; else if(url.indexOf("soundcloud.com") != -1) return [url, "sc"]; else if(url.indexOf("vimeo.com") != -1) @@ -550,6 +552,14 @@ function parseLivestream(url) { return null; } +function parseUstream(url) { + var m = url.match(/ustream\.tv\/([a-zA-Z0-9-]+)/); + if(m) { + return m[1]; + } + return null; +} + function parseVimeo(url) { var m = url.match(/vimeo\.com\/([0-9]+)/); if(m) { diff --git a/www/assets/js/media.js b/www/assets/js/media.js index d95e3899..b9981dcb 100644 --- a/www/assets/js/media.js +++ b/www/assets/js/media.js @@ -34,6 +34,9 @@ var Media = function(data) { case "jw": this.initJWPlayer(); break; + case "us": + this.initUstream(); + break; default: this.nullPlayer(); break; @@ -373,6 +376,31 @@ Media.prototype.initJWPlayer = function() { this.seek = function() { } } +Media.prototype.initUstream = function() { + var iframe = $("