mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Merge pull request #287 from iptv-org/update-arianatelevision-com
Update arianatelevision.com
This commit is contained in:
commit
ba02e93f60
3 changed files with 100 additions and 22 deletions
|
@ -1,10 +1,8 @@
|
|||
const jsdom = require('jsdom')
|
||||
const { JSDOM } = jsdom
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const tabletojson = require('tabletojson').Tabletojson
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
@ -12,25 +10,26 @@ dayjs.extend(customParseFormat)
|
|||
|
||||
module.exports = {
|
||||
site: 'arianatelevision.com',
|
||||
url() {
|
||||
return `https://www.arianatelevision.com/program-schedule/`
|
||||
url: `https://www.arianatelevision.com/program-schedule/`,
|
||||
logo({ channel }) {
|
||||
return channel.logo
|
||||
},
|
||||
parser({ content, date }) {
|
||||
let PM = false
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
items.forEach(item => {
|
||||
const title = item.title
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart(item, date)
|
||||
if (start.hour() > 11) PM = true
|
||||
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||
const stop = start.add(30, 'm')
|
||||
if (programs.length) {
|
||||
programs[programs.length - 1].stop = start
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
|
||||
const stop = start.add(30, 'm')
|
||||
programs.push({
|
||||
title,
|
||||
title: item.title,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
|
@ -48,12 +47,25 @@ function parseStart(item, date) {
|
|||
|
||||
function parseItems(content, date) {
|
||||
const items = []
|
||||
const dom = new JSDOM(content)
|
||||
const dayOfWeek = date.format('dddd')
|
||||
const el = dom.window.document.getElementById('jtrt_table_508')
|
||||
const data = tabletojson.convert(el.outerHTML)
|
||||
if (!data) return items
|
||||
const rows = data[0]
|
||||
const col = date.day()
|
||||
const $ = cheerio.load(content)
|
||||
const settings = $('#jtrt_table_settings_508').text()
|
||||
if (!settings) return []
|
||||
const data = JSON.parse(settings)
|
||||
if (!data || !Array.isArray(data)) return []
|
||||
|
||||
return rows.map(r => ({ start: r.Start, title: r[dayOfWeek] })).filter(i => i.start)
|
||||
let rows = data[0]
|
||||
rows.shift()
|
||||
const output = []
|
||||
rows.forEach(row => {
|
||||
let day = date.day() + 2
|
||||
if (day > 7) day = 1
|
||||
if (!row[0] || !row[day]) return
|
||||
output.push({
|
||||
start: row[0].trim(),
|
||||
title: row[day].trim()
|
||||
})
|
||||
})
|
||||
|
||||
return output
|
||||
}
|
||||
|
|
66
sites/arianatelevision.com/arianatelevision.com.test.js
Normal file
66
sites/arianatelevision.com/arianatelevision.com.test.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
// npx epg-grabber --config=sites/arianatelevision.com/arianatelevision.com.config.js --channels=sites/arianatelevision.com/arianatelevision.com_af.channels.xml --output=.gh-pages/guides/af/arianatelevision.com.epg.xml --days=2
|
||||
|
||||
const { parser, url, logo } = require('./arianatelevision.com.config.js')
|
||||
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-27', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '#',
|
||||
xmltv_id: 'ArianaTVNational.af',
|
||||
logo: 'https://www.arianatelevision.com/wp-content/uploads/2017/08/logo-atn-new.png'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url).toBe('https://www.arianatelevision.com/program-schedule/')
|
||||
})
|
||||
|
||||
it('can generate valid logo url', () => {
|
||||
expect(logo({ channel })).toBe(
|
||||
'https://www.arianatelevision.com/wp-content/uploads/2017/08/logo-atn-new.png'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = `<!DOCTYPE html><html><head></head><body><textarea data-jtrt-table-id="508" id="jtrt_table_settings_508" cols="30" rows="10">[[["Start","Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","",""],["7:00AM","City Report","ICC T20 Highlights","ICC T20 Highlights","ICC T20 Highlights","ICC T20 Highlights","ICC T20 Highlights","ICC T20 Highlights","",""],["7:30AM","ICC T20 Highlights","Sport ","Sport ","Sport ","Sport ","Sport ","Sport ","",""],["3:00PM","ICC T20 World Cup","ICC T20 World Cup","ICC T20 World Cup","ICC T20 World Cup","ICC T20 World Cup","ICC T20 World Cup","ICC T20 World Cup","",""],["6:30AM","Quran and Hadis ","Falah","Falah","Falah","Falah","Falah","Falah","",""],["","\\n","","","","","","","",""]]]</textarea></body></html>`
|
||||
const result = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2021-11-27T02:30:00.000Z',
|
||||
stop: '2021-11-27T03:00:00.000Z',
|
||||
title: `City Report`
|
||||
},
|
||||
{
|
||||
start: '2021-11-27T03:00:00.000Z',
|
||||
stop: '2021-11-27T10:30:00.000Z',
|
||||
title: `ICC T20 Highlights`
|
||||
},
|
||||
{
|
||||
start: '2021-11-27T10:30:00.000Z',
|
||||
stop: '2021-11-28T02:00:00.000Z',
|
||||
title: `ICC T20 World Cup`
|
||||
},
|
||||
{
|
||||
start: '2021-11-28T02:00:00.000Z',
|
||||
stop: '2021-11-28T02:30:00.000Z',
|
||||
title: `Quran and Hadis`
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: `<!DOCTYPE html><html><head></head><body><textarea data-jtrt-table-id="508" id="jtrt_table_settings_508" cols="30" rows="10"></textarea></body></html>`
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="arianatelevision.com">
|
||||
<channels>
|
||||
<channel lang="en" xmltv_id="ArianaTVNational.af" logo="https://www.arianatelevision.com/wp-content/uploads/2017/08/logo-atn-new.png" site_id="#">Ariana TV National</channel>
|
||||
<channel lang="en" xmltv_id="ArianaTVNational.af" site_id="#" logo="https://www.arianatelevision.com/wp-content/uploads/2017/08/logo-atn-new.png">Ariana TV National</channel>
|
||||
</channels>
|
||||
</site>
|
Loading…
Add table
Add a link
Reference in a new issue