-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprocess.js
56 lines (53 loc) · 1.36 KB
/
process.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
var fs = require('fs');
var util = require('util');
var s = fs.readFileSync('pub/index.html','utf8').split('\r').join('').split('\n');
var redirects = [];
var o = [];
for (var l of s) {
if ((l.indexOf('/rss/radio/')>0) || (l.indexOf('/rss/tv/')>0)) {
var c = l.split('"');
var n = c[c.length-2];
if ((n.indexOf('genre')>0) || (n.indexOf('format')>0)) {
var g = n.split('/').pop().replace('.rss','');
console.log(n+' '+g);
/*
/rss/both/upcoming/format/PT015.rss PT015
/rss/tv/formats/talentshows.rss
*/
var r = [];
for (var i of c) {
if (i.indexOf('/rss/radio/')>=0) {
console.log(' '+i);
var redirect = {};
redirect.from = i;
if (n.indexOf('genre')>0) {
i = '/rss/radio/available/genre/'+g+'.rss';
}
else {
i = '/rss/radio/available/format/'+g+'.rss';
}
redirect.to = i;
redirects.push(redirect);
}
if (i.indexOf('/rss/tv/')>=0) {
console.log(' '+i);
var redirect = {};
redirect.from = i;
if (n.indexOf('genre')>0) {
i = '/rss/tv/available/genre/'+g+'.rss';
}
else {
i = '/rss/tv/available/format/'+g+'.rss';
}
redirect.to = i;
redirects.push(redirect);
}
r.push(i);
}
l = r.join('"');
}
}
o.push(l);
}
fs.writeFileSync('pub/index.new',o.join('\n'),'utf8');
fs.writeFileSync('redirect.json',JSON.stringify(redirects,null,2),'utf8');