Skip to content

Commit

Permalink
Play with DLNA
Browse files Browse the repository at this point in the history
  • Loading branch information
apelike committed Aug 24, 2015
1 parent 54c642d commit 0624ac9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down

0 comments on commit 0624ac9

Please sign in to comment.