-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapg.js
72 lines (61 loc) · 1.94 KB
/
apg.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const cheerio = require('cheerio');
const j2x = require('jgexml/json2xml.js');
const fetch = require('node-fetch');
function buildXml(links, page) {
var feed = {};
var rss = {};
rss['@version'] = '2.0';
rss["@xmlns:atom"] = 'http://www.w3.org/2005/Atom';
rss.channel = {};
rss.channel.title = 'AudioPlayGround RSS feed - '+page;
rss.channel.link = 'http://bbc-rss.herokuapp.com/rss/apg/'+page+'.rss';
rss.channel["atom:link"] = {};
rss.channel["atom:link"]["@rel"] = 'self';
rss.channel["atom:link"]["@href"] = rss.channel.link;
rss.channel["atom:link"]["@type"] = 'application/rss+xml';
rss.channel.description = 'Unofficial AudioPlayGround RSS feeds';
rss.channel.webMaster = '[email protected] (Mike Ralphson)';
rss.channel.pubDate = new Date().toUTCString();
rss.channel.generator = 'apg by Mermade Software http://github.com/mermade/bbc-rss';
rss.channel.item = [];
for (let link of links) {
var d = new Date();
var title = link.title + ' by ' + link.author;
var i = {};
i.title = title;
i.link = link.url;
i.description = title;
i.category = 'audio_video';
i.guid = {};
i.guid["@isPermaLink"] = 'true';
i.guid[""] = link.url;
i.pubDate = d.toUTCString();
i.enclosure = {};
i.enclosure["@url"] = link.url;
i.enclosure["@length"] = 150260;
i.enclosure["@type"] = 'audio/mpeg';
rss.channel.item.push(i);
}
feed.rss = rss;
let xml = j2x.getXml(feed,'@','',2);
return xml;
}
function main(page,cb) {
const links = [];
fetch('https://www.audioplayground.xyz/'+page)
.then(function(res){
return res.text();
})
.then(function(body){
const $ = cheerio.load(body);
$('.sqs-audio-embed').each(function(){
const link = { url: $(this).attr('data-url'), title: $(this).attr('data-title'), author: $(this).attr('data-author') };
links.push(link);
});
cb(buildXml(links,page));
});
}
module.exports = {
main: main
};