mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-30 04:25:03 +02:00
Update podcasts to new library item model
This commit is contained in:
parent
4a398f6113
commit
d8823c8b1c
14 changed files with 416 additions and 281 deletions
|
@ -6,8 +6,9 @@ const globals = require('../utils/globals')
|
|||
class PodcastEpisodeDownload {
|
||||
constructor() {
|
||||
this.id = null
|
||||
/** @type {import('../objects/entities/PodcastEpisode')} */
|
||||
this.podcastEpisode = null
|
||||
/** @type {import('../utils/podcastUtils').RssPodcastEpisode} */
|
||||
this.rssPodcastEpisode = null
|
||||
|
||||
this.url = null
|
||||
/** @type {import('../models/LibraryItem')} */
|
||||
this.libraryItem = null
|
||||
|
@ -17,7 +18,7 @@ class PodcastEpisodeDownload {
|
|||
this.isFinished = false
|
||||
this.failed = false
|
||||
|
||||
this.appendEpisodeId = false
|
||||
this.appendRandomId = false
|
||||
|
||||
this.startedAt = null
|
||||
this.createdAt = null
|
||||
|
@ -27,22 +28,22 @@ class PodcastEpisodeDownload {
|
|||
toJSONForClient() {
|
||||
return {
|
||||
id: this.id,
|
||||
episodeDisplayTitle: this.podcastEpisode?.title ?? null,
|
||||
episodeDisplayTitle: this.rssPodcastEpisode?.title ?? null,
|
||||
url: this.url,
|
||||
libraryItemId: this.libraryItemId,
|
||||
libraryId: this.libraryId || null,
|
||||
isFinished: this.isFinished,
|
||||
failed: this.failed,
|
||||
appendEpisodeId: this.appendEpisodeId,
|
||||
appendRandomId: this.appendRandomId,
|
||||
startedAt: this.startedAt,
|
||||
createdAt: this.createdAt,
|
||||
finishedAt: this.finishedAt,
|
||||
podcastTitle: this.libraryItem?.media.title ?? null,
|
||||
podcastExplicit: !!this.libraryItem?.media.explicit,
|
||||
season: this.podcastEpisode?.season ?? null,
|
||||
episode: this.podcastEpisode?.episode ?? null,
|
||||
episodeType: this.podcastEpisode?.episodeType ?? 'full',
|
||||
publishedAt: this.podcastEpisode?.publishedAt ?? null
|
||||
season: this.rssPodcastEpisode?.season ?? null,
|
||||
episode: this.rssPodcastEpisode?.episode ?? null,
|
||||
episodeType: this.rssPodcastEpisode?.episodeType ?? 'full',
|
||||
publishedAt: this.rssPodcastEpisode?.publishedAt ?? null
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +57,7 @@ class PodcastEpisodeDownload {
|
|||
return 'mp3'
|
||||
}
|
||||
get enclosureType() {
|
||||
const enclosureType = this.podcastEpisode?.enclosure?.type
|
||||
const enclosureType = this.rssPodcastEpisode.enclosure.type
|
||||
return typeof enclosureType === 'string' ? enclosureType : null
|
||||
}
|
||||
/**
|
||||
|
@ -69,10 +70,12 @@ class PodcastEpisodeDownload {
|
|||
if (this.enclosureType && !this.enclosureType.includes('mpeg')) return false
|
||||
return this.fileExtension === 'mp3'
|
||||
}
|
||||
|
||||
get episodeTitle() {
|
||||
return this.rssPodcastEpisode.title
|
||||
}
|
||||
get targetFilename() {
|
||||
const appendage = this.appendEpisodeId ? ` (${this.podcastEpisode.id})` : ''
|
||||
const filename = `${this.podcastEpisode.title}${appendage}.${this.fileExtension}`
|
||||
const appendage = this.appendRandomId ? ` (${uuidv4()})` : ''
|
||||
const filename = `${this.rssPodcastEpisode.title}${appendage}.${this.fileExtension}`
|
||||
return sanitizeFilename(filename)
|
||||
}
|
||||
get targetPath() {
|
||||
|
@ -84,19 +87,23 @@ class PodcastEpisodeDownload {
|
|||
get libraryItemId() {
|
||||
return this.libraryItem?.id || null
|
||||
}
|
||||
get pubYear() {
|
||||
if (!this.rssPodcastEpisode.publishedAt) return null
|
||||
return new Date(this.rssPodcastEpisode.publishedAt).getFullYear()
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('../objects/entities/PodcastEpisode')} podcastEpisode - old model
|
||||
* @param {import('../utils/podcastUtils').RssPodcastEpisode} rssPodcastEpisode - from rss feed
|
||||
* @param {import('../models/LibraryItem')} libraryItem
|
||||
* @param {*} isAutoDownload
|
||||
* @param {*} libraryId
|
||||
*/
|
||||
setData(podcastEpisode, libraryItem, isAutoDownload, libraryId) {
|
||||
setData(rssPodcastEpisode, libraryItem, isAutoDownload, libraryId) {
|
||||
this.id = uuidv4()
|
||||
this.podcastEpisode = podcastEpisode
|
||||
this.rssPodcastEpisode = rssPodcastEpisode
|
||||
|
||||
const url = podcastEpisode.enclosure.url
|
||||
const url = rssPodcastEpisode.enclosure.url
|
||||
if (decodeURIComponent(url) !== url) {
|
||||
// Already encoded
|
||||
this.url = url
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue