Skip to content

Commit 3ad1359

Browse files
committed
Play with DLNA
1 parent 54c642d commit 3ad1359

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
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')
@@ -289,6 +290,50 @@ var ontorrent = function (torrent) {
289290
})
290291
browser.start()
291292
}
293+
if (argv.dlna) {
294+
var Browser = require('nodecast-js')
295+
var Client = require('upnp-mediarenderer-client')
296+
var xmlb = require('xmlbuilder')
297+
298+
var nodecast = new Browser()
299+
300+
// Apparently, the metadata constructed in
301+
// upnp-mediarenderer-client doesn't work
302+
var metadata = xmlb.create('DIDL-Lite', {
303+
'headless': true
304+
}).att({
305+
'xmlns': 'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/',
306+
'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
307+
'xmlns:upnp': 'urn:schemas-upnp-org:metadata-1-0/upnp/',
308+
'xmlns:dlna': 'urn:schemas-dlna-org:metadata-1-0/',
309+
'xmlns:sec': 'http://www.sec.co.kr/',
310+
'xmlns:xbmc': 'urn:schemas-xbmc-org:metadata-1-0/'
311+
})
312+
.ele('item', {
313+
'id': '0',
314+
'parentID': '-1',
315+
'restricted': '1'
316+
})
317+
.ele('dc:title', {}, filename)
318+
.insertAfter('res', { 'protocolInfo': 'http-get:*:video/mp4:*' }, href)
319+
.insertAfter('upnp:class', {}, 'object.item.videoItem.movie')
320+
.end({ pretty: false })
321+
322+
nodecast.onDevice(function (device) {
323+
device.onError(function (err) {
324+
throw err
325+
})
326+
327+
new Client(device.xml).load(href, {
328+
autoplay: true,
329+
metadata: metadata
330+
}, function (err, result) {
331+
if (err) throw err
332+
})
333+
})
334+
335+
nodecast.start()
336+
}
292337

293338
if (argv['on-listening']) proc.exec(argv['on-listening'] + ' ' + href)
294339

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
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",
@@ -31,7 +32,9 @@
3132
"rc": "^0.4.0",
3233
"read-torrent": "^1.1.0",
3334
"torrent-stream": "^0.20.0",
35+
"upnp-mediarenderer-client": "^1.2.1",
3436
"windows-no-runnable": "~0.0.6",
37+
"xmlbuilder": "^2.6.4",
3538
"xtend": "^4.0.0"
3639
},
3740
"devDependencies": {

0 commit comments

Comments
 (0)