Save selected subtitle (#702)

This commit is contained in:
Mathias Rasmussen
2016-07-09 03:26:30 +02:00
committed by DC
parent 1668c4c614
commit c15711aae8
4 changed files with 24 additions and 6 deletions

View File

@@ -224,6 +224,11 @@ function openPlayerFromActiveTorrent (state, torrentSummary, index, timeout, cb)
// if it's video, check for subtitles files that are done downloading
dispatch('checkForSubtitles')
// enable previously selected subtitle track
if (fileSummary.selectedSubtitle) {
dispatch('addSubtitles', [fileSummary.selectedSubtitle], true)
}
ipcRenderer.send('wt-start-server', torrentSummary.infoHash, index)
ipcRenderer.once('wt-server-' + torrentSummary.infoHash, (e, info) => {
clearTimeout(timeout)

View File

@@ -31,10 +31,11 @@ module.exports = class SubtitlesController {
}
addSubtitles (files, autoSelect) {
var state = this.state
// Subtitles are only supported when playing video files
if (this.state.playing.type !== 'video') return
if (state.playing.type !== 'video') return
if (files.length === 0) return
var subtitles = this.state.playing.subtitles
var subtitles = state.playing.subtitles
// Read the files concurrently, then add all resulting subtitle tracks
var tasks = files.map((file) => (cb) => loadSubtitle(file, cb))
@@ -44,15 +45,17 @@ module.exports = class SubtitlesController {
for (var i = 0; i < tracks.length; i++) {
// No dupes allowed
var track = tracks[i]
if (subtitles.tracks.some(
(t) => track.filePath === t.filePath)) continue
var trackIndex = state.playing.subtitles.tracks
.findIndex((t) => track.filePath === t.filePath)
// Add the track
subtitles.tracks.push(track)
if (trackIndex === -1) {
trackIndex = state.playing.subtitles.tracks.push(track) - 1
}
// If we're auto-selecting a track, try to find one in the user's language
if (autoSelect && (i === 0 || isSystemLanguage(track.language))) {
subtitles.selectedIndex = subtitles.tracks.length - 1
state.playing.subtitles.selectedIndex = trackIndex
}
}