-
Notifications
You must be signed in to change notification settings - Fork 0
/
reduce.js
29 lines (27 loc) · 950 Bytes
/
reduce.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var _ = require('underscore');
function reduce(rss, sub, EventEmitter) {
/*
* Returns array or objects, each with title of subcription and url of each podcast episode
*/
var hasAudio,
title = sub.title;
//remove RSS without audio
hasAudio = _(rss).filter(function(post) {
return post.enclosures.length && _(post.enclosures).find(function(enc) {return enc.type === 'audio/mpeg';});
});
if (hasAudio.length) {
//reduce RSS to array of MP3 URLS
var collection = _(hasAudio).map(function(post) {
var enc = {
title: title,
url: _(post.enclosures).find(function(enc) { return enc.type === 'audio/mpeg';}).url
};
return enc;
});
EventEmitter.emit('rssReduced', collection, sub);
return collection;
} else {
console.log(sub.title + ' has no audio');
}
}
exports.reduce = reduce;