Initial commit for server side approach

This is the first commit for bringing this over to the server side.

It works! Right now it fails if the autoscanner or or the manual
individual book scanner try to do it's thing. I'll need to update those
This commit is contained in:
jmt-gh 2022-06-11 23:17:22 -07:00
parent effc63755b
commit b3d9323f66
6 changed files with 175 additions and 42 deletions

View file

@ -196,6 +196,9 @@ class MediaFileScanner {
}
async scanMediaFiles(mediaLibraryFiles, scanData, libraryItem, preferAudioMetadata, libraryScan = null) {
Logger.debug('[scanMediaFiles] inside scan media files!')
Logger.debug(`[scanMediaFiles] libraryScan: ${JSON.stringify(libraryScan)}`)
var hasUpdated = false
var mediaScanResult = await this.executeMediaFileScans(libraryItem.mediaType, mediaLibraryFiles, scanData)
@ -208,6 +211,7 @@ class MediaFileScanner {
} else if (mediaScanResult.audioFiles.length) {
if (libraryScan) {
libraryScan.addLog(LogLevel.DEBUG, `Library Item "${scanData.path}" Audio file scan took ${mediaScanResult.elapsed}ms for ${mediaScanResult.audioFiles.length} with average time of ${mediaScanResult.averageScanDuration}ms`)
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
@ -217,18 +221,23 @@ class MediaFileScanner {
// Book: Adding audio files to book media
if (libraryItem.mediaType === 'book') {
Logger.debug('Its a book!')
if (newAudioFiles.length) {
Logger.debug('[MediaFileScanner] newAudioFiles.length was true?')
// Single Track Audiobooks
if (totalAudioFilesToInclude === 1) {
Logger.debug('[MediaFileScanner] totalAudioFilesToInclude === 1')
var af = mediaScanResult.audioFiles[0]
af.index = 1
libraryItem.media.addAudioFile(af)
hasUpdated = true
} else {
Logger.debug('[MediaFileScanner] totalAudioFilesToInclude === 1 WAS FALSE')
this.runSmartTrackOrder(libraryItem, mediaScanResult.audioFiles)
hasUpdated = true
}
} else {
Logger.debug('[MediaFileScanner] Only updating metadata?')
// Only update metadata not index
mediaScanResult.audioFiles.forEach((af) => {
var existingAF = libraryItem.media.findFileWithInode(af.ino)
@ -247,7 +256,9 @@ class MediaFileScanner {
}
if (hasUpdated) {
libraryItem.media.rebuildTracks()
Logger.debug('[MediaFileScanner] hasUpdated is true! Going to rebuild tracks now...')
Logger.debug(`[MediaFileScanner] libraryScan: ${JSON.stringify(libraryScan)}`)
libraryItem.media.rebuildTracks(libraryScan.scanOptions.preferOverdriveMediaMarker)
}
} else { // Podcast Media Type
var existingAudioFiles = mediaScanResult.audioFiles.filter(af => libraryItem.media.findFileWithInode(af.ino))
@ -264,6 +275,7 @@ class MediaFileScanner {
// Update audio file metadata for audio files already there
existingAudioFiles.forEach((af) => {
var peAudioFile = libraryItem.media.findFileWithInode(af.ino)
Logger.debug(`[MediaFileScanner] peAudioFile: ${JSON.stringify(peAudioFile)}`)
if (peAudioFile.updateFromScan && peAudioFile.updateFromScan(af)) {
hasUpdated = true
}