Delete config for rtb.gov.bn
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "[object Object]". Closes: https://github.com/iptv-org/epg/issues/2257
This commit is contained in:
1 parent
2eefe82abd
commit
97bc375c1a
6 files changed
-189
No files matched your search
Binary file not shown.
Binary file not shown.
@@ -1,15 +0,0 @@
|
|||||||
# rtb.gov.bn
|
|
||||||
|
|
||||||
https://www.rtb.gov.bn/SitePages/Programme%20Guide.aspx
|
|
||||||
|
|
||||||
### Download the guide
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm run grab --- --site=rtb.gov.bn
|
|
||||||
```
|
|
||||||
|
|
||||||
### Test
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm test --- rtb.gov.bn
|
|
||||||
```
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<channels>
|
|
||||||
<channel site="rtb.gov.bn" lang="ms" xmltv_id="RTBAneka.bn" site_id="Aneka">RTB Aneka</channel>
|
|
||||||
<channel site="rtb.gov.bn" lang="ms" xmltv_id="RTBPerdana.bn" site_id="Perdana">RTB Perdana</channel>
|
|
||||||
<channel site="rtb.gov.bn" lang="ms" xmltv_id="RTBSukmaindera.bn" site_id="Sukmaindera">RTB Sukmaindera</channel>
|
|
||||||
</channels>
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
const pdf = require('pdf-parse')
|
|
||||||
const dayjs = require('dayjs')
|
|
||||||
const utc = require('dayjs/plugin/utc')
|
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
|
||||||
|
|
||||||
dayjs.extend(utc)
|
|
||||||
dayjs.extend(timezone)
|
|
||||||
dayjs.extend(customParseFormat)
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
site: 'rtb.gov.bn',
|
|
||||||
days: 2,
|
|
||||||
url: function ({ channel, date }) {
|
|
||||||
return encodeURI(
|
|
||||||
`http://www.rtb.gov.bn/PublishingImages/SitePages/Programme Guide/${
|
|
||||||
channel.site_id
|
|
||||||
} ${date.format('DD MMMM YYYY')}.pdf`
|
|
||||||
)
|
|
||||||
},
|
|
||||||
parser: async function ({ buffer, date }) {
|
|
||||||
let programs = []
|
|
||||||
const items = await parseItems(buffer)
|
|
||||||
items.forEach(item => {
|
|
||||||
const prev = programs[programs.length - 1]
|
|
||||||
let start = parseStart(item, date)
|
|
||||||
if (prev) {
|
|
||||||
if (start.isBefore(prev.start)) {
|
|
||||||
start = start.add(1, 'd')
|
|
||||||
date = date.add(1, 'd')
|
|
||||||
}
|
|
||||||
prev.stop = start
|
|
||||||
}
|
|
||||||
const stop = start.add(1, 'h')
|
|
||||||
programs.push({
|
|
||||||
title: item.title,
|
|
||||||
start,
|
|
||||||
stop
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
return programs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStart(item, date) {
|
|
||||||
const dateString = `${date.format('YYYY-MM-DD')} ${item.time}`
|
|
||||||
|
|
||||||
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Asia/Brunei')
|
|
||||||
}
|
|
||||||
|
|
||||||
async function parseItems(buffer) {
|
|
||||||
let data
|
|
||||||
try {
|
|
||||||
data = await pdf(buffer)
|
|
||||||
} catch {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!data) return []
|
|
||||||
|
|
||||||
return data.text
|
|
||||||
.split('\n')
|
|
||||||
.filter(s => {
|
|
||||||
const string = s.trim()
|
|
||||||
|
|
||||||
return string && /^\d{2}:\d{2}/.test(string)
|
|
||||||
})
|
|
||||||
.map(s => {
|
|
||||||
const [, time, title] = s.trim().match(/^(\d{2}:\d{2}) (.*)/) || [null, null, null]
|
|
||||||
|
|
||||||
return { time, title }
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
const { parser, url } = require('./rtb.gov.bn.config.js')
|
|
||||||
const path = require('path')
|
|
||||||
const fs = require('fs')
|
|
||||||
const dayjs = require('dayjs')
|
|
||||||
const utc = require('dayjs/plugin/utc')
|
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
|
||||||
dayjs.extend(customParseFormat)
|
|
||||||
dayjs.extend(utc)
|
|
||||||
|
|
||||||
const date = dayjs.utc('2021-11-11', 'YYYY-MM-DD').startOf('d')
|
|
||||||
const channel = {
|
|
||||||
site_id: 'Sukmaindera',
|
|
||||||
xmltv_id: 'RTBSukmaindera.bn'
|
|
||||||
}
|
|
||||||
|
|
||||||
it('can generate valid url', () => {
|
|
||||||
expect(url({ channel, date })).toBe(
|
|
||||||
'http://www.rtb.gov.bn/PublishingImages/SitePages/Programme%20Guide/Sukmaindera%2011%20November%202021.pdf'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can parse Sukmaindera 11 November 2021.pdf', done => {
|
|
||||||
const buffer = fs.readFileSync(
|
|
||||||
path.resolve(__dirname, '__data__/Sukmaindera 11 November 2021.pdf'),
|
|
||||||
{
|
|
||||||
charset: 'utf8'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
parser({ buffer, date })
|
|
||||||
.then(results => {
|
|
||||||
results = results.map(p => {
|
|
||||||
p.start = p.start.toJSON()
|
|
||||||
p.stop = p.stop.toJSON()
|
|
||||||
return p
|
|
||||||
})
|
|
||||||
expect(results.length).toBe(47)
|
|
||||||
expect(results[0]).toMatchObject({
|
|
||||||
start: '2021-11-10T22:00:00.000Z',
|
|
||||||
stop: '2021-11-10T22:05:00.000Z',
|
|
||||||
title: 'NATIONAL ANTHEM'
|
|
||||||
})
|
|
||||||
expect(results[46]).toMatchObject({
|
|
||||||
start: '2021-11-11T21:30:00.000Z',
|
|
||||||
stop: '2021-11-11T22:30:00.000Z',
|
|
||||||
title: 'BACAAN SURAH YASSIN'
|
|
||||||
})
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
done(error)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can parse Aneka 11 November 2021.pdf', done => {
|
|
||||||
const buffer = fs.readFileSync(path.resolve(__dirname, '__data__/Aneka 11 November 2021.pdf'), {
|
|
||||||
charset: 'utf8'
|
|
||||||
})
|
|
||||||
parser({ buffer, date })
|
|
||||||
.then(results => {
|
|
||||||
results = results.map(p => {
|
|
||||||
p.start = p.start.toJSON()
|
|
||||||
p.stop = p.stop.toJSON()
|
|
||||||
return p
|
|
||||||
})
|
|
||||||
expect(results.length).toBe(26)
|
|
||||||
expect(results[4]).toMatchObject({
|
|
||||||
start: '2021-11-11T03:00:00.000Z',
|
|
||||||
stop: '2021-11-11T04:05:00.000Z',
|
|
||||||
title: 'DRAMA TURKI:'
|
|
||||||
})
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
done(error)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can handle empty guide', done => {
|
|
||||||
parser({
|
|
||||||
date,
|
|
||||||
channel,
|
|
||||||
content: `<html><head><title>Object moved</title></head><body>
|
|
||||||
<h2>Object moved to <a href="/en/_layouts/OGP/ErrorPage.aspx">here</a>.</h2>
|
|
||||||
</body></html>
|
|
||||||
`
|
|
||||||
})
|
|
||||||
.then(result => {
|
|
||||||
expect(result).toMatchObject([])
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
done(error)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
Reference in new issue
Block a user