Closed tsoernes closed 8 years ago
What is config.port
set to?
According to your example any url will work.
It's set to 8888, like in the example. I've tried both VLC and MPC-HC at the URLs above, but there is no response.
If I use the same torrentfile, url (localhost) and port in Web-Torrent and it's build in HTTP-server, it works, so I don't think there is problem with the torrent-file or a firewall or something.
if you're piping it to a media player you need to set a content type res.setHeader('Content-Type', 'video/mp4')
if it's an mp4 file and you should create the stream every time there is a request - not just once
var stream = engine.files[biggestIdx].createReadStream();
var server = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'video/mkv')
stream.pipe(res);
})
server.listen(config.port, 'localhost'); // start
server.on('request', function (req, res) {
stream.pipe(res);
})
I tried the above, but no luck. What am I missing? I can see MPC-HC sending requests to the server.
You need to create the stream everytime a request is made
function (req, res) {
var stream = engine.files[biggestIdx].createReadStream()
...
stream.pipe(res)
}
Hmm, I tried that in addition to trying both video/mkv
and video/mp4
.
engine.on('ready', function() {
var biggestIdx = 0
for (var i = 1 ; i < engine.files.length; i++) {
if (engine.files[i].length > engine.files[biggestIdx].length) {
biggestIdx = i
}
}
var stream = engine.files[biggestIdx].createReadStream();
var server = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'video/mp4')
stream.pipe(res);
})
server.listen(config.port, 'localhost'); // start
server.on('request', function (req, res) {
stream = engine.files[biggestIdx].createReadStream()
res.setHeader('Content-Type', 'video/mp4')
stream.pipe(res);
})
})
You are attaching two request handlers in your example. You should only have one.
No success, did I get it right?
function launchTorrentStream (torrentFilePath) {
var engine = torrentStream(fs.readFileSync(torrentFilePath))
engine.on('ready', function() {
var biggestIdx = 0
for (var i = 1 ; i < engine.files.length; i++) {
if (engine.files[i].length > engine.files[biggestIdx].length) {
biggestIdx = i
}
}
var server = http.createServer(function (req, res) {
var stream = engine.files[biggestIdx].createReadStream()
res.setHeader('Content-Type', 'video/mp4')
stream.pipe(res)
})
server.listen(config.port, 'localhost');
})
}
Yep. That looks right to me. If it still doesn't work I'd suggest adding some console.log's to your request handler to try to figure out whats wrong
I'm trying to launch torrent-stream and download the biggest video file in a torrent, piping it to a HTTP server in order to play the video in an external video player. I've gotten this far:
But I can't figure what URL the file would be available at. Neither
http://localhost:8888/<biggestIndex>
orhttp://localhost:8888/MyVideo.mkv
or justhttp://localhost:8888
works. What decides the path, the HTTP server or the torrent-stream?