audiobookshelf/server/utils/parsers/parseOPML.js
advplyr 37ad1cced2 Fix:Large OPML import timeouts #3118
- Added OPML Api endpoints for /parse and /create, removed old
- Show task for OPML import and create failed tasks for failed feeds
2024-07-16 17:05:52 -05:00

29 lines
696 B
JavaScript

const h = require('htmlparser2')
const Logger = require('../../Logger')
/**
*
* @param {string} opmlText
* @returns {Array<{title: string, feedUrl: string}>
*/
function parse(opmlText) {
var feeds = []
var parser = new h.Parser({
onopentag: (name, attribs) => {
if (name === 'outline' && attribs.type === 'rss') {
if (!attribs.xmlurl) {
Logger.error('[parseOPML] Invalid opml outline tag has no xmlurl attribute')
} else {
feeds.push({
title: attribs.title || attribs.text || '',
feedUrl: attribs.xmlurl
})
}
}
}
})
parser.write(opmlText)
return feeds
}
module.exports.parse = parse