mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-09 21:39:37 +00:00
New scanner updates with library scan data
This commit is contained in:
parent
14128f3e29
commit
bf11d266dc
15 changed files with 428 additions and 135 deletions
|
|
@ -1,3 +1,5 @@
|
|||
const { isNullOrNaN } = require('../utils/index')
|
||||
|
||||
const Logger = require('../Logger')
|
||||
const AudioFileMetadata = require('./AudioFileMetadata')
|
||||
|
||||
|
|
@ -154,7 +156,7 @@ class AudioFile {
|
|||
}
|
||||
|
||||
// New scanner creates AudioFile from AudioFileScanner
|
||||
setData2(fileData, probeData) {
|
||||
setDataFromProbe(fileData, probeData) {
|
||||
this.index = fileData.index || null
|
||||
this.ino = fileData.ino || null
|
||||
this.filename = fileData.filename
|
||||
|
|
@ -162,6 +164,42 @@ class AudioFile {
|
|||
this.path = fileData.path
|
||||
this.fullPath = fileData.fullPath
|
||||
this.addedAt = Date.now()
|
||||
|
||||
this.trackNumFromMeta = fileData.trackNumFromMeta || null
|
||||
this.trackNumFromFilename = fileData.trackNumFromFilename || null
|
||||
this.cdNumFromFilename = fileData.cdNumFromFilename || null
|
||||
|
||||
this.format = probeData.format
|
||||
this.duration = probeData.duration
|
||||
this.size = probeData.size
|
||||
this.bitRate = probeData.bitRate || null
|
||||
this.language = probeData.language
|
||||
this.codec = probeData.codec || null
|
||||
this.timeBase = probeData.timeBase
|
||||
this.channels = probeData.channels
|
||||
this.channelLayout = probeData.channelLayout
|
||||
this.chapters = probeData.chapters || []
|
||||
this.metadata = probeData.audioFileMetadata
|
||||
}
|
||||
|
||||
validateTrackIndex(isSingleTrack) {
|
||||
var numFromMeta = isNullOrNaN(this.trackNumFromMeta) ? null : Number(this.trackNumFromMeta)
|
||||
var numFromFilename = isNullOrNaN(this.trackNumFromFilename) ? null : Number(this.trackNumFromFilename)
|
||||
|
||||
if (isSingleTrack) { // Single audio track audiobook only use metadata tag and default to 1
|
||||
return numFromMeta ? numFromMeta : 1
|
||||
}
|
||||
if (numFromMeta !== null) return numFromMeta
|
||||
if (numFromFilename !== null) return numFromFilename
|
||||
|
||||
this.invalid = true
|
||||
this.error = 'Failed to get track number'
|
||||
return null
|
||||
}
|
||||
|
||||
setDuplicateTrackNumber(num) {
|
||||
this.invalid = true
|
||||
this.error = 'Duplicate track number "' + num + '"'
|
||||
}
|
||||
|
||||
syncChapters(updatedChapters) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const Path = require('path')
|
||||
const fs = require('fs-extra')
|
||||
const { bytesPretty, elapsedPretty, readTextFile } = require('../utils/fileUtils')
|
||||
const { comparePaths, getIno, getId } = require('../utils/index')
|
||||
const { bytesPretty, readTextFile } = require('../utils/fileUtils')
|
||||
const { comparePaths, getIno, getId, elapsedPretty } = require('../utils/index')
|
||||
const { parseOpfMetadataXML } = require('../utils/parseOpfMetadata')
|
||||
const { extractCoverArt } = require('../utils/ffmpegHelpers')
|
||||
const nfoGenerator = require('../utils/nfoGenerator')
|
||||
|
|
@ -128,6 +128,8 @@ class Audiobook {
|
|||
get _otherFiles() { return this.otherFiles || [] }
|
||||
get _tracks() { return this.tracks || [] }
|
||||
|
||||
get audioFilesToInclude() { return this._audioFiles.filter(af => !af.exclude) }
|
||||
|
||||
get ebooks() {
|
||||
return this.otherFiles.filter(file => file.filetype === 'ebook')
|
||||
}
|
||||
|
|
@ -346,6 +348,11 @@ class Audiobook {
|
|||
this.scanVersion = version
|
||||
}
|
||||
|
||||
setMissing() {
|
||||
this.isMissing = true
|
||||
this.lastUpdate = Date.now()
|
||||
}
|
||||
|
||||
setBook(data) {
|
||||
// Use first image file as cover
|
||||
if (this.otherFiles && this.otherFiles.length) {
|
||||
|
|
@ -353,7 +360,6 @@ class Audiobook {
|
|||
if (imageFile) {
|
||||
data.coverFullPath = imageFile.fullPath
|
||||
var relImagePath = imageFile.path.replace(this.path, '')
|
||||
console.log('SET BOOK PATH', imageFile.path, 'REPLACE', this.path, 'RESULT', relImagePath)
|
||||
data.cover = Path.posix.join(`/s/book/${this.id}`, relImagePath)
|
||||
}
|
||||
}
|
||||
|
|
@ -383,10 +389,15 @@ class Audiobook {
|
|||
}
|
||||
|
||||
addAudioFile(audioFileData) {
|
||||
var audioFile = new AudioFile()
|
||||
audioFile.setData(audioFileData)
|
||||
this.audioFiles.push(audioFile)
|
||||
return audioFile
|
||||
if (audioFileData instanceof AudioFile) {
|
||||
this.audioFiles.push(audioFileData)
|
||||
return audioFileData
|
||||
} else {
|
||||
var audioFile = new AudioFile()
|
||||
audioFile.setData(audioFileData)
|
||||
this.audioFiles.push(audioFile)
|
||||
return audioFile
|
||||
}
|
||||
}
|
||||
|
||||
addOtherFile(fileData) {
|
||||
|
|
@ -426,6 +437,10 @@ class Audiobook {
|
|||
return this.book.updateCover(cover, coverFullPath)
|
||||
}
|
||||
|
||||
checkHasTrackNum(trackNum) {
|
||||
return this.tracks.find(t => t.index === trackNum)
|
||||
}
|
||||
|
||||
updateAudioTracks(orderedFileData) {
|
||||
var index = 1
|
||||
this.audioFiles = orderedFileData.map((fileData) => {
|
||||
|
|
@ -444,8 +459,12 @@ class Audiobook {
|
|||
return audioFile
|
||||
})
|
||||
|
||||
this.audioFiles.sort((a, b) => a.index - b.index)
|
||||
this.rebuildTracks()
|
||||
}
|
||||
|
||||
// After audio files have been added/removed/updated this method sets tracks
|
||||
rebuildTracks() {
|
||||
this.audioFiles.sort((a, b) => a.index - b.index)
|
||||
this.tracks = []
|
||||
this.missingParts = []
|
||||
this.audioFiles.forEach((file) => {
|
||||
|
|
@ -570,7 +589,6 @@ class Audiobook {
|
|||
}
|
||||
})
|
||||
|
||||
|
||||
var imageFiles = this.otherFiles.filter(f => f.filetype === 'image')
|
||||
|
||||
// OLD Path Check if cover was a local image and that it still exists
|
||||
|
|
@ -866,7 +884,7 @@ class Audiobook {
|
|||
return hasUpdated
|
||||
}
|
||||
|
||||
checkShouldScan(dataFound) {
|
||||
checkScanData(dataFound) {
|
||||
var hasUpdated = false
|
||||
|
||||
if (dataFound.ino !== this.ino) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ class ServerSettings {
|
|||
// Scanner
|
||||
this.scannerParseSubtitle = false
|
||||
this.scannerFindCovers = false
|
||||
this.scannerPreferAudioMetadata = false
|
||||
this.scannerPreferOpfMetadata = false
|
||||
|
||||
// Metadata
|
||||
this.coverDestination = CoverDestination.METADATA
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ const EventEmitter = require('events')
|
|||
const Path = require('path')
|
||||
const fs = require('fs-extra')
|
||||
const Logger = require('../Logger')
|
||||
const { getId } = require('../utils/index')
|
||||
const { secondsToTimestamp } = require('../utils/fileUtils')
|
||||
const { getId, secondsToTimestamp } = require('../utils/index')
|
||||
const { writeConcatFile } = require('../utils/ffmpegHelpers')
|
||||
const hlsPlaylistGenerator = require('../utils/hlsPlaylistGenerator')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue