2022-03-09 02:31:44 +01:00
|
|
|
const PodcastEpisode = require('./PodcastEpisode')
|
|
|
|
const PodcastMetadata = require('../metadata/PodcastMetadata')
|
2022-03-13 00:45:32 +01:00
|
|
|
const { areEquivalent, copyValue } = require('../../utils/index')
|
2022-03-09 02:31:44 +01:00
|
|
|
|
|
|
|
class Podcast {
|
|
|
|
constructor(podcast) {
|
|
|
|
this.id = null
|
|
|
|
|
|
|
|
this.metadata = null
|
2022-03-11 01:45:02 +01:00
|
|
|
this.coverPath = null
|
|
|
|
this.tags = []
|
2022-03-09 02:31:44 +01:00
|
|
|
this.episodes = []
|
|
|
|
|
2022-03-13 00:45:32 +01:00
|
|
|
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)
|
2022-03-11 01:45:02 +01:00
|
|
|
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(),
|
2022-03-11 01:45:02 +01:00
|
|
|
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()),
|
2022-03-13 00:45:32 +01:00
|
|
|
|
2022-03-11 01:45:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()),
|
2022-03-13 00:45:32 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2022-03-13 00:45:32 +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
|
|
|
}
|
2022-03-13 18:39:12 +01:00
|
|
|
|
|
|
|
searchQuery(query) {
|
|
|
|
var payload = this.metadata.searchQuery(query)
|
|
|
|
return payload || {}
|
|
|
|
}
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
module.exports = Podcast
|