Skip to content

Commit a770e51

Browse files
committed
Play with DLNA
1 parent 61bd216 commit a770e51

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

app.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var argv = rc('peerflix', {}, optimist
2727
.alias('q', 'quiet').describe('q', 'be quiet').boolean('v')
2828
.alias('v', 'vlc').describe('v', 'autoplay in vlc*').boolean('v')
2929
.alias('s', 'airplay').describe('s', 'autoplay via AirPlay').boolean('a')
30+
.alias('u', 'dlna').describe('u', 'autoplay via DLNA').boolean('u')
3031
.alias('m', 'mplayer').describe('m', 'autoplay in mplayer*').boolean('m')
3132
.alias('g', 'smplayer').describe('g', 'autoplay in smplayer*').boolean('g')
3233
.describe('mpchc', 'autoplay in MPC-HC player*').boolean('boolean')
@@ -301,6 +302,50 @@ var ontorrent = function (torrent) {
301302
})
302303
browser.start()
303304
}
305+
if (argv.dlna) {
306+
var Browser = require('nodecast-js')
307+
var Client = require('upnp-mediarenderer-client')
308+
var xmlb = require('xmlbuilder')
309+
310+
var nodecast = new Browser()
311+
312+
// Apparently, the metadata constructed in
313+
// upnp-mediarenderer-client doesn't work
314+
var metadata = xmlb.create('DIDL-Lite', {
315+
'headless': true
316+
}).att({
317+
'xmlns': 'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/',
318+
'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
319+
'xmlns:upnp': 'urn:schemas-upnp-org:metadata-1-0/upnp/',
320+
'xmlns:dlna': 'urn:schemas-dlna-org:metadata-1-0/',
321+
'xmlns:sec': 'http://www.sec.co.kr/',
322+
'xmlns:xbmc': 'urn:schemas-xbmc-org:metadata-1-0/'
323+
})
324+
.ele('item', {
325+
'id': '0',
326+
'parentID': '-1',
327+
'restricted': '1'
328+
})
329+
.ele('dc:title', {}, filename)
330+
.insertAfter('res', { 'protocolInfo': 'http-get:*:video/mp4:*' }, href)
331+
.insertAfter('upnp:class', {}, 'object.item.videoItem.movie')
332+
.end({ pretty: false })
333+
334+
nodecast.onDevice(function (device) {
335+
device.onError(function (err) {
336+
throw err
337+
})
338+
339+
new Client(device.xml).load(href, {
340+
autoplay: true,
341+
metadata: metadata
342+
}, function (err, result) {
343+
if (err) throw err
344+
})
345+
})
346+
347+
nodecast.start()
348+
}
304349

305350
if (argv['on-listening']) proc.exec(argv['on-listening'] + ' ' + href)
306351

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@
2323
"keypress": "^0.2.1",
2424
"mime": "^1.2.11",
2525
"network-address": "0.0.5",
26+
"nodecast-js": "^0.1.2",
2627
"numeral": "^1.5.3",
2728
"open": "0.0.5",
2829
"optimist": "^0.6.1",
2930
"pump": "^0.3.1",
3031
"range-parser": "^1.0.0",
3132
"rc": "^0.4.0",
3233
"torrent-stream": "^0.20.0",
34+
"upnp-mediarenderer-client": "^1.2.1",
3335
"windows-no-runnable": "~0.0.6",
3436
"xtend": "^4.0.0",
35-
"parse-torrent": "^5.4.0"
37+
"parse-torrent": "^5.4.0",
38+
"xmlbuilder": "^2.6.4"
3639
},
3740
"devDependencies": {
3841
"standard": "^2.2.3"

0 commit comments

Comments
 (0)