Adding files tables, fixing loading when switching streams

This commit is contained in:
Mark Cooper 2021-08-18 18:31:19 -05:00
parent 30ca0bb95f
commit a89d2e71cc
18 changed files with 233 additions and 76 deletions

View file

@ -14,7 +14,6 @@ class Audiobook {
this.invalidParts = []
this.audioFiles = []
this.ebookFiles = []
this.otherFiles = []
this.tags = []
@ -38,7 +37,6 @@ class Audiobook {
this.invalidParts = audiobook.invalidParts
this.audioFiles = audiobook.audioFiles
this.ebookFiles = audiobook.ebookFiles
this.otherFiles = audiobook.otherFiles
this.tags = audiobook.tags
@ -103,7 +101,6 @@ class Audiobook {
book: this.bookToJSON(),
tracks: this.tracksToJSON(),
audioFiles: this.audioFiles,
ebookFiles: this.ebookFiles,
otherFiles: this.otherFiles
}
}
@ -141,7 +138,6 @@ class Audiobook {
missingParts: this.missingParts,
invalidParts: this.invalidParts,
audioFiles: this.audioFiles,
ebookFiles: this.ebookFiles,
otherFiles: this.otherFiles,
tags: this.tags,
book: this.bookToJSON(),
@ -156,7 +152,6 @@ class Audiobook {
this.addedAt = Date.now()
this.otherFiles = data.otherFiles || []
this.ebookFiles = data.ebooks || []
this.setBook(data)
}

View file

@ -83,7 +83,8 @@ class Stream extends EventEmitter {
clientPlaylistUri: this.clientPlaylistUri,
clientCurrentTime: this.clientCurrentTime,
startTime: this.startTime,
segmentStartNumber: this.segmentStartNumber
segmentStartNumber: this.segmentStartNumber,
isTranscodeComplete: this.isTranscodeComplete
}
}

View file

@ -92,17 +92,14 @@ async function scanParts(audiobook, parts) {
continue;
}
var audioFileObj = {
path: parts[i],
filename: Path.basename(parts[i]),
fullPath: fullPath
}
var trackNumFromMeta = getTrackNumberFromMeta(scanData)
var trackNumFromFilename = getTrackNumberFromFilename(parts[i])
audioFileObj = {
...audioFileObj,
var audioFileObj = {
path: Path.join(audiobook.path, parts[i]),
ext: Path.extname(parts[i]),
filename: parts[i],
fullPath: fullPath,
...scanData,
trackNumFromMeta,
trackNumFromFilename
@ -129,15 +126,8 @@ async function scanParts(audiobook, parts) {
continue;
}
var track = {
index: trackNumber,
filename: parts[i],
ext: Path.extname(parts[i]),
path: Path.join(audiobook.path, parts[i]),
fullPath: Path.join(audiobook.fullPath, parts[i]),
...scanData
}
tracks.push(track)
audioFileObj.index = trackNumber
tracks.push(audioFileObj)
}
if (!tracks.length) {

View file

@ -26,47 +26,44 @@ function getFileType(ext) {
if (INFO_FORMATS.includes(ext_cleaned)) return 'info'
if (IMAGE_FORMATS.includes(ext_cleaned)) return 'image'
if (EBOOK_FORMATS.includes(ext_cleaned)) return 'ebook'
return null
return 'unknown'
}
async function getAllAudiobookFiles(path) {
console.log('getAllAudiobooks', path)
var paths = await getPaths(path)
var books = {}
var audiobooks = {}
paths.files.forEach((filepath) => {
var relpath = filepath.replace(path, '').slice(1)
var pathformat = Path.parse(relpath)
var authordir = Path.dirname(pathformat.dir)
var bookdir = Path.basename(pathformat.dir)
if (!books[bookdir]) {
books[bookdir] = {
if (!audiobooks[bookdir]) {
audiobooks[bookdir] = {
author: authordir,
title: bookdir,
path: pathformat.dir,
fullPath: Path.join(path, pathformat.dir),
parts: [],
infos: [],
images: [],
ebooks: [],
otherFiles: []
}
}
var filetype = getFileType(pathformat.ext)
if (filetype === 'abpart') {
books[bookdir].parts.push(`${pathformat.name}${pathformat.ext}`)
} else if (filetype === 'info') {
books[bookdir].infos.push(`${pathformat.name}${pathformat.ext}`)
} else if (filetype === 'image') {
books[bookdir].images.push(`${pathformat.name}${pathformat.ext}`)
} else if (filetype === 'ebook') {
books[bookdir].ebooks.push(`${pathformat.name}${pathformat.ext}`)
audiobooks[bookdir].parts.push(pathformat.base)
} else {
Logger.warn('Invalid file type', pathformat.name, pathformat.ext)
books[bookdir].otherFiles.push(`${pathformat.name}${pathformat.ext}`)
var fileObj = {
filetype: filetype,
filename: pathformat.base,
path: relpath,
fullPath: filepath,
ext: pathformat.ext
}
audiobooks[bookdir].otherFiles.push(fileObj)
}
})
return Object.values(books)
return Object.values(audiobooks)
}
module.exports.getAllAudiobookFiles = getAllAudiobookFiles