mirror of
https://github.com/iptv-org/epg
synced 2026-05-09 19:07:03 -04:00
Update rotana.net TV guide api.
This site is using cloudflare so user agent must be set as normal browser. Signed-off-by: Toha <tohenk@yahoo.com>
This commit is contained in:
@@ -1,66 +1,106 @@
|
||||
const stream = require('stream')
|
||||
const csv = require('csv-parser')
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
const headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 OPR/104.0.0.0'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
site: 'rotana.net',
|
||||
days: 2,
|
||||
url({ channel }) {
|
||||
return `https://rotana.net/triAssets/uploads/2020/11/${channel.site_id}.csv`
|
||||
return `https://rotana.net/${channel.lang}/streams?channel=${channel.site_id}`
|
||||
},
|
||||
request: {
|
||||
method: 'POST'
|
||||
headers,
|
||||
timeout: 15000
|
||||
},
|
||||
parser: async function ({ buffer, date }) {
|
||||
let programs = []
|
||||
const items = await parseItems(buffer, date)
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
|
||||
const items = parseItems(content, 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()
|
||||
})
|
||||
const info = item.find('.iq-accordion-block > .iq-accordion-title .big-title span')
|
||||
if (info.length) {
|
||||
const details = item.find('.trending-info div > span')
|
||||
const [ time, title ] = info.text().split('\n')
|
||||
const [ _, duration, description ] = details.text().split('\n')
|
||||
if (duration) {
|
||||
const start = dayjs.tz(`${date.format('YYYY-MM-DD')} ${time.trim()}`, 'YYYY-MM-DD HH:mm', 'Asia/Riyadh')
|
||||
const stop = addDuration(start, duration.trim())
|
||||
|
||||
programs.push({
|
||||
title: title.trim(),
|
||||
description: description.trim(),
|
||||
start: start.toISOString(),
|
||||
stop: stop.toISOString()
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ lang = 'en'}) {
|
||||
const axios = require('axios')
|
||||
const options = {headers}
|
||||
const result = await axios
|
||||
.get(`https://rotana.net/${lang}/streams`, options)
|
||||
.then(response => response.data)
|
||||
.catch(console.error)
|
||||
|
||||
const $ = cheerio.load(result)
|
||||
const items = $('#channels-list a').toArray()
|
||||
const channels = items.map(item => {
|
||||
const $item = $(item)
|
||||
const data = $item.attr('href').match(/channel=([A-Za-z0-9]+)/)
|
||||
|
||||
return {
|
||||
lang,
|
||||
site_id: data[1],
|
||||
name: $item.text().trim()
|
||||
}
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function addDuration(date, duration) {
|
||||
const matches = duration.matchAll(/(\d+)(h|m|s|ms)/g)
|
||||
while (true) {
|
||||
const m = matches.next()
|
||||
if (!m.value) {
|
||||
break
|
||||
}
|
||||
if (m.value[1] && m.value[2]) {
|
||||
date = date.add(parseInt(m.value[1]), m.value[2])
|
||||
}
|
||||
}
|
||||
return date
|
||||
}
|
||||
|
||||
function parseStart(item) {
|
||||
const time = `${item['Start Date']} ${item['Start Time']}`
|
||||
function parseItems(content, date) {
|
||||
const result = []
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
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([])
|
||||
})
|
||||
const expectedId = `item-${date.format('DD-MM-YYYY')}`
|
||||
let lastId
|
||||
$('.hour > div').toArray().forEach(item => {
|
||||
const $item = $(item)
|
||||
if ($item.hasClass('bg')) {
|
||||
lastId = $item.attr('id')
|
||||
} else if ($item.hasClass('iq-accordion') && lastId === expectedId) {
|
||||
result.push($item)
|
||||
}
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user