Experimental ustream fix

This commit is contained in:
Calvin Montgomery 2017-03-02 18:47:47 -08:00
parent 20326194f7
commit 70be35e3fa
6 changed files with 59 additions and 3 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.30.1",
"version": "3.30.2",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View File

@ -8,5 +8,5 @@ window.UstreamPlayer = class UstreamPlayer extends EmbedPlayer
load: (data) ->
data.meta.embed =
tag: 'iframe'
src: "https://www.ustream.tv/embed/#{data.id}?html5ui&autoplay=1"
src: "/ustream_bypass/embed/#{data.id}?html5ui&autoplay=1"
super(data)

View File

@ -1,3 +1,4 @@
export const OK = 200;
export const BAD_REQUEST = 400;
export const FORBIDDEN = 403;
export const NOT_FOUND = 404;

View File

@ -0,0 +1,54 @@
import { HTTPError } from '../../errors';
import * as HTTPStatus from '../httpstatus';
import https from 'https';
import Promise from 'bluebird';
const INJECTION = `
<head>
<style type="text/css">
#PlayerOne.ui-enabled #ScreensContainer.shown {
display: none !important;
}
</style>`;
function ustreamSucks(channelId) {
const url = `https://www.ustream.tv/embed/${channelId}`;
return new Promise((resolve, reject) => {
const req = https.get(url, (res) => {
if (res.statusCode !== HTTPStatus.OK) {
res.resume();
return reject(new HTTPError(res.statusMessage, { status: res.statusCode }));
}
res.setEncoding('utf8');
let buffer = '';
res.on('data', data => buffer += data);
res.on('end', () => {
buffer = buffer.replace(/<head>/, INJECTION);
resolve(buffer);
});
});
req.on('error', error => {
reject(error);
});
});
}
export default function initialize(app) {
app.get('/ustream_bypass/embed/:channelId', (req, res) => {
if (!req.params.channelId || !/^\d+$/.test(req.params.channelId)) {
throw new HTTPError(`Invalid channel ID "${req.params.channelId}".`, {
status: HTTPStatus.BAD_REQUEST
});
}
ustreamSucks(req.params.channelId).then(buffer => {
res.type('html').send(buffer);
}).catch(HTTPError, error => {
res.status(error.status).send(error.message);
}).catch(error => {
res.status(HTTPStatus.INTERNAL_SERVER_ERROR).send('Internal Server Error');
});
});
};

View File

@ -186,6 +186,7 @@ module.exports = {
require('./acp').init(app);
require('../google2vtt').attach(app);
require('./routes/google_drive_userscript')(app);
require('./routes/ustream_bypass')(app);
app.use(serveStatic(path.join(__dirname, '..', '..', 'www'), {
maxAge: webConfig.getCacheTTL()
}));

View File

@ -1271,7 +1271,7 @@
UstreamPlayer.prototype.load = function(data) {
data.meta.embed = {
tag: 'iframe',
src: "https://www.ustream.tv/embed/" + data.id + "?html5ui&autoplay=1"
src: "/ustream_bypass/embed/" + data.id + "?html5ui&autoplay=1"
};
return UstreamPlayer.__super__.load.call(this, data);
};