audiobookshelf/server/objects/entities/Podcast.js

133 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-03-09 02:31:44 +01:00
const PodcastEpisode = require('./PodcastEpisode')
const PodcastMetadata = require('../metadata/PodcastMetadata')
const { areEquivalent, copyValue } = require('../../utils/index')
2022-03-09 02:31:44 +01:00
class Podcast {
constructor(podcast) {
this.id = null
this.metadata = null
this.coverPath = null
this.tags = []
2022-03-09 02:31:44 +01:00
this.episodes = []
this.lastCoverSearch = null
this.lastCoverSearchQuery = null
2022-03-09 02:31:44 +01:00
if (podcast) {
this.construct(podcast)
}
}
construct(podcast) {
this.id = podcast.id
this.metadata = new PodcastMetadata(podcast.metadata)
this.coverPath = podcast.coverPath
this.tags = [...podcast.tags]
2022-03-09 02:31:44 +01:00
this.episodes = podcast.episodes.map((e) => new PodcastEpisode(e))
}
toJSON() {
return {
id: this.id,
metadata: this.metadata.toJSON(),
coverPath: this.coverPath,
tags: [...this.tags],
episodes: this.episodes.map(e => e.toJSON()),
}
}
toJSONMinified() {
return {
id: this.id,
metadata: this.metadata.toJSON(),
coverPath: this.coverPath,
tags: [...this.tags],
episodes: this.episodes.map(e => e.toJSON()),
}
}
toJSONExpanded() {
return {
id: this.id,
metadata: this.metadata.toJSONExpanded(),
coverPath: this.coverPath,
tags: [...this.tags],
2022-03-09 02:31:44 +01:00
episodes: this.episodes.map(e => e.toJSON()),
}
}
get tracks() {
return []
}
get duration() {
return 0
}
get size() {
return 0
}
get hasMediaFiles() {
return !!this.episodes.length
}
get shouldSearchForCover() {
return false
}
get hasEmbeddedCoverArt() {
return false
}
update(payload) {
var json = this.toJSON()
var hasUpdates = false
for (const key in json) {
if (payload[key] !== undefined) {
if (key === 'metadata') {
if (this.metadata.update(payload.metadata)) {
hasUpdates = true
}
} else if (!areEquivalent(payload[key], json[key])) {
this[key] = copyValue(payload[key])
Logger.debug('[Podcast] Key updated', key, this[key])
hasUpdates = true
}
}
2022-03-09 02:31:44 +01:00
}
return hasUpdates
}
updateCover(coverPath) {
coverPath = coverPath.replace(/\\/g, '/')
if (this.coverPath === coverPath) return false
this.coverPath = coverPath
return true
}
checkUpdateMissingTracks() {
return false
}
removeFileWithInode(inode) {
return false
}
findFileWithInode(inode) {
return null
}
setData(scanMediaMetadata) {
this.metadata = new PodcastMetadata()
this.metadata.setData(scanMediaMetadata)
}
async syncMetadataFiles(textMetadataFiles, opfMetadataOverrideDetails) {
return false
2022-03-09 02:31:44 +01:00
}
searchQuery(query) {
var payload = this.metadata.searchQuery(query)
return payload || {}
}
2022-03-09 02:31:44 +01:00
}
module.exports = Podcast