Merge pull request #1165 from janza/chromecast-subtitles
Add support for subtitles on Chromecast
This commit is contained in:
@@ -13,6 +13,8 @@ module.exports = {
|
|||||||
setRate
|
setRate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const http = require('http')
|
||||||
|
|
||||||
const config = require('../../config')
|
const config = require('../../config')
|
||||||
const {CastingError} = require('./errors')
|
const {CastingError} = require('./errors')
|
||||||
|
|
||||||
@@ -130,22 +132,47 @@ function chromecastPlayer () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function serveSubtitles (callback) {
|
||||||
|
const subtitles = state.playing.subtitles
|
||||||
|
const selectedSubtitle = subtitles.tracks[subtitles.selectedIndex]
|
||||||
|
if (!selectedSubtitle) {
|
||||||
|
callback()
|
||||||
|
} else {
|
||||||
|
ret.subServer = http.createServer((req, res) => {
|
||||||
|
res.writeHead(200, {
|
||||||
|
'Content-Type': 'text/vtt;charset=utf-8',
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Transfer-Encoding': 'chunked'
|
||||||
|
})
|
||||||
|
res.end(Buffer.from(selectedSubtitle.buffer.substr(21), 'base64'))
|
||||||
|
}).listen(0, function () {
|
||||||
|
const port = ret.subServer.address().port
|
||||||
|
const subtitlesUrl = 'http://' + state.server.networkAddress + ':' + port + '/'
|
||||||
|
callback(subtitlesUrl)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function open () {
|
function open () {
|
||||||
const torrentSummary = state.saved.torrents.find((x) => x.infoHash === state.playing.infoHash)
|
const torrentSummary = state.saved.torrents.find((x) => x.infoHash === state.playing.infoHash)
|
||||||
ret.device.play(state.server.networkURL + '/' + state.playing.fileIndex, {
|
serveSubtitles(function (subtitlesUrl) {
|
||||||
type: 'video/mp4',
|
ret.device.play(state.server.networkURL + '/' + state.playing.fileIndex, {
|
||||||
title: config.APP_NAME + ' - ' + torrentSummary.name
|
type: 'video/mp4',
|
||||||
}, function (err) {
|
title: config.APP_NAME + ' - ' + torrentSummary.name,
|
||||||
if (err) {
|
subtitles: subtitlesUrl ? [subtitlesUrl] : [],
|
||||||
state.playing.location = 'local'
|
autoSubtitles: !!subtitlesUrl
|
||||||
state.errors.push({
|
}, function (err) {
|
||||||
time: new Date().getTime(),
|
if (err) {
|
||||||
message: 'Could not connect to Chromecast. ' + err.message
|
state.playing.location = 'local'
|
||||||
})
|
state.errors.push({
|
||||||
} else {
|
time: new Date().getTime(),
|
||||||
state.playing.location = 'chromecast'
|
message: 'Could not connect to Chromecast. ' + err.message
|
||||||
}
|
})
|
||||||
update()
|
} else {
|
||||||
|
state.playing.location = 'chromecast'
|
||||||
|
}
|
||||||
|
update()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +186,9 @@ function chromecastPlayer () {
|
|||||||
|
|
||||||
function stop (callback) {
|
function stop (callback) {
|
||||||
ret.device.stop(callback)
|
ret.device.stop(callback)
|
||||||
|
if (ret.subServer) {
|
||||||
|
ret.subServer.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function status () {
|
function status () {
|
||||||
|
|||||||
@@ -320,7 +320,8 @@ function startServerFromReadyTorrent (torrent, cb) {
|
|||||||
const info = {
|
const info = {
|
||||||
torrentKey: torrent.key,
|
torrentKey: torrent.key,
|
||||||
localURL: 'http://localhost' + urlSuffix,
|
localURL: 'http://localhost' + urlSuffix,
|
||||||
networkURL: 'http://' + networkAddress() + urlSuffix
|
networkURL: 'http://' + networkAddress() + urlSuffix,
|
||||||
|
networkAddress: networkAddress()
|
||||||
}
|
}
|
||||||
|
|
||||||
ipc.send('wt-server-running', info)
|
ipc.send('wt-server-running', info)
|
||||||
|
|||||||
Reference in New Issue
Block a user