diff --git a/server/objects/files/AudioFile.js b/server/objects/files/AudioFile.js index c2a15fb5..27c62e8e 100644 --- a/server/objects/files/AudioFile.js +++ b/server/objects/files/AudioFile.js @@ -111,6 +111,10 @@ class AudioFile { } } + get isValidTrack() { + return !this.invalid && !this.exclude + } + // New scanner creates AudioFile from MediaFileScanner setDataFromProbe(libraryFile, probeData) { this.ino = libraryFile.ino || null diff --git a/server/scanner/MediaFileScanner.js b/server/scanner/MediaFileScanner.js index 3ed96895..e010d1b1 100644 --- a/server/scanner/MediaFileScanner.js +++ b/server/scanner/MediaFileScanner.js @@ -211,22 +211,26 @@ class MediaFileScanner { Logger.debug(`Library Item "${scanData.path}" Audio file scan took ${mediaScanResult.elapsed}ms for ${mediaScanResult.audioFiles.length} with average time of ${mediaScanResult.averageScanDuration}ms`) } - var totalAudioFilesToInclude = mediaScanResult.audioFiles.length var newAudioFiles = mediaScanResult.audioFiles.filter(af => { return !libraryItem.media.findFileWithInode(af.ino) }) // Book: Adding audio files to book media if (libraryItem.mediaType === 'book') { + var mediaScanFileInodes = mediaScanResult.audioFiles.map(af => af.ino) + // Filter for existing valid track audio files not included in the audio files scanned + var existingAudioFiles = libraryItem.media.audioFiles.filter(af => af.isValidTrack && !mediaScanFileInodes.includes(af.ino)) + if (newAudioFiles.length) { // Single Track Audiobooks - if (totalAudioFilesToInclude === 1) { + if (mediaScanFileInodes.length + existingAudioFiles.length === 1) { var af = mediaScanResult.audioFiles[0] af.index = 1 libraryItem.media.addAudioFile(af) hasUpdated = true } else { - this.runSmartTrackOrder(libraryItem, mediaScanResult.audioFiles) + var allAudioFiles = existingAudioFiles.concat(mediaScanResult.audioFiles) + this.runSmartTrackOrder(libraryItem, allAudioFiles) hasUpdated = true } } else {