-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathpicast.js
More file actions
27 lines (23 loc) · 905 Bytes
/
picast.js
File metadata and controls
27 lines (23 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var sys = require('sys');
var exec = require('child_process').exec;
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Welcome to PiCAST 3! In the URL, type what you want to do...');
});
app.get('/yt-stream/:url', function (req, res) {
// Sanitize URL parameter to prevent command injection
var videoId = req.params.url.replace(/[^a-zA-Z0-9_-]/g, '');
if (!videoId) {
res.status(400).send('Invalid video ID');
return;
}
res.send('Streaming YouTube Video...');
exec("livestreamer --player=mplayer https://www.youtube.com/watch?v=" + videoId + " best");
});
// Setup PiCAST Server
var srv = app.listen(3000, function () {
var host = srv.address().address;
var port = srv.address().port;
console.log('Access at http://%s:%s', host, port);
});