-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_playlist.js
111 lines (93 loc) · 2.96 KB
/
make_playlist.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const fs = require('fs');
const https = require('https');
const parser = require("iptv-playlist-parser");
class Make {
constructor() {
this.chanellsItem = [];
this.fileName = './public/m3u/playlist.m3u8';
this.removeChanals = ['Religious', 'Music', 'Geo-blocked']
this.EPG_LIST = [
{
country: 'AZ',
url: "https://iptv-org.github.io/iptv/countries/az.m3u"
},
{
country: 'AM',
url: "https://iptv-org.github.io/iptv/countries/am.m3u"
},
{
country: 'BY',
url: "https://iptv-org.github.io/iptv/countries/by.m3u"
},
{
country: 'KZ',
url: "https://iptv-org.github.io/iptv/countries/kz.m3u"
},
{
country: 'KG',
url: "https://iptv-org.github.io/iptv/countries/kg.m3u"
},
{
country: 'RU',
url: "https://iptv-org.github.io/iptv/countries/ru.m3u"
},
{
country: 'TJ',
url: "https://iptv-org.github.io/iptv/countries/tj.m3u"
},
{
country: 'TM',
url: "https://iptv-org.github.io/iptv/countries/tm.m3u"
},
{
country: 'UZ',
url: "https://iptv-org.github.io/iptv/countries/uz.m3u"
},
];
}
clearFile() {
fs.truncate(this.fileName, err => {
if (err) {
throw err; // не удалось очистить файл
}
});
}
setItems(item) {
this.chanellsItem.push(item);
}
getElements() {
this.EPG_LIST.forEach(list => {
https.get(list.url, (response) => {
let body = "";
response.on("data", (chunk) => {
body += chunk;
});
response.on("end", () => {
const playlist = parser.parse(body);
playlist.items.forEach((channel) => {
let remove = false
this.removeChanals.forEach(blocker => {
if (channel.raw.indexOf(blocker) >= 0) {
remove = true;
}
});
if (!remove) {
channel.tvg.country = list.country;
this.setItems(channel);
}
});
});
})
});
}
createFile() {
this.clearFile();
this.getElements();
setTimeout(() => {
console.log(this.chanellsItem)
fs.appendFileSync(this.fileName, JSON.stringify(this.chanellsItem));
}, 4000)
}
}
let creater = new Make();
creater.createFile();