mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-31 15:19:42 +02:00
Update podcast search page to support manually entering podcast RSS feed
This commit is contained in:
parent
2c6e1cc2b5
commit
4edba20e9e
6 changed files with 87 additions and 37 deletions
|
@ -1,5 +1,6 @@
|
|||
const Logger = require('../Logger')
|
||||
const { xmlToJSON } = require('./index')
|
||||
const { stripHtml } = require('string-strip-html')
|
||||
|
||||
function extractFirstArrayItem(json, key) {
|
||||
if (!json[key] || !json[key].length) return null
|
||||
|
@ -39,11 +40,26 @@ function extractCategories(channel) {
|
|||
}
|
||||
|
||||
function extractPodcastMetadata(channel) {
|
||||
var arrayFields = ['title', 'language', 'description', 'itunes:explicit', 'itunes:author']
|
||||
var metadata = {
|
||||
image: extractImage(channel),
|
||||
categories: extractCategories(channel)
|
||||
categories: extractCategories(channel),
|
||||
feedUrl: null,
|
||||
description: null,
|
||||
descriptionPlain: null
|
||||
}
|
||||
|
||||
if (channel['itunes:new-feed-url']) {
|
||||
metadata.feedUrl = extractFirstArrayItem(channel, 'itunes:new-feed-url')
|
||||
} else if (channel['atom:link'] && channel['atom:link'].length && channel['atom:link'][0]['$']) {
|
||||
metadata.feedUrl = channel['atom:link'][0]['$'].href || null
|
||||
}
|
||||
|
||||
if (channel['description']) {
|
||||
metadata.description = extractFirstArrayItem(channel, 'description')
|
||||
metadata.descriptionPlain = stripHtml(metadata.description || '').result
|
||||
}
|
||||
|
||||
var arrayFields = ['title', 'language', 'itunes:explicit', 'itunes:author', 'pubDate', 'link']
|
||||
arrayFields.forEach((key) => {
|
||||
var cleanKey = key.split(':').pop()
|
||||
metadata[cleanKey] = extractFirstArrayItem(channel, key)
|
||||
|
@ -114,12 +130,25 @@ function cleanPodcastJson(rssJson) {
|
|||
return podcast
|
||||
}
|
||||
|
||||
module.exports.parsePodcastRssFeedXml = async (xml) => {
|
||||
module.exports.parsePodcastRssFeedXml = async (xml, includeRaw = false) => {
|
||||
if (!xml) return null
|
||||
var json = await xmlToJSON(xml)
|
||||
if (!json || !json.rss) {
|
||||
Logger.error('[podcastUtils] Invalid XML or RSS feed')
|
||||
return null
|
||||
}
|
||||
return cleanPodcastJson(json.rss)
|
||||
|
||||
const podcast = cleanPodcastJson(json.rss)
|
||||
if (!podcast) return null
|
||||
|
||||
if (includeRaw) {
|
||||
return {
|
||||
podcast,
|
||||
rawJson: json
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
podcast
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue