rss-parser
Advanced tools
Comparing version 2.3.0 to 2.4.0
69
index.js
@@ -10,3 +10,18 @@ var Entities = require("entities"); | ||
var TOP_FIELDS = ['title', 'description', 'author', 'link']; | ||
var TOP_FIELDS = [ | ||
'title', | ||
'description', | ||
'author', | ||
'pubDate', | ||
'webMaster', | ||
'managingEditor', | ||
'generator', | ||
'link' | ||
]; | ||
var PODCAST_TOP_FIELDS = [ | ||
'author', | ||
'subtitle', | ||
'summary', | ||
'explicit' | ||
]; | ||
var ITEM_FIELDS = [ | ||
@@ -18,4 +33,13 @@ 'title', | ||
'content:encoded', | ||
] | ||
'enclosure' | ||
]; | ||
var PODCAST_ITEM_FIELDS = [ | ||
'author', | ||
'subtitle', | ||
'summary', | ||
'explicit', | ||
'duration' | ||
]; | ||
var stripHtml = function(str) { | ||
@@ -82,3 +106,3 @@ return str.replace(/<(?:.|\n)*?>/gm, ''); | ||
var channel = xmlObj.rss.channel[0]; | ||
if (channel['atom:link']) json.feed.feedUrl = channel['atom:link'][0].href; | ||
if (channel['atom:link']) json.feed.feedUrl = channel['atom:link'][0].$.href; | ||
TOP_FIELDS.forEach(function(f) { | ||
@@ -93,2 +117,5 @@ if (channel[f]) json.feed[f] = channel[f][0]; | ||
}) | ||
if (item.enclosure) { | ||
entry.enclosure = item.enclosure[0].$; | ||
} | ||
if (item.description) { | ||
@@ -105,5 +132,41 @@ entry.content = getContent(item.description[0]); | ||
}) | ||
if (xmlObj.rss.$['xmlns:itunes']) { | ||
decorateItunes(json, channel); | ||
} | ||
callback(null, json); | ||
} | ||
/** | ||
* Add iTunes specific fields from XML to extracted JSON | ||
* | ||
* @access public | ||
* @param {object} json extracted | ||
* @param {object} channel parsed XML | ||
*/ | ||
var decorateItunes = function decorateItunes(json, channel) { | ||
var items = channel.item || [], | ||
entry = {}; | ||
if (channel['itunes:owner']) { | ||
json.feed.itunes = { | ||
owner: { | ||
name: channel['itunes:owner'][0]['itunes:name'][0], | ||
email: channel['itunes:owner'][0]['itunes:email'][0] | ||
}, | ||
image: channel['itunes:image'][0].$.href | ||
}; | ||
} | ||
PODCAST_TOP_FIELDS.forEach(function(f) { | ||
if (channel['itunes:' + f]) json.feed.itunes[f] = channel['itunes:' + f][0]; | ||
}); | ||
(items).forEach(function(item, index) { | ||
entry = json.feed.entries[index]; | ||
PODCAST_ITEM_FIELDS.forEach(function(f) { | ||
entry.itunes = entry.itunes || {}; | ||
if (item['itunes:' + f]) entry.itunes[f] = item['itunes:' + f][0]; | ||
}); | ||
json.feed.entries[index] = entry; | ||
}); | ||
} | ||
Parser.parseString = function(xml, callback) { | ||
@@ -110,0 +173,0 @@ XML2JS.parseString(xml, function(err, result) { |
{ | ||
"name": "rss-parser", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -16,4 +16,5 @@ { | ||
"description": "1, 2, 1, 2… check the mic!", | ||
"pubDate": "Fri, 13 May 2016 15:14:05 GMT", | ||
"link": "https://localhost:8000" | ||
} | ||
} |
@@ -280,2 +280,3 @@ { | ||
], | ||
"feedUrl": "https://www.reddit.com/.rss", | ||
"title": "reddit: the front page of the internet", | ||
@@ -282,0 +283,0 @@ "description": "", |
@@ -280,2 +280,3 @@ { | ||
], | ||
"feedUrl": "https://www.reddit.com/.rss", | ||
"title": "reddit: the front page of the internet", | ||
@@ -282,0 +283,0 @@ "description": "", |
@@ -67,2 +67,5 @@ var FS = require('fs'); | ||
}); | ||
it('should parse podcasts', function(done) { | ||
testParseForFile('narro', 'rss', done); | ||
}); | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1065676
27
15368
6