From d3a553c78e7aff5e69883bde4db1a48d037f43af Mon Sep 17 00:00:00 2001 From: Luigi Poole Date: Mon, 9 Nov 2015 20:38:02 -0800 Subject: [PATCH 1/2] Add DLNA headers / subtitle header (s) if a subtitle by the name of video.srt is present in the same folder as the video file => use it. --- index.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/index.js b/index.js index e8bfc1d..8c35f91 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,28 @@ var url = require('url') var mime = require('mime') var pump = require('pump') +var subtitlesUrl = false +var getIPAddress= function () { + var ip, alias = 0 + var ifaces = require('os').networkInterfaces() + for (var dev in ifaces) { + ifaces[dev].forEach(function (details) { + if (details.family === 'IPv4') { + if (!/(loopback|vmware|internal|hamachi|vboxnet)/gi.test(dev + (alias ? ':' + alias : ''))) { + if (details.address.substring(0, 8) === '192.168.' || + details.address.substring(0, 7) === '172.16.' || + details.address.substring(0, 5) === '10.0.' + ) { + ip = details.address + ++alias + } + } + } + }) + } + return ip +} + var parseBlocklist = function (filename) { // TODO: support gzipped files var blocklistData = fs.readFileSync(filename, { encoding: 'utf8' }) @@ -54,6 +76,8 @@ var createServer = function (e, opts) { var u = url.parse(request.url) var host = request.headers.host || 'localhost' + subtitlesUrl = 'http://'+ getIPAddress() + ':9999/video.srt' + var toPlaylist = function () { var toEntry = function (file, i) { return '#EXTINF:-1,' + file.path + '\n' + 'http://' + host + '/' + i @@ -154,6 +178,7 @@ var createServer = function (e, opts) { response.setHeader('Content-Type', getType(file.name)) response.setHeader('transferMode.dlna.org', 'Streaming') response.setHeader('contentFeatures.dlna.org', 'DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=017000 00000000000000000000000000') + response.setHeader('CaptionInfo.sec', subtitlesUrl) if (!range) { response.setHeader('Content-Length', file.length) if (request.method === 'HEAD') return response.end() @@ -164,6 +189,9 @@ var createServer = function (e, opts) { response.statusCode = 206 response.setHeader('Content-Length', range.end - range.start + 1) response.setHeader('Content-Range', 'bytes ' + range.start + '-' + range.end + '/' + file.length) + response.setHeader('transferMode.dlna.org', 'Streaming') + response.setHeader('contentFeatures.dlna.org', 'DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=017000 00000000000000000000000000') + response.setHeader('CaptionInfo.sec', subtitlesUrl) if (request.method === 'HEAD') return response.end() pump(file.createReadStream(range), response) }) From 4a2e9f59f0033b5a5aa525bd2f25535f3bddd95f Mon Sep 17 00:00:00 2001 From: Luigi Poole Date: Mon, 9 Nov 2015 20:43:39 -0800 Subject: [PATCH 2/2] remove subs part for now --- index.js | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/index.js b/index.js index 8c35f91..b5d8e74 100644 --- a/index.js +++ b/index.js @@ -7,28 +7,6 @@ var url = require('url') var mime = require('mime') var pump = require('pump') -var subtitlesUrl = false -var getIPAddress= function () { - var ip, alias = 0 - var ifaces = require('os').networkInterfaces() - for (var dev in ifaces) { - ifaces[dev].forEach(function (details) { - if (details.family === 'IPv4') { - if (!/(loopback|vmware|internal|hamachi|vboxnet)/gi.test(dev + (alias ? ':' + alias : ''))) { - if (details.address.substring(0, 8) === '192.168.' || - details.address.substring(0, 7) === '172.16.' || - details.address.substring(0, 5) === '10.0.' - ) { - ip = details.address - ++alias - } - } - } - }) - } - return ip -} - var parseBlocklist = function (filename) { // TODO: support gzipped files var blocklistData = fs.readFileSync(filename, { encoding: 'utf8' }) @@ -76,8 +54,6 @@ var createServer = function (e, opts) { var u = url.parse(request.url) var host = request.headers.host || 'localhost' - subtitlesUrl = 'http://'+ getIPAddress() + ':9999/video.srt' - var toPlaylist = function () { var toEntry = function (file, i) { return '#EXTINF:-1,' + file.path + '\n' + 'http://' + host + '/' + i @@ -178,7 +154,6 @@ var createServer = function (e, opts) { response.setHeader('Content-Type', getType(file.name)) response.setHeader('transferMode.dlna.org', 'Streaming') response.setHeader('contentFeatures.dlna.org', 'DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=017000 00000000000000000000000000') - response.setHeader('CaptionInfo.sec', subtitlesUrl) if (!range) { response.setHeader('Content-Length', file.length) if (request.method === 'HEAD') return response.end() @@ -191,7 +166,6 @@ var createServer = function (e, opts) { response.setHeader('Content-Range', 'bytes ' + range.start + '-' + range.end + '/' + file.length) response.setHeader('transferMode.dlna.org', 'Streaming') response.setHeader('contentFeatures.dlna.org', 'DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=017000 00000000000000000000000000') - response.setHeader('CaptionInfo.sec', subtitlesUrl) if (request.method === 'HEAD') return response.end() pump(file.createReadStream(range), response) })