2022-04-12 23:05:16 +02:00
|
|
|
const Path = require('path')
|
2022-03-13 00:45:32 +01:00
|
|
|
const { version } = require('../../package.json')
|
2022-03-09 02:31:44 +01:00
|
|
|
const Logger = require('../Logger')
|
2022-04-12 23:05:16 +02:00
|
|
|
const abmetadataGenerator = require('../utils/abmetadataGenerator')
|
2022-03-09 02:31:44 +01:00
|
|
|
const LibraryFile = require('./files/LibraryFile')
|
2022-03-17 01:15:25 +01:00
|
|
|
const Book = require('./mediaTypes/Book')
|
|
|
|
const Podcast = require('./mediaTypes/Podcast')
|
2022-03-13 19:47:36 +01:00
|
|
|
const { areEquivalent, copyValue, getId } = require('../utils/index')
|
2022-03-09 02:31:44 +01:00
|
|
|
|
|
|
|
class LibraryItem {
|
|
|
|
constructor(libraryItem = null) {
|
|
|
|
this.id = null
|
|
|
|
this.ino = null // Inode
|
|
|
|
|
|
|
|
this.libraryId = null
|
|
|
|
this.folderId = null
|
|
|
|
|
|
|
|
this.path = null
|
|
|
|
this.relPath = null
|
|
|
|
this.mtimeMs = null
|
|
|
|
this.ctimeMs = null
|
|
|
|
this.birthtimeMs = null
|
|
|
|
this.addedAt = null
|
2022-03-11 01:45:02 +01:00
|
|
|
this.updatedAt = null
|
2022-03-09 02:31:44 +01:00
|
|
|
this.lastScan = null
|
|
|
|
this.scanVersion = null
|
|
|
|
|
2022-03-13 00:45:32 +01:00
|
|
|
// Was scanned and no longer exists
|
2022-03-09 02:31:44 +01:00
|
|
|
this.isMissing = false
|
2022-03-13 00:45:32 +01:00
|
|
|
// Was scanned and no longer has media files
|
|
|
|
this.isInvalid = false
|
2022-03-09 02:31:44 +01:00
|
|
|
|
2022-03-11 01:45:02 +01:00
|
|
|
this.mediaType = null
|
|
|
|
this.media = null
|
2022-03-09 02:31:44 +01:00
|
|
|
|
|
|
|
this.libraryFiles = []
|
|
|
|
|
|
|
|
if (libraryItem) {
|
|
|
|
this.construct(libraryItem)
|
|
|
|
}
|
2022-04-12 23:05:16 +02:00
|
|
|
|
|
|
|
// Temporary attributes
|
|
|
|
this.isSavingMetadata = false
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
construct(libraryItem) {
|
|
|
|
this.id = libraryItem.id
|
|
|
|
this.ino = libraryItem.ino || null
|
|
|
|
this.libraryId = libraryItem.libraryId
|
|
|
|
this.folderId = libraryItem.folderId
|
|
|
|
this.path = libraryItem.path
|
|
|
|
this.relPath = libraryItem.relPath
|
|
|
|
this.mtimeMs = libraryItem.mtimeMs || 0
|
|
|
|
this.ctimeMs = libraryItem.ctimeMs || 0
|
|
|
|
this.birthtimeMs = libraryItem.birthtimeMs || 0
|
|
|
|
this.addedAt = libraryItem.addedAt
|
2022-03-11 01:45:02 +01:00
|
|
|
this.updatedAt = libraryItem.updatedAt || this.addedAt
|
2022-03-09 02:31:44 +01:00
|
|
|
this.lastScan = libraryItem.lastScan || null
|
|
|
|
this.scanVersion = libraryItem.scanVersion || null
|
|
|
|
|
|
|
|
this.isMissing = !!libraryItem.isMissing
|
2022-03-13 00:45:32 +01:00
|
|
|
this.isInvalid = !!libraryItem.isInvalid
|
2022-03-09 02:31:44 +01:00
|
|
|
|
2022-03-11 01:45:02 +01:00
|
|
|
this.mediaType = libraryItem.mediaType
|
|
|
|
if (this.mediaType === 'book') {
|
|
|
|
this.media = new Book(libraryItem.media)
|
2022-04-03 23:01:59 +02:00
|
|
|
this.media.libraryItemId = this.id
|
2022-03-11 01:45:02 +01:00
|
|
|
} else if (this.mediaType === 'podcast') {
|
|
|
|
this.media = new Podcast(libraryItem.media)
|
2022-04-03 23:01:59 +02:00
|
|
|
this.media.libraryItemId = this.id
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.libraryFiles = libraryItem.libraryFiles.map(f => new LibraryFile(f))
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
ino: this.ino,
|
|
|
|
libraryId: this.libraryId,
|
|
|
|
folderId: this.folderId,
|
|
|
|
path: this.path,
|
|
|
|
relPath: this.relPath,
|
|
|
|
mtimeMs: this.mtimeMs,
|
|
|
|
ctimeMs: this.ctimeMs,
|
|
|
|
birthtimeMs: this.birthtimeMs,
|
|
|
|
addedAt: this.addedAt,
|
2022-03-11 01:45:02 +01:00
|
|
|
updatedAt: this.updatedAt,
|
2022-03-09 02:31:44 +01:00
|
|
|
lastScan: this.lastScan,
|
|
|
|
scanVersion: this.scanVersion,
|
|
|
|
isMissing: !!this.isMissing,
|
2022-03-13 00:45:32 +01:00
|
|
|
isInvalid: !!this.isInvalid,
|
2022-03-11 01:45:02 +01:00
|
|
|
mediaType: this.mediaType,
|
|
|
|
media: this.media.toJSON(),
|
2022-03-09 02:31:44 +01:00
|
|
|
libraryFiles: this.libraryFiles.map(f => f.toJSON())
|
|
|
|
}
|
|
|
|
}
|
2022-03-11 01:45:02 +01:00
|
|
|
|
|
|
|
toJSONMinified() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
ino: this.ino,
|
|
|
|
libraryId: this.libraryId,
|
|
|
|
folderId: this.folderId,
|
|
|
|
path: this.path,
|
|
|
|
relPath: this.relPath,
|
|
|
|
mtimeMs: this.mtimeMs,
|
|
|
|
ctimeMs: this.ctimeMs,
|
|
|
|
birthtimeMs: this.birthtimeMs,
|
|
|
|
addedAt: this.addedAt,
|
|
|
|
updatedAt: this.updatedAt,
|
|
|
|
isMissing: !!this.isMissing,
|
2022-03-13 00:45:32 +01:00
|
|
|
isInvalid: !!this.isInvalid,
|
2022-03-11 01:45:02 +01:00
|
|
|
mediaType: this.mediaType,
|
|
|
|
media: this.media.toJSONMinified(),
|
2022-03-17 18:25:12 +01:00
|
|
|
numFiles: this.libraryFiles.length,
|
|
|
|
size: this.size
|
2022-03-11 01:45:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds additional helpful fields like media duration, tracks, etc.
|
|
|
|
toJSONExpanded() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
ino: this.ino,
|
|
|
|
libraryId: this.libraryId,
|
|
|
|
folderId: this.folderId,
|
|
|
|
path: this.path,
|
|
|
|
relPath: this.relPath,
|
|
|
|
mtimeMs: this.mtimeMs,
|
|
|
|
ctimeMs: this.ctimeMs,
|
|
|
|
birthtimeMs: this.birthtimeMs,
|
|
|
|
addedAt: this.addedAt,
|
|
|
|
updatedAt: this.updatedAt,
|
|
|
|
lastScan: this.lastScan,
|
|
|
|
scanVersion: this.scanVersion,
|
|
|
|
isMissing: !!this.isMissing,
|
2022-03-13 00:45:32 +01:00
|
|
|
isInvalid: !!this.isInvalid,
|
2022-03-11 01:45:02 +01:00
|
|
|
mediaType: this.mediaType,
|
|
|
|
media: this.media.toJSONExpanded(),
|
|
|
|
libraryFiles: this.libraryFiles.map(f => f.toJSON()),
|
|
|
|
size: this.size
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get size() {
|
|
|
|
var total = 0
|
|
|
|
this.libraryFiles.forEach((lf) => total += lf.metadata.size)
|
|
|
|
return total
|
|
|
|
}
|
2022-03-18 15:16:10 +01:00
|
|
|
get audioFileTotalSize() {
|
|
|
|
var total = 0
|
|
|
|
this.libraryFiles.filter(lf => lf.fileType == 'audio').forEach((lf) => total += lf.metadata.size)
|
|
|
|
return total
|
|
|
|
}
|
2022-03-13 00:45:32 +01:00
|
|
|
get hasAudioFiles() {
|
|
|
|
return this.libraryFiles.some(lf => lf.fileType === 'audio')
|
|
|
|
}
|
2022-03-17 01:15:25 +01:00
|
|
|
get hasMediaEntities() {
|
|
|
|
return this.media.hasMediaEntities
|
2022-03-13 00:45:32 +01:00
|
|
|
}
|
2022-03-18 18:37:47 +01:00
|
|
|
get hasIssues() {
|
|
|
|
if (this.isMissing || this.isInvalid) return true
|
|
|
|
return this.media.hasIssues
|
|
|
|
}
|
2022-03-13 00:45:32 +01:00
|
|
|
|
|
|
|
// Data comes from scandir library item data
|
|
|
|
setData(libraryMediaType, payload) {
|
2022-03-13 19:47:36 +01:00
|
|
|
this.id = getId('li')
|
2022-03-13 00:45:32 +01:00
|
|
|
if (libraryMediaType === 'podcast') {
|
|
|
|
this.mediaType = 'podcast'
|
|
|
|
this.media = new Podcast()
|
2022-04-03 23:01:59 +02:00
|
|
|
this.media.libraryItemId = this.id
|
2022-03-13 00:45:32 +01:00
|
|
|
} else {
|
|
|
|
this.mediaType = 'book'
|
|
|
|
this.media = new Book()
|
2022-04-03 23:01:59 +02:00
|
|
|
this.media.libraryItemId = this.id
|
2022-03-13 00:45:32 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 01:24:38 +01:00
|
|
|
|
2022-03-13 00:45:32 +01:00
|
|
|
for (const key in payload) {
|
|
|
|
if (key === 'libraryFiles') {
|
|
|
|
this.libraryFiles = payload.libraryFiles.map(lf => lf.clone())
|
|
|
|
|
|
|
|
// Use first image library file as cover
|
|
|
|
var firstImageFile = this.libraryFiles.find(lf => lf.fileType === 'image')
|
|
|
|
if (firstImageFile) this.media.coverPath = firstImageFile.metadata.path
|
2022-03-22 01:24:38 +01:00
|
|
|
} else if (this[key] !== undefined && key !== 'media') {
|
2022-03-13 00:45:32 +01:00
|
|
|
this[key] = payload[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 01:24:38 +01:00
|
|
|
if (payload.media) {
|
|
|
|
this.media.setData(payload.media)
|
2022-03-13 00:45:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.addedAt = Date.now()
|
|
|
|
this.updatedAt = Date.now()
|
|
|
|
}
|
2022-03-12 02:46:32 +01:00
|
|
|
|
|
|
|
update(payload) {
|
|
|
|
var json = this.toJSON()
|
|
|
|
var hasUpdates = false
|
|
|
|
for (const key in json) {
|
|
|
|
if (payload[key] !== undefined) {
|
|
|
|
if (key === 'media') {
|
|
|
|
if (this.media.update(payload[key])) {
|
|
|
|
hasUpdates = true
|
|
|
|
}
|
|
|
|
} else if (!areEquivalent(payload[key], json[key])) {
|
|
|
|
this[key] = copyValue(payload[key])
|
|
|
|
hasUpdates = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-13 00:45:32 +01:00
|
|
|
if (hasUpdates) {
|
|
|
|
this.updatedAt = Date.now()
|
|
|
|
}
|
2022-03-12 02:46:32 +01:00
|
|
|
return hasUpdates
|
|
|
|
}
|
2022-03-13 00:45:32 +01:00
|
|
|
|
|
|
|
updateMediaCover(coverPath) {
|
|
|
|
this.media.updateCover(coverPath)
|
|
|
|
this.updatedAt = Date.now()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
setMissing() {
|
|
|
|
this.isMissing = true
|
|
|
|
this.updatedAt = Date.now()
|
|
|
|
}
|
|
|
|
|
|
|
|
setInvalid() {
|
|
|
|
this.isInvalid = true
|
|
|
|
this.updatedAt = Date.now()
|
|
|
|
}
|
|
|
|
|
|
|
|
setLastScan() {
|
|
|
|
this.lastScan = Date.now()
|
|
|
|
this.scanVersion = version
|
|
|
|
}
|
|
|
|
|
|
|
|
saveMetadata() { }
|
|
|
|
|
|
|
|
// Returns null if file not found, true if file was updated, false if up to date
|
2022-03-26 20:29:49 +01:00
|
|
|
// updates existing LibraryFile, AudioFile, EBookFile's
|
2022-03-13 00:45:32 +01:00
|
|
|
checkFileFound(fileFound) {
|
|
|
|
var hasUpdated = false
|
|
|
|
|
|
|
|
var existingFile = this.libraryFiles.find(lf => lf.ino === fileFound.ino)
|
|
|
|
var mediaFile = null
|
|
|
|
if (!existingFile) {
|
|
|
|
existingFile = this.libraryFiles.find(lf => lf.metadata.path === fileFound.metadata.path)
|
|
|
|
if (existingFile) {
|
|
|
|
// Update media file ino
|
|
|
|
mediaFile = this.media.findFileWithInode(existingFile.ino)
|
|
|
|
if (mediaFile) {
|
|
|
|
mediaFile.ino = fileFound.ino
|
|
|
|
}
|
|
|
|
|
|
|
|
// file inode was updated
|
|
|
|
existingFile.ino = fileFound.ino
|
|
|
|
hasUpdated = true
|
|
|
|
} else {
|
|
|
|
// file not found
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mediaFile = this.media.findFileWithInode(existingFile.ino)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (existingFile.metadata.path !== fileFound.metadata.path) {
|
|
|
|
existingFile.metadata.path = fileFound.metadata.path
|
|
|
|
existingFile.metadata.relPath = fileFound.metadata.relPath
|
|
|
|
if (mediaFile) {
|
|
|
|
mediaFile.metadata.path = fileFound.metadata.path
|
|
|
|
mediaFile.metadata.relPath = fileFound.metadata.relPath
|
|
|
|
}
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
|
2022-03-26 20:29:49 +01:00
|
|
|
// FileMetadata keys
|
|
|
|
['filename', 'ext', 'mtimeMs', 'ctimeMs', 'birthtimeMs', 'size'].forEach((key) => {
|
2022-03-13 00:45:32 +01:00
|
|
|
if (existingFile.metadata[key] !== fileFound.metadata[key]) {
|
|
|
|
|
|
|
|
// Add modified flag on file data object if exists and was changed
|
|
|
|
if (key === 'mtimeMs' && existingFile.metadata[key]) {
|
|
|
|
fileFound.metadata.wasModified = true
|
|
|
|
}
|
|
|
|
|
|
|
|
existingFile.metadata[key] = fileFound.metadata[key]
|
|
|
|
if (mediaFile) {
|
|
|
|
if (key === 'mtimeMs') mediaFile.metadata.wasModified = true
|
|
|
|
mediaFile.metadata[key] = fileFound.metadata[key]
|
|
|
|
}
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return hasUpdated
|
|
|
|
}
|
|
|
|
|
|
|
|
// Data pulled from scandir during a scan, check it with current data
|
|
|
|
checkScanData(dataFound) {
|
|
|
|
var hasUpdated = false
|
|
|
|
|
|
|
|
if (this.isMissing) {
|
|
|
|
// Item no longer missing
|
|
|
|
this.isMissing = false
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataFound.ino !== this.ino) {
|
|
|
|
this.ino = dataFound.ino
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataFound.folderId !== this.folderId) {
|
|
|
|
Logger.warn(`[LibraryItem] Check scan item changed folder ${this.folderId} -> ${dataFound.folderId}`)
|
|
|
|
this.folderId = dataFound.folderId
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataFound.path !== this.path) {
|
|
|
|
Logger.warn(`[LibraryItem] Check scan item changed path "${this.path}" -> "${dataFound.path}"`)
|
|
|
|
this.path = dataFound.path
|
|
|
|
this.relPath = dataFound.relPath
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
|
2022-03-26 20:29:49 +01:00
|
|
|
['mtimeMs', 'ctimeMs', 'birthtimeMs'].forEach((key) => {
|
2022-03-13 00:45:32 +01:00
|
|
|
if (dataFound[key] != this[key]) {
|
|
|
|
this[key] = dataFound[key] || 0
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var newLibraryFiles = []
|
|
|
|
var existingLibraryFiles = []
|
|
|
|
|
|
|
|
dataFound.libraryFiles.forEach((lf) => {
|
|
|
|
var fileFoundCheck = this.checkFileFound(lf, true)
|
|
|
|
if (fileFoundCheck === null) {
|
|
|
|
newLibraryFiles.push(lf)
|
|
|
|
} else if (fileFoundCheck) {
|
|
|
|
hasUpdated = true
|
|
|
|
existingLibraryFiles.push(lf)
|
|
|
|
} else {
|
|
|
|
existingLibraryFiles.push(lf)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const filesRemoved = []
|
|
|
|
|
|
|
|
// Remove files not found (inodes will all be up to date at this point)
|
|
|
|
this.libraryFiles = this.libraryFiles.filter(lf => {
|
|
|
|
if (!dataFound.libraryFiles.find(_lf => _lf.ino === lf.ino)) {
|
2022-03-26 20:29:49 +01:00
|
|
|
// Check if removing cover path
|
2022-03-13 00:45:32 +01:00
|
|
|
if (lf.metadata.path === this.media.coverPath) {
|
|
|
|
Logger.debug(`[LibraryItem] "${this.media.metadata.title}" check scan cover removed`)
|
|
|
|
this.media.updateCover('')
|
|
|
|
}
|
|
|
|
filesRemoved.push(lf.toJSON())
|
|
|
|
this.media.removeFileWithInode(lf.ino)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
if (filesRemoved.length) {
|
2022-03-26 17:59:34 +01:00
|
|
|
if (this.media.mediaType === 'book') {
|
|
|
|
this.media.checkUpdateMissingTracks()
|
2022-03-18 15:16:10 +01:00
|
|
|
}
|
2022-03-13 00:45:32 +01:00
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add library files to library item
|
|
|
|
if (newLibraryFiles.length) {
|
|
|
|
newLibraryFiles.forEach((lf) => this.libraryFiles.push(lf.clone()))
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if invalid
|
2022-03-17 01:15:25 +01:00
|
|
|
this.isInvalid = !this.media.hasMediaEntities
|
2022-03-13 00:45:32 +01:00
|
|
|
|
|
|
|
// If cover path is in item folder, make sure libraryFile exists for it
|
|
|
|
if (this.media.coverPath && this.media.coverPath.startsWith(this.path)) {
|
|
|
|
var lf = this.libraryFiles.find(lf => lf.metadata.path === this.media.coverPath)
|
|
|
|
if (!lf) {
|
|
|
|
Logger.warn(`[LibraryItem] Invalid cover path - library file dne "${this.media.coverPath}"`)
|
|
|
|
this.media.updateCover('')
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasUpdated) {
|
|
|
|
this.setLastScan()
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
updated: hasUpdated,
|
|
|
|
newLibraryFiles,
|
|
|
|
filesRemoved,
|
|
|
|
existingLibraryFiles // Existing file data may get re-scanned if forceRescan is set
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set metadata from files
|
|
|
|
async syncFiles(preferOpfMetadata) {
|
2022-03-13 19:47:36 +01:00
|
|
|
var hasUpdated = false
|
|
|
|
|
|
|
|
if (this.mediaType === 'book') {
|
2022-03-26 17:59:34 +01:00
|
|
|
// Add/update ebook file (ebooks that were removed are removed in checkScanData)
|
2022-03-13 19:47:36 +01:00
|
|
|
this.libraryFiles.forEach((lf) => {
|
|
|
|
if (lf.fileType === 'ebook') {
|
2022-03-26 17:59:34 +01:00
|
|
|
if (!this.media.ebookFile) {
|
|
|
|
this.media.setEbookFile(lf)
|
|
|
|
hasUpdated = true
|
|
|
|
} else if (this.media.ebookFile.ino == lf.ino && this.media.ebookFile.updateFromLibraryFile(lf)) { // Update existing ebookFile
|
2022-03-13 19:47:36 +01:00
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set cover image if not set
|
2022-03-13 00:45:32 +01:00
|
|
|
var imageFiles = this.libraryFiles.filter(lf => lf.fileType === 'image')
|
|
|
|
if (imageFiles.length && !this.media.coverPath) {
|
|
|
|
this.media.coverPath = imageFiles[0].metadata.path
|
|
|
|
Logger.debug('[LibraryItem] Set media cover path', this.media.coverPath)
|
2022-03-13 19:47:36 +01:00
|
|
|
hasUpdated = true
|
2022-03-13 00:45:32 +01:00
|
|
|
}
|
|
|
|
|
2022-03-13 19:47:36 +01:00
|
|
|
// Parse metadata files
|
2022-03-13 00:45:32 +01:00
|
|
|
var textMetadataFiles = this.libraryFiles.filter(lf => lf.fileType === 'metadata' || lf.fileType === 'text')
|
2022-03-13 19:47:36 +01:00
|
|
|
if (textMetadataFiles.length) {
|
|
|
|
if (await this.media.syncMetadataFiles(textMetadataFiles, preferOpfMetadata)) {
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
2022-03-13 00:45:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hasUpdated) {
|
|
|
|
this.updatedAt = Date.now()
|
|
|
|
}
|
|
|
|
return hasUpdated
|
|
|
|
}
|
2022-03-13 18:39:12 +01:00
|
|
|
|
|
|
|
searchQuery(query) {
|
|
|
|
query = query.toLowerCase()
|
|
|
|
return this.media.searchQuery(query)
|
|
|
|
}
|
2022-03-17 01:15:25 +01:00
|
|
|
|
2022-04-03 23:01:59 +02:00
|
|
|
getDirectPlayTracklist(episodeId) {
|
|
|
|
return this.media.getDirectPlayTracklist(episodeId)
|
2022-03-17 01:15:25 +01:00
|
|
|
}
|
2022-04-12 23:05:16 +02:00
|
|
|
|
|
|
|
// Saves metadata.abs file
|
|
|
|
async saveMetadata() {
|
|
|
|
if (this.isSavingMetadata) return
|
|
|
|
this.isSavingMetadata = true
|
|
|
|
|
|
|
|
var metadataPath = Path.join(global.MetadataPath, 'items', this.id)
|
|
|
|
if (global.ServerSettings.storeMetadataWithItem) {
|
|
|
|
metadataPath = this.path
|
|
|
|
} else {
|
|
|
|
// Make sure metadata book dir exists
|
|
|
|
await fs.ensureDir(metadataPath)
|
|
|
|
}
|
|
|
|
metadataPath = Path.join(metadataPath, 'metadata.abs')
|
|
|
|
|
|
|
|
return abmetadataGenerator.generate(this, metadataPath).then((success) => {
|
|
|
|
this.isSavingMetadata = false
|
|
|
|
if (!success) Logger.error(`[LibraryItem] Failed saving abmetadata to "${metadataPath}"`)
|
|
|
|
else Logger.debug(`[LibraryItem] Success saving abmetadata to "${metadataPath}"`)
|
|
|
|
return success
|
|
|
|
})
|
|
|
|
}
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
module.exports = LibraryItem
|