Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@bochilteam/scraper/lib/esm/others/jadwal-tv.js
1126 views
1
import got from 'got';
2
import cheerio from 'cheerio';
3
import { ScraperError } from '../utils.js';
4
export const listJadwalTV = (async () => await got('https://raw.githubusercontent.com/BochilTeam/scraper/master/data/jadwal-tv.json').json())();
5
export default async function jadwalTV(channel) {
6
const list = await listJadwalTV;
7
const data = list.find(({ channel: name }) => (new RegExp(channel, 'ig')).test(name));
8
if (!data)
9
throw new ScraperError(`List not found!!\n${JSON.stringify(listJadwalTV, null, 2)}`);
10
const text = await got(`https://www.jadwaltv.net/${data.isPay ? 'jadwal-pay-tv/' : ''}${data.value}`).text();
11
const result = [];
12
const $ = cheerio.load(text);
13
$('div > table.table').each(function () {
14
$(this).find('tbody > tr')
15
.slice(1).each(function () {
16
const el = $(this).find('td');
17
const date = el.eq(0).text();
18
const event = el.eq(1).text();
19
if (!/Jadwal TV selengkapnya di/ig.test(event)) {
20
result.push({
21
date, event
22
});
23
}
24
});
25
});
26
return {
27
channel: data.channel,
28
result
29
};
30
}
31
export async function jadwalTVNow() {
32
const text = await got('https://www.jadwaltv.net/channel/acara-tv-nasional-saat-ini').text();
33
const result = {};
34
const $ = cheerio.load(text);
35
$('div > table.table').each(function () {
36
let prevChannel;
37
$(this).find('tbody > tr')
38
.slice(1).each(function () {
39
const el = $(this).find('td');
40
const channel = el.eq(0).find('strong > a[href]')
41
.text().trim().toLowerCase();
42
if (channel) {
43
prevChannel = channel;
44
result[channel] = [];
45
}
46
else if (prevChannel) {
47
const date = el.eq(0).text();
48
const event = el.eq(1).text();
49
result[prevChannel].push({
50
date,
51
event
52
});
53
}
54
});
55
});
56
return result;
57
}
58
//# sourceMappingURL=jadwal-tv.js.map
59