mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-24 04:39:40 +00: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
|
|
@ -94,17 +94,18 @@ class PodcastController {
|
|||
if (!url) {
|
||||
return res.status(400).send('Bad request')
|
||||
}
|
||||
var includeRaw = req.query.raw == 1 // Include raw json
|
||||
|
||||
axios.get(url).then(async (data) => {
|
||||
if (!data || !data.data) {
|
||||
Logger.error('Invalid podcast feed request response')
|
||||
return res.status(500).send('Bad response from feed request')
|
||||
}
|
||||
var podcast = await parsePodcastRssFeedXml(data.data)
|
||||
if (!podcast) {
|
||||
var payload = await parsePodcastRssFeedXml(data.data, includeRaw)
|
||||
if (!payload) {
|
||||
return res.status(500).send('Invalid podcast RSS feed')
|
||||
}
|
||||
res.json(podcast)
|
||||
res.json(payload)
|
||||
}).catch((error) => {
|
||||
console.error('Failed', error)
|
||||
res.status(500).send(error)
|
||||
|
|
|
|||
|
|
@ -190,11 +190,11 @@ class PodcastManager {
|
|||
Logger.error('Invalid podcast feed request response')
|
||||
return false
|
||||
}
|
||||
var podcast = await parsePodcastRssFeedXml(data.data)
|
||||
if (!podcast) {
|
||||
var payload = await parsePodcastRssFeedXml(data.data)
|
||||
if (!payload) {
|
||||
return false
|
||||
}
|
||||
return podcast
|
||||
return payload.podcast
|
||||
}).catch((error) => {
|
||||
console.error('Failed', error)
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -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