Add Scanner support for podcasts

This commit is contained in:
advplyr 2022-03-26 14:29:49 -05:00
parent 86e7c7fc33
commit 5446aea910
8 changed files with 84 additions and 28 deletions

View file

@ -166,7 +166,6 @@ class LibraryItem {
} else {
this.mediaType = 'book'
this.media = new Book()
}
@ -235,6 +234,7 @@ class LibraryItem {
saveMetadata() { }
// Returns null if file not found, true if file was updated, false if up to date
// updates existing LibraryFile, AudioFile, EBookFile's
checkFileFound(fileFound) {
var hasUpdated = false
@ -270,8 +270,8 @@ class LibraryItem {
hasUpdated = true
}
var keysToCheck = ['filename', 'ext', 'mtimeMs', 'ctimeMs', 'birthtimeMs', 'size']
keysToCheck.forEach((key) => {
// FileMetadata keys
['filename', 'ext', 'mtimeMs', 'ctimeMs', 'birthtimeMs', 'size'].forEach((key) => {
if (existingFile.metadata[key] !== fileFound.metadata[key]) {
// Add modified flag on file data object if exists and was changed
@ -319,8 +319,7 @@ class LibraryItem {
hasUpdated = true
}
var keysToCheck = ['mtimeMs', 'ctimeMs', 'birthtimeMs']
keysToCheck.forEach((key) => {
['mtimeMs', 'ctimeMs', 'birthtimeMs'].forEach((key) => {
if (dataFound[key] != this[key]) {
this[key] = dataFound[key] || 0
hasUpdated = true
@ -347,6 +346,7 @@ class LibraryItem {
// 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)) {
// Check if removing cover path
if (lf.metadata.path === this.media.coverPath) {
Logger.debug(`[LibraryItem] "${this.media.metadata.title}" check scan cover removed`)
this.media.updateCover('')
@ -395,10 +395,6 @@ class LibraryItem {
}
}
findLibraryFileWithIno(inode) {
return this.libraryFiles.find(lf => lf.ino === inode)
}
// Set metadata from files
async syncFiles(preferOpfMetadata) {
var hasUpdated = false

View file

@ -86,6 +86,15 @@ class PodcastEpisode {
this.updatedAt = Date.now()
}
setDataFromAudioFile(audioFile, index) {
this.id = getId('ep')
this.audioFile = audioFile
this.title = audioFile.metadata.filename
this.index = index
this.addedAt = Date.now()
this.updatedAt = Date.now()
}
// Only checks container format
checkCanDirectPlay(payload) {
var supportedMimeTypes = payload.supportedMimeTypes || []

View file

@ -1,6 +1,10 @@
const PodcastEpisode = require('../entities/PodcastEpisode')
const PodcastMetadata = require('../metadata/PodcastMetadata')
const { areEquivalent, copyValue } = require('../../utils/index')
const { createNewSortInstance } = require('fast-sort')
const naturalSort = createNewSortInstance({
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
})
class Podcast {
constructor(podcast) {
@ -69,7 +73,7 @@ class Podcast {
return false
}
get hasEmbeddedCoverArt() {
return false
return this.episodes.some(ep => ep.audioFile.embeddedCoverArt)
}
get hasIssues() {
return false
@ -111,11 +115,11 @@ class Podcast {
}
removeFileWithInode(inode) {
return false
this.episodes = this.episodes.filter(ep => ep.ino !== inode)
}
findFileWithInode(inode) {
return null
return this.episodes.find(ep => ep.audioFile.ino === inode)
}
setData(mediaMetadata) {
@ -137,10 +141,6 @@ class Podcast {
return payload || {}
}
addPodcastEpisode(podcastEpisode) {
this.episodes.push(podcastEpisode)
}
// Only checks container format
checkCanDirectPlay(payload, epsiodeIndex = 0) {
var episode = this.episodes[epsiodeIndex]
@ -151,5 +151,27 @@ class Podcast {
var episode = this.episodes[episodeIndex]
return episode.getDirectPlayTracklist(libraryItemId)
}
addPodcastEpisode(podcastEpisode) {
this.episodes.push(podcastEpisode)
}
addNewEpisodeFromAudioFile(audioFile, index) {
var pe = new PodcastEpisode()
pe.setDataFromAudioFile(audioFile, index)
this.episodes.push(pe)
}
reorderEpisodes() {
var hasUpdates = false
this.episodes = naturalSort(this.episodes).asc((ep) => ep.bestFilename)
for (let i = 0; i < this.episodes.length; i++) {
if (this.episodes[i].index !== (i + 1)) {
this.episodes[i].index = i + 1
hasUpdates = true
}
}
return hasUpdates
}
}
module.exports = Podcast