Merge pull request #296 from iptv-org/update-rtb-gov-bn

Update rtb.gov.bn
This commit is contained in:
Aleksandr Statciuk 2021-11-25 01:36:25 +03:00 committed by GitHub
commit a1e6367df1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View file

@ -24,21 +24,23 @@ module.exports = {
return channel.logo return channel.logo
}, },
parser: async function ({ buffer, date }) { parser: async function ({ buffer, date }) {
let PM = false
let programs = [] let programs = []
const items = await parseItems(buffer) const items = await parseItems(buffer)
items.forEach(item => { items.forEach(item => {
const prev = programs[programs.length - 1]
let start = parseStart(item, date) let start = parseStart(item, date)
if (start.hour() > 11) PM = true if (prev) {
if (start.hour() < 12 && PM) start = start.add(1, 'd') if (start.isBefore(prev.start)) {
const stop = start.add(1, 'h') start = start.add(1, 'd')
if (programs.length) { date = date.add(1, 'd')
programs[programs.length - 1].stop = start.toJSON()
} }
prev.stop = start
}
const stop = start.add(1, 'h')
programs.push({ programs.push({
title: item.title, title: item.title,
start: start.toJSON(), start,
stop: stop.toJSON() stop
}) })
}) })
@ -47,9 +49,9 @@ module.exports = {
} }
function parseStart(item, date) { function parseStart(item, date) {
const time = `${date.format('YYYY-MM-DD')} ${item.time}` const dateString = `${date.format('YYYY-MM-DD')} ${item.time}`
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Asia/Brunei') return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Asia/Brunei')
} }
async function parseItems(buffer) { async function parseItems(buffer) {

View file

@ -37,6 +37,11 @@ it('can parse Sukmaindera 11 November 2021.pdf', done => {
) )
parser({ buffer, date }) parser({ buffer, date })
.then(results => { .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.length).toBe(47)
expect(results[0]).toMatchObject({ expect(results[0]).toMatchObject({
start: '2021-11-10T22:00:00.000Z', start: '2021-11-10T22:00:00.000Z',
@ -61,6 +66,11 @@ it('can parse Aneka 11 November 2021.pdf', done => {
}) })
parser({ buffer, date }) parser({ buffer, date })
.then(results => { .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.length).toBe(26)
expect(results[4]).toMatchObject({ expect(results[4]).toMatchObject({
start: '2021-11-11T03:00:00.000Z', start: '2021-11-11T03:00:00.000Z',