mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-31 19:18:57 +01:00
Add support for various scan types
This commit adds support for the various scan types, and ensures that we only run Overdrive parsing on files that can actually support it
This commit is contained in:
parent
b3d9323f66
commit
68afc2c718
@ -360,9 +360,9 @@ class Book {
|
|||||||
this.rebuildTracks()
|
this.rebuildTracks()
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuildTracks(preferOverdriveMediaMarker = false) {
|
rebuildTracks(preferOverdriveMediaMarker) {
|
||||||
Logger.debug(`[Book] we are rebuilding the tracks!`)
|
Logger.debug(`[Book] we are rebuilding the tracks!`)
|
||||||
Logger.debug(`[Book] preferOverdriveMediaMarker: ${preferOverdriveMediaMarker}`)
|
Logger.debug(`[Book] preferOverdriveMediaMarker: ${JSON.stringify(preferOverdriveMediaMarker)}`)
|
||||||
this.audioFiles.sort((a, b) => a.index - b.index)
|
this.audioFiles.sort((a, b) => a.index - b.index)
|
||||||
this.missingParts = []
|
this.missingParts = []
|
||||||
this.setChapters(preferOverdriveMediaMarker)
|
this.setChapters(preferOverdriveMediaMarker)
|
||||||
@ -491,11 +491,24 @@ class Book {
|
|||||||
return newOChapters
|
return newOChapters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getOverdriveMediaMarkers(audioFiles) {
|
||||||
|
var markers = audioFiles.map((af) => af.metaTags.tagOverdriveMediaMarker).filter(notUndefined => notUndefined !== undefined).filter(elem => { return elem !== null }) || []
|
||||||
|
return markers
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
setChapters(preferOverdriveMediaMarker = false) {
|
setChapters(preferOverdriveMediaMarker = false) {
|
||||||
Logger.debug('[Book] inside setChapters!')
|
|
||||||
// If 1 audio file without chapters, then no chapters will be set
|
// If 1 audio file without chapters, then no chapters will be set
|
||||||
var includedAudioFiles = this.audioFiles.filter(af => !af.exclude)
|
var includedAudioFiles = this.audioFiles.filter(af => !af.exclude)
|
||||||
|
|
||||||
|
var overdriveMediaMarkers = this.getOverdriveMediaMarkers(includedAudioFiles)
|
||||||
|
|
||||||
|
// If preferOverdriveMediaMarker is set, try and use that first
|
||||||
|
// fallback to non-overdrive chapters if there are no Overdrive Media Markers available
|
||||||
|
if (preferOverdriveMediaMarker && (overdriveMediaMarkers.length > 0)) {
|
||||||
|
Logger.debug(`[Book] preferring overdrive media markers! Lets generate em.`)
|
||||||
|
this.chapters = this.generateChaptersFromOverdriveMediaMarkers(overdriveMediaMarkers, includedAudioFiles)
|
||||||
|
} else {
|
||||||
if (includedAudioFiles.length === 1) {
|
if (includedAudioFiles.length === 1) {
|
||||||
// 1 audio file with chapters
|
// 1 audio file with chapters
|
||||||
if (includedAudioFiles[0].chapters) {
|
if (includedAudioFiles[0].chapters) {
|
||||||
@ -505,15 +518,6 @@ class Book {
|
|||||||
this.chapters = []
|
this.chapters = []
|
||||||
var currChapterId = 0
|
var currChapterId = 0
|
||||||
var currStartTime = 0
|
var currStartTime = 0
|
||||||
var overdriveMediaMarkers = includedAudioFiles.map((af) => af.metaTags.tagOverdriveMediaMarker).filter(notUndefined => notUndefined !== undefined) || []
|
|
||||||
Logger.debug(`[setChapters] overdriveMediaMarkers: ${JSON.stringify(overdriveMediaMarkers)}`)
|
|
||||||
|
|
||||||
// If preferOverdriveMediaMarker is set, try and use that first
|
|
||||||
if (preferOverdriveMediaMarker) {
|
|
||||||
Logger.debug(`[Book] preferring overdrive media markers! Lets generate em.`)
|
|
||||||
this.chapters = this.generateChaptersFromOverdriveMediaMarkers(overdriveMediaMarkers, includedAudioFiles)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
includedAudioFiles.forEach((file) => {
|
includedAudioFiles.forEach((file) => {
|
||||||
//console.log(`audiofile MetaTags Overdrive: ${JSON.stringify(file.metaTags.tagOverdriveMediaMarker)}}`)
|
//console.log(`audiofile MetaTags Overdrive: ${JSON.stringify(file.metaTags.tagOverdriveMediaMarker)}}`)
|
||||||
// If audio file has chapters use chapters
|
// If audio file has chapters use chapters
|
||||||
|
@ -195,7 +195,7 @@ class MediaFileScanner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async scanMediaFiles(mediaLibraryFiles, scanData, libraryItem, preferAudioMetadata, libraryScan = null) {
|
async scanMediaFiles(mediaLibraryFiles, scanData, libraryItem, preferAudioMetadata, preferOverdriveMediaMarker, libraryScan = null) {
|
||||||
Logger.debug('[scanMediaFiles] inside scan media files!')
|
Logger.debug('[scanMediaFiles] inside scan media files!')
|
||||||
Logger.debug(`[scanMediaFiles] libraryScan: ${JSON.stringify(libraryScan)}`)
|
Logger.debug(`[scanMediaFiles] libraryScan: ${JSON.stringify(libraryScan)}`)
|
||||||
|
|
||||||
@ -257,8 +257,8 @@ class MediaFileScanner {
|
|||||||
|
|
||||||
if (hasUpdated) {
|
if (hasUpdated) {
|
||||||
Logger.debug('[MediaFileScanner] hasUpdated is true! Going to rebuild tracks now...')
|
Logger.debug('[MediaFileScanner] hasUpdated is true! Going to rebuild tracks now...')
|
||||||
Logger.debug(`[MediaFileScanner] libraryScan: ${JSON.stringify(libraryScan)}`)
|
Logger.debug(`[MediaFileScanner] preferOverdriveMediaMarker: ${JSON.stringify(preferOverdriveMediaMarker)}`)
|
||||||
libraryItem.media.rebuildTracks(libraryScan.scanOptions.preferOverdriveMediaMarker)
|
libraryItem.media.rebuildTracks(preferOverdriveMediaMarker)
|
||||||
}
|
}
|
||||||
} else { // Podcast Media Type
|
} else { // Podcast Media Type
|
||||||
var existingAudioFiles = mediaScanResult.audioFiles.filter(af => libraryItem.media.findFileWithInode(af.ino))
|
var existingAudioFiles = mediaScanResult.audioFiles.filter(af => libraryItem.media.findFileWithInode(af.ino))
|
||||||
|
@ -81,7 +81,7 @@ class Scanner {
|
|||||||
// Scan all audio files
|
// Scan all audio files
|
||||||
if (libraryItem.hasAudioFiles) {
|
if (libraryItem.hasAudioFiles) {
|
||||||
var libraryAudioFiles = libraryItem.libraryFiles.filter(lf => lf.fileType === 'audio')
|
var libraryAudioFiles = libraryItem.libraryFiles.filter(lf => lf.fileType === 'audio')
|
||||||
if (await MediaFileScanner.scanMediaFiles(libraryAudioFiles, libraryItemData, libraryItem, this.db.serverSettings.scannerPreferAudioMetadata)) {
|
if (await MediaFileScanner.scanMediaFiles(libraryAudioFiles, libraryItemData, libraryItem, this.db.serverSettings.scannerPreferAudioMetadata, this.db.serverSettings.scannerPreferOverdriveMediaMarker)) {
|
||||||
hasUpdated = true
|
hasUpdated = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ class Scanner {
|
|||||||
|
|
||||||
async scanNewLibraryItemDataChunk(newLibraryItemsData, libraryScan) {
|
async scanNewLibraryItemDataChunk(newLibraryItemsData, libraryScan) {
|
||||||
var newLibraryItems = await Promise.all(newLibraryItemsData.map((lid) => {
|
var newLibraryItems = await Promise.all(newLibraryItemsData.map((lid) => {
|
||||||
return this.scanNewLibraryItem(lid, libraryScan.libraryMediaType, libraryScan.preferAudioMetadata, libraryScan.preferOpfMetadata, libraryScan.findCovers, libraryScan)
|
return this.scanNewLibraryItem(lid, libraryScan.libraryMediaType, libraryScan.preferAudioMetadata, libraryScan.preferOpfMetadata, libraryScan.findCovers, libraryScan.preferOverdriveMediaMarker, libraryScan)
|
||||||
}))
|
}))
|
||||||
newLibraryItems = newLibraryItems.filter(li => li) // Filter out nulls
|
newLibraryItems = newLibraryItems.filter(li => li) // Filter out nulls
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ class Scanner {
|
|||||||
// forceRescan all existing audio files - will probe and update ID3 tag metadata
|
// forceRescan all existing audio files - will probe and update ID3 tag metadata
|
||||||
var existingAudioFiles = existingLibraryFiles.filter(lf => lf.fileType === 'audio')
|
var existingAudioFiles = existingLibraryFiles.filter(lf => lf.fileType === 'audio')
|
||||||
if (libraryScan.scanOptions.forceRescan && existingAudioFiles.length) {
|
if (libraryScan.scanOptions.forceRescan && existingAudioFiles.length) {
|
||||||
if (await MediaFileScanner.scanMediaFiles(existingAudioFiles, scanData, libraryItem, libraryScan.preferAudioMetadata, libraryScan)) {
|
if (await MediaFileScanner.scanMediaFiles(existingAudioFiles, scanData, libraryItem, libraryScan.preferAudioMetadata, libraryScan.preferOverdriveMediaMarker, libraryScan)) {
|
||||||
hasUpdated = true
|
hasUpdated = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ class Scanner {
|
|||||||
var newAudioFiles = newLibraryFiles.filter(lf => lf.fileType === 'audio')
|
var newAudioFiles = newLibraryFiles.filter(lf => lf.fileType === 'audio')
|
||||||
var removedAudioFiles = filesRemoved.filter(lf => lf.fileType === 'audio')
|
var removedAudioFiles = filesRemoved.filter(lf => lf.fileType === 'audio')
|
||||||
if (newAudioFiles.length || removedAudioFiles.length) {
|
if (newAudioFiles.length || removedAudioFiles.length) {
|
||||||
if (await MediaFileScanner.scanMediaFiles(newAudioFiles, scanData, libraryItem, libraryScan.preferAudioMetadata, libraryScan)) {
|
if (await MediaFileScanner.scanMediaFiles(newAudioFiles, scanData, libraryItem, libraryScan.preferAudioMetadata, libraryScan.preferOverdriveMediaMarker, libraryScan)) {
|
||||||
hasUpdated = true
|
hasUpdated = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -384,7 +384,7 @@ class Scanner {
|
|||||||
return hasUpdated ? libraryItem : null
|
return hasUpdated ? libraryItem : null
|
||||||
}
|
}
|
||||||
|
|
||||||
async scanNewLibraryItem(libraryItemData, libraryMediaType, preferAudioMetadata, preferOpfMetadata, findCovers, libraryScan = null) {
|
async scanNewLibraryItem(libraryItemData, libraryMediaType, preferAudioMetadata, preferOpfMetadata, findCovers, preferOverdriveMediaMarker, libraryScan = null) {
|
||||||
if (libraryScan) libraryScan.addLog(LogLevel.DEBUG, `Scanning new library item "${libraryItemData.path}"`)
|
if (libraryScan) libraryScan.addLog(LogLevel.DEBUG, `Scanning new library item "${libraryItemData.path}"`)
|
||||||
else Logger.debug(`[Scanner] Scanning new item "${libraryItemData.path}"`)
|
else Logger.debug(`[Scanner] Scanning new item "${libraryItemData.path}"`)
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ class Scanner {
|
|||||||
|
|
||||||
var mediaFiles = libraryItemData.libraryFiles.filter(lf => lf.fileType === 'audio' || lf.fileType === 'video')
|
var mediaFiles = libraryItemData.libraryFiles.filter(lf => lf.fileType === 'audio' || lf.fileType === 'video')
|
||||||
if (mediaFiles.length) {
|
if (mediaFiles.length) {
|
||||||
await MediaFileScanner.scanMediaFiles(mediaFiles, libraryItemData, libraryItem, preferAudioMetadata, libraryScan)
|
await MediaFileScanner.scanMediaFiles(mediaFiles, libraryItemData, libraryItem, preferAudioMetadata, preferOverdriveMediaMarker, libraryScan)
|
||||||
}
|
}
|
||||||
|
|
||||||
await libraryItem.syncFiles(preferOpfMetadata)
|
await libraryItem.syncFiles(preferOpfMetadata)
|
||||||
@ -613,7 +613,7 @@ class Scanner {
|
|||||||
var libraryItemData = await getLibraryItemFileData(libraryMediaType, folder, fullPath, isSingleMediaItem, this.db.serverSettings)
|
var libraryItemData = await getLibraryItemFileData(libraryMediaType, folder, fullPath, isSingleMediaItem, this.db.serverSettings)
|
||||||
if (!libraryItemData) return null
|
if (!libraryItemData) return null
|
||||||
var serverSettings = this.db.serverSettings
|
var serverSettings = this.db.serverSettings
|
||||||
return this.scanNewLibraryItem(libraryItemData, libraryMediaType, serverSettings.scannerPreferAudioMetadata, serverSettings.scannerPreferOpfMetadata, serverSettings.scannerFindCovers)
|
return this.scanNewLibraryItem(libraryItemData, libraryMediaType, serverSettings.scannerPreferAudioMetadata, serverSettings.scannerPreferOpfMetadata, serverSettings.scannerFindCovers, serverSettings.scannerPreferOverdriveMediaMarker)
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchForCover(libraryItem, libraryScan = null) {
|
async searchForCover(libraryItem, libraryScan = null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user