diff --git a/app.js b/app.js index 91a45ed..6c51c9f 100755 --- a/app.js +++ b/app.js @@ -27,6 +27,7 @@ var argv = rc('peerflix', {}, optimist .alias('q', 'quiet').describe('q', 'be quiet').boolean('v') .alias('v', 'vlc').describe('v', 'autoplay in vlc*').boolean('v') .alias('s', 'airplay').describe('s', 'autoplay via AirPlay').boolean('a') + .alias('d', 'dlna').describe('d', 'autoplay via DLNA').boolean('d') .alias('m', 'mplayer').describe('m', 'autoplay in mplayer*').boolean('m') .alias('g', 'smplayer').describe('g', 'autoplay in smplayer*').boolean('g') .describe('mpchc', 'autoplay in MPC-HC player*').boolean('boolean') @@ -289,6 +290,50 @@ var ontorrent = function (torrent) { }) browser.start() } + if (argv.dlna) { + var Browser = require('nodecast-js') + var Client = require('upnp-mediarenderer-client') + var xmlb = require('xmlbuilder') + + var nodecast = new Browser() + + // Apparently, the metadata constructed in + // upnp-mediarenderer-client doesn't work + var metadata = xmlb.create('DIDL-Lite', { + 'headless': true + }).att({ + 'xmlns': 'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/', + 'xmlns:dc': 'http://purl.org/dc/elements/1.1/', + 'xmlns:upnp': 'urn:schemas-upnp-org:metadata-1-0/upnp/', + 'xmlns:dlna': 'urn:schemas-dlna-org:metadata-1-0/', + 'xmlns:sec': 'http://www.sec.co.kr/', + 'xmlns:xbmc': 'urn:schemas-xbmc-org:metadata-1-0/' + }) + .ele('item', { + 'id': '0', + 'parentID': '-1', + 'restricted': '1' + }) + .ele('dc:title', {}, filename) + .insertAfter('res', { 'protocolInfo': 'http-get:*:video/mp4:*' }, href) + .insertAfter('upnp:class', {}, 'object.item.videoItem.movie') + .end({ pretty: false }) + + nodecast.onDevice(function (device) { + device.onError(function (err) { + throw err + }) + + new Client(device.xml).load(href, { + autoplay: true, + metadata: metadata + }, function (err, result) { + if (err) throw err + }) + }) + + nodecast.start() + } if (argv['on-listening']) proc.exec(argv['on-listening'] + ' ' + href) diff --git a/package.json b/package.json index cc681e7..726f987 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "keypress": "^0.2.1", "mime": "^1.2.11", "network-address": "0.0.5", + "nodecast-js": "^0.1.2", "numeral": "^1.5.3", "open": "0.0.5", "optimist": "^0.6.1", @@ -31,7 +32,9 @@ "rc": "^0.4.0", "read-torrent": "^1.1.0", "torrent-stream": "^0.20.0", + "upnp-mediarenderer-client": "^1.2.1", "windows-no-runnable": "~0.0.6", + "xmlbuilder": "^2.6.4", "xtend": "^4.0.0" }, "devDependencies": {