Clean up addSubtitles (#535)
* Fix comments from #529 * Don't unlink deselected files I still want to do that eventually, but needs to be supported in WebTorrent See https://github.com/feross/webtorrent/issues/806
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"airplay-js": "guerrerocarlos/node-airplay-js",
|
"airplay-js": "guerrerocarlos/node-airplay-js",
|
||||||
"application-config": "^0.2.1",
|
"application-config": "^0.2.1",
|
||||||
"async": "^2.0.0-rc.5",
|
|
||||||
"bitfield": "^1.0.2",
|
"bitfield": "^1.0.2",
|
||||||
"chromecasts": "^1.8.0",
|
"chromecasts": "^1.8.0",
|
||||||
"concat-stream": "^1.5.1",
|
"concat-stream": "^1.5.1",
|
||||||
@@ -34,6 +33,7 @@
|
|||||||
"musicmetadata": "^2.0.2",
|
"musicmetadata": "^2.0.2",
|
||||||
"network-address": "^1.1.0",
|
"network-address": "^1.1.0",
|
||||||
"prettier-bytes": "^1.0.1",
|
"prettier-bytes": "^1.0.1",
|
||||||
|
"run-parallel": "^1.1.6",
|
||||||
"simple-get": "^2.0.0",
|
"simple-get": "^2.0.0",
|
||||||
"srt-to-vtt": "^1.1.1",
|
"srt-to-vtt": "^1.1.1",
|
||||||
"virtual-dom": "^2.1.1",
|
"virtual-dom": "^2.1.1",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ var ipcRenderer = electron.ipcRenderer
|
|||||||
setupIpc()
|
setupIpc()
|
||||||
|
|
||||||
var appConfig = require('application-config')('WebTorrent')
|
var appConfig = require('application-config')('WebTorrent')
|
||||||
var Async = require('async')
|
var parallel = require('run-parallel')
|
||||||
var concat = require('concat-stream')
|
var concat = require('concat-stream')
|
||||||
var dragDrop = require('drag-drop')
|
var dragDrop = require('drag-drop')
|
||||||
var fs = require('fs-extra')
|
var fs = require('fs-extra')
|
||||||
@@ -606,22 +606,23 @@ function addSubtitles (files, autoSelect) {
|
|||||||
if (state.playing.type !== 'video') return
|
if (state.playing.type !== 'video') return
|
||||||
|
|
||||||
// Read the files concurrently, then add all resulting subtitle tracks
|
// Read the files concurrently, then add all resulting subtitle tracks
|
||||||
console.log(files)
|
var jobs = files.map((file) => (cb) => loadSubtitle(file, cb))
|
||||||
var subs = state.playing.subtitles
|
parallel(jobs, function (err, tracks) {
|
||||||
Async.map(files, loadSubtitle, function (err, tracks) {
|
|
||||||
if (err) return onError(err)
|
if (err) return onError(err)
|
||||||
|
|
||||||
for (var i = 0; i < tracks.length; i++) {
|
for (var i = 0; i < tracks.length; i++) {
|
||||||
// No dupes allowed
|
// No dupes allowed
|
||||||
var track = tracks[i]
|
var track = tracks[i]
|
||||||
if (subs.tracks.some((t) => track.filePath === t.filePath)) continue
|
if (state.playing.subtitles.tracks.some(
|
||||||
|
(t) => track.filePath === t.filePath)) continue
|
||||||
|
|
||||||
// Add the track
|
// Add the track
|
||||||
subs.tracks.push(track)
|
state.playing.subtitles.tracks.push(track)
|
||||||
|
|
||||||
// If we're auto-selecting a track, try to find one in the user's language
|
// If we're auto-selecting a track, try to find one in the user's language
|
||||||
if (autoSelect && (i === 0 || isSystemLanguage(track.language))) {
|
if (autoSelect && (i === 0 || isSystemLanguage(track.language))) {
|
||||||
state.playing.subtitles.selectedIndex = subs.tracks.length - 1
|
state.playing.subtitles.selectedIndex =
|
||||||
|
state.playing.subtitles.tracks.length - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -349,10 +349,6 @@ function selectFiles (torrentOrInfoHash, selections) {
|
|||||||
} else {
|
} else {
|
||||||
console.log('deselecting file ' + i + ' of torrent ' + torrent.name)
|
console.log('deselecting file ' + i + ' of torrent ' + torrent.name)
|
||||||
file.deselect()
|
file.deselect()
|
||||||
|
|
||||||
// If we deselected a file, try to nuke it to save disk space
|
|
||||||
var filePath = path.join(torrent.path, file.path)
|
|
||||||
fs.unlink(filePath) // Ignore errors for now
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user