rss.js 594 B

123456789101112131415161718192021
  1. const XML = require('./xml')
  2. const request = require('request-promise-native')
  3. const getRss = async url => {
  4. // http://www.hellointernet.fm/podcast?format=rss
  5. url = new URL(url)
  6. if (url.protocol !== 'http:' && url.protocol !== 'https:') throw new Error('Unsupported protocol: ' + url.protocol)
  7. const xml = await request(url, {
  8. headers: {
  9. 'Accept': 'application/xml;application/rss+xml',
  10. 'User-Agent': 'rssunlimited.com'
  11. }
  12. })
  13. const data = XML.parse(xml)
  14. if (!data.rss) throw new Error('Response not an RSS feed.')
  15. return data
  16. }
  17. module.exports = {
  18. getRss
  19. }