mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-23 04:09:38 +00:00
Podcast episode downloader, update podcast data model
This commit is contained in:
parent
28d76d21f1
commit
920ca683b9
19 changed files with 407 additions and 49 deletions
|
|
@ -166,8 +166,10 @@ class LibraryItem {
|
|||
} else {
|
||||
this.mediaType = 'book'
|
||||
this.media = new Book()
|
||||
|
||||
}
|
||||
|
||||
|
||||
for (const key in payload) {
|
||||
if (key === 'libraryFiles') {
|
||||
this.libraryFiles = payload.libraryFiles.map(lf => lf.clone())
|
||||
|
|
@ -175,13 +177,13 @@ class LibraryItem {
|
|||
// Use first image library file as cover
|
||||
var firstImageFile = this.libraryFiles.find(lf => lf.fileType === 'image')
|
||||
if (firstImageFile) this.media.coverPath = firstImageFile.metadata.path
|
||||
} else if (this[key] !== undefined) {
|
||||
} else if (this[key] !== undefined && key !== 'media') {
|
||||
this[key] = payload[key]
|
||||
}
|
||||
}
|
||||
|
||||
if (payload.mediaMetadata) {
|
||||
this.media.setData(payload.mediaMetadata)
|
||||
if (payload.media) {
|
||||
this.media.setData(payload.media)
|
||||
}
|
||||
|
||||
this.addedAt = Date.now()
|
||||
|
|
|
|||
38
server/objects/PodcastEpisodeDownload.js
Normal file
38
server/objects/PodcastEpisodeDownload.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const Path = require('path')
|
||||
const { getId } = require('../utils/index')
|
||||
const { sanitizeFilename } = require('../utils/fileUtils')
|
||||
|
||||
class PodcastEpisodeDownload {
|
||||
constructor() {
|
||||
this.id = null
|
||||
this.podcastEpisode = null
|
||||
this.url = null
|
||||
this.libraryItem = null
|
||||
|
||||
this.isDownloading = false
|
||||
this.startedAt = null
|
||||
this.createdAt = null
|
||||
this.finishedAt = null
|
||||
}
|
||||
|
||||
get targetFilename() {
|
||||
return sanitizeFilename(`${this.podcastEpisode.bestFilename}.mp3`)
|
||||
}
|
||||
|
||||
get targetPath() {
|
||||
return Path.join(this.libraryItem.path, this.targetFilename)
|
||||
}
|
||||
|
||||
get targetRelPath() {
|
||||
return Path.join(this.libraryItem.relPath, this.targetFilename)
|
||||
}
|
||||
|
||||
setData(podcastEpisode, libraryItem) {
|
||||
this.id = getId('epdl')
|
||||
this.podcastEpisode = podcastEpisode
|
||||
this.url = podcastEpisode.enclosure.url
|
||||
this.libraryItem = libraryItem
|
||||
this.createdAt = Date.now()
|
||||
}
|
||||
}
|
||||
module.exports = PodcastEpisodeDownload
|
||||
|
|
@ -7,13 +7,16 @@ class PodcastEpisode {
|
|||
this.id = null
|
||||
this.index = null
|
||||
|
||||
this.episodeNumber = null
|
||||
this.episode = null
|
||||
this.episodeType = null
|
||||
this.title = null
|
||||
this.subtitle = null
|
||||
this.description = null
|
||||
this.enclosure = null
|
||||
this.pubDate = null
|
||||
|
||||
this.audioFile = null
|
||||
this.publishedAt = null
|
||||
this.addedAt = null
|
||||
this.updatedAt = null
|
||||
|
||||
|
|
@ -25,12 +28,15 @@ class PodcastEpisode {
|
|||
construct(episode) {
|
||||
this.id = episode.id
|
||||
this.index = episode.index
|
||||
this.episodeNumber = episode.episodeNumber
|
||||
this.episode = episode.episode
|
||||
this.episodeType = episode.episodeType
|
||||
this.title = episode.title
|
||||
this.subtitle = episode.subtitle
|
||||
this.description = episode.description
|
||||
this.enclosure = episode.enclosure ? { ...episode.enclosure } : null
|
||||
this.pubDate = episode.pubDate
|
||||
this.audioFile = new AudioFile(episode.audioFile)
|
||||
this.publishedAt = episode.publishedAt
|
||||
this.addedAt = episode.addedAt
|
||||
this.updatedAt = episode.updatedAt
|
||||
}
|
||||
|
|
@ -39,12 +45,15 @@ class PodcastEpisode {
|
|||
return {
|
||||
id: this.id,
|
||||
index: this.index,
|
||||
episodeNumber: this.episodeNumber,
|
||||
episode: this.episode,
|
||||
episodeType: this.episodeType,
|
||||
title: this.title,
|
||||
subtitle: this.subtitle,
|
||||
description: this.description,
|
||||
enclosure: this.enclosure ? { ...this.enclosure } : null,
|
||||
pubDate: this.pubDate,
|
||||
audioFile: this.audioFile.toJSON(),
|
||||
publishedAt: this.publishedAt,
|
||||
addedAt: this.addedAt,
|
||||
updatedAt: this.updatedAt
|
||||
}
|
||||
|
|
@ -58,15 +67,22 @@ class PodcastEpisode {
|
|||
return this.audioFile.duration
|
||||
}
|
||||
get size() { return this.audioFile.metadata.size }
|
||||
get bestFilename() {
|
||||
if (this.episode) return `${this.episode} - ${this.title}`
|
||||
return this.title
|
||||
}
|
||||
|
||||
setData(data, index = 1) {
|
||||
this.id = getId('ep')
|
||||
this.index = index
|
||||
this.title = data.title
|
||||
this.subtitle = data.subtitle || ''
|
||||
this.pubDate = data.pubDate || ''
|
||||
this.description = data.description || ''
|
||||
this.enclosure = data.enclosure ? { ...data.enclosure } : null
|
||||
this.episodeNumber = data.episodeNumber || ''
|
||||
this.episode = data.episode || ''
|
||||
this.episodeType = data.episodeType || ''
|
||||
this.publishedAt = data.publishedAt || 0
|
||||
this.addedAt = Date.now()
|
||||
this.updatedAt = Date.now()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,9 +176,11 @@ class Book {
|
|||
return this.metadata.setDataFromAudioMetaTags(audioFile.metaTags, overrideExistingDetails)
|
||||
}
|
||||
|
||||
setData(scanMediaMetadata) {
|
||||
setData(mediaPayload) {
|
||||
this.metadata = new BookMetadata()
|
||||
this.metadata.setData(scanMediaMetadata)
|
||||
if (mediaPayload.metadata) {
|
||||
this.metadata.setData(mediaPayload.metadata)
|
||||
}
|
||||
}
|
||||
|
||||
// Look for desc.txt, reader.txt, metadata.abs and opf file then update details if found
|
||||
|
|
|
|||
|
|
@ -118,10 +118,14 @@ class Podcast {
|
|||
return this.episodes[0]
|
||||
}
|
||||
|
||||
setData(metadata, coverPath = null, autoDownload = false) {
|
||||
this.metadata = new PodcastMetadata(metadata)
|
||||
this.coverPath = coverPath
|
||||
this.autoDownloadEpisodes = autoDownload
|
||||
setData(mediaMetadata) {
|
||||
this.metadata = new PodcastMetadata()
|
||||
if (mediaMetadata.metadata) {
|
||||
this.metadata.setData(mediaMetadata.metadata)
|
||||
}
|
||||
|
||||
this.coverPath = mediaMetadata.coverPath || null
|
||||
this.autoDownloadEpisodes = !!mediaMetadata.autoDownloadEpisodes
|
||||
}
|
||||
|
||||
async syncMetadataFiles(textMetadataFiles, opfMetadataOverrideDetails) {
|
||||
|
|
@ -150,5 +154,9 @@ class Podcast {
|
|||
this.episodes.forEach((ep) => total += ep.duration)
|
||||
return total
|
||||
}
|
||||
|
||||
addPodcastEpisode(podcastEpisode) {
|
||||
this.episodes.push(podcastEpisode)
|
||||
}
|
||||
}
|
||||
module.exports = Podcast
|
||||
|
|
@ -70,5 +70,22 @@ class PodcastMetadata {
|
|||
}
|
||||
return null
|
||||
}
|
||||
|
||||
setData(mediaMetadata = {}) {
|
||||
this.title = mediaMetadata.title || null
|
||||
this.author = mediaMetadata.author || null
|
||||
this.description = mediaMetadata.description || null
|
||||
this.releaseDate = mediaMetadata.releaseDate || null
|
||||
this.feedUrl = mediaMetadata.feedUrl || null
|
||||
this.imageUrl = mediaMetadata.imageUrl || null
|
||||
this.itunesPageUrl = mediaMetadata.itunesPageUrl || null
|
||||
this.itunesId = mediaMetadata.itunesId || null
|
||||
this.itunesArtistId = mediaMetadata.itunesArtistId || null
|
||||
this.explicit = !!mediaMetadata.explicit
|
||||
this.language = mediaMetadata.language || null
|
||||
if (mediaMetadata.genres && mediaMetadata.genres.length) {
|
||||
this.genres = [...mediaMetadata.genres]
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = PodcastMetadata
|
||||
Loading…
Add table
Add a link
Reference in a new issue