mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 17:10:07 -04:00
66 lines
1.6 KiB
JavaScript
66 lines
1.6 KiB
JavaScript
const stream = require('stream')
|
|
const csv = require('csv-parser')
|
|
const dayjs = require('dayjs')
|
|
const utc = require('dayjs/plugin/utc')
|
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
|
|
|
dayjs.extend(utc)
|
|
dayjs.extend(customParseFormat)
|
|
|
|
module.exports = {
|
|
site: 'rotana.net',
|
|
days: 2,
|
|
url({ channel }) {
|
|
return `https://rotana.net/triAssets/uploads/2020/11/${channel.site_id}.csv`
|
|
},
|
|
request: {
|
|
method: 'POST'
|
|
},
|
|
parser: async function ({ buffer, date }) {
|
|
let programs = []
|
|
const items = await parseItems(buffer, date)
|
|
items.forEach(item => {
|
|
const start = parseStart(item)
|
|
const stop = parseStop(item)
|
|
programs.push({
|
|
title: item['Arabic Event Name'],
|
|
category: item['Genre'],
|
|
description: item['Arabic Extended Description'],
|
|
start: start.toJSON(),
|
|
stop: stop.toJSON()
|
|
})
|
|
})
|
|
|
|
return programs
|
|
}
|
|
}
|
|
|
|
function parseStart(item) {
|
|
const time = `${item['Start Date']} ${item['Start Time']}`
|
|
|
|
return dayjs.utc(time, 'DD/MM/YYYY HH:mm:ss:00')
|
|
}
|
|
|
|
function parseStop(item) {
|
|
const time = `${item['End Date']} ${item['End Time']}`
|
|
|
|
return dayjs.utc(time, 'DD/MM/YYYY HH:mm:ss:00')
|
|
}
|
|
|
|
function parseItems(buffer, date) {
|
|
return new Promise(resolve => {
|
|
let items = []
|
|
const input = new stream.PassThrough()
|
|
input.end(buffer)
|
|
input
|
|
.pipe(csv())
|
|
.on('data', data => items.push(data))
|
|
.on('end', () => {
|
|
items = items.filter(i => i['Start Date'] === date.format('DD/MM/YYYY'))
|
|
resolve(items)
|
|
})
|
|
.on('error', () => {
|
|
resolve([])
|
|
})
|
|
})
|
|
}
|