Skip to content

Instantly share code, notes, and snippets.

@thebells1111
Created July 21, 2021 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebells1111/707e04a54457b3671f7d6e810cc88001 to your computer and use it in GitHub Desktop.
Save thebells1111/707e04a54457b3671f7d6e810cc88001 to your computer and use it in GitHub Desktop.
fast-parse-xml html entities
var parser = require('fast-xml-parser');
var he = require('he');
const fetch = require('node-fetch');
const getEpisodesFromURL = (exports.getEpisodesFromURL = async function (
feedUrl
) {
try {
const res = await fetch(feedUrl);
const feed = await res.text();
if (!feed.includes('<rss')) reject(new Error('Not XML'));
var parserOptions = {
ignoreAttributes: false,
attributeNamePrefix: '',
trimValues: true,
allowBooleanAttributes: true,
attrValueProcessor: (val, attrName) =>
he.decode(val, { isAttributeValue: true }), //default is a=>a
tagValueProcessor: (val, tagName) => he.decode(val), //default is a=>a
};
let rss = parser.parse(feed, parserOptions).rss;
return rss.channel;
} catch (err) {
throw err;
}
});
getEpisodesFromURL(
'https://api.spokenlayer.com/feed/channel/cnet-tnn-podcasts-ext/3c9929b72538c12bd92ac6762f8d798b9d4e8cdca7692ea74f466061d01816cb'
).then((channel) => console.log(channel.item[0].enclosure.url));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment