Initial Commit
This commit is contained in:
13
sites/walesi.com.fj/walesi.com.fj.channels.xml
Normal file
13
sites/walesi.com.fj/walesi.com.fj.channels.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="walesi.com.fj">
|
||||
<channels>
|
||||
<channel lang="fj" xmltv_id="Channel2.fj" site_id="channel-2">Channel 2</channel>
|
||||
<channel lang="fj" xmltv_id="FBC2.fj" site_id="fbc2">FBC 2</channel>
|
||||
<channel lang="fj" xmltv_id="FBCSports.fj" site_id="fbc">FBC Sports</channel>
|
||||
<channel lang="fj" xmltv_id="FBCTV.fj" site_id="fbc-2">FBC TV</channel>
|
||||
<channel lang="fj" xmltv_id="FijiOne.fj" site_id="fiji_one">Fiji One</channel>
|
||||
<channel lang="fj" xmltv_id="HopeChannelFiji.fj" site_id="hope-channel">Hope Channel Fiji</channel>
|
||||
<channel lang="fj" xmltv_id="MaiTV.fj" site_id="mai-tv">Mai TV</channel>
|
||||
<channel lang="fj" xmltv_id="ParliamentofFiji.fj" site_id="parliament">Parliament of Fiji</channel>
|
||||
</channels>
|
||||
</site>
|
||||
92
sites/walesi.com.fj/walesi.com.fj.config.js
Normal file
92
sites/walesi.com.fj/walesi.com.fj.config.js
Normal file
@@ -0,0 +1,92 @@
|
||||
const axios = require('axios')
|
||||
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')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'walesi.com.fj',
|
||||
days: 2,
|
||||
skip: true, // the program is no longer available on the website
|
||||
url: 'https://www.walesi.com.fj/wp-admin/admin-ajax.php',
|
||||
request: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||
},
|
||||
data({ channel, date }) {
|
||||
const params = new URLSearchParams()
|
||||
params.append('chanel', channel.site_id)
|
||||
params.append('date', date.unix())
|
||||
params.append('action', 'extvs_get_schedule_simple')
|
||||
|
||||
return params
|
||||
}
|
||||
},
|
||||
parser({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
const start = parseStart($item, date)
|
||||
const stop = start.add(30, 'm')
|
||||
if (prev) prev.stop = start
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get(`https://www.walesi.com.fj/channel-guide/`)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(data)
|
||||
const channels = $(
|
||||
'div.ex-chanel-list > div.extvs-inline-chanel > ul > li.extvs-inline-select'
|
||||
).toArray()
|
||||
return channels.map(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const [_, name] = $item('span')
|
||||
.text()
|
||||
.trim()
|
||||
.match(/\d+\. (.*)/) || [null, null]
|
||||
return {
|
||||
lang: 'fj',
|
||||
site_id: $item('*').data('value'),
|
||||
name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('td.extvs-table1-programme > div > div > figure > h3').text()
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
let time = $item('td.extvs-table1-time > span').text().trim()
|
||||
if (!time) return null
|
||||
time = `${date.format('YYYY-MM-DD')} ${time}`
|
||||
|
||||
return dayjs.tz(time, 'YYYY-MM-DD H:mm a', 'Pacific/Fiji')
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const data = JSON.parse(content)
|
||||
if (!data.html) return []
|
||||
const $ = cheerio.load(data.html)
|
||||
|
||||
return $('table > tbody > tr').toArray()
|
||||
}
|
||||
67
sites/walesi.com.fj/walesi.com.fj.test.js
Normal file
67
sites/walesi.com.fj/walesi.com.fj.test.js
Normal file
@@ -0,0 +1,67 @@
|
||||
// npm run channels:parse --config=./sites/walesi.com.fj/walesi.com.fj.config.js --output=./sites/walesi.com.fj/walesi.com.fj.channels.xml
|
||||
// npx epg-grabber --config=sites/walesi.com.fj/walesi.com.fj.config.js --channels=sites/walesi.com.fj/walesi.com.fj.channels.xml --output=guide.xml --days=2
|
||||
|
||||
const { parser, url, request } = require('./walesi.com.fj.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-21', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'fbc-2',
|
||||
xmltv_id: 'FBCTV.fj'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url).toBe('https://www.walesi.com.fj/wp-admin/admin-ajax.php')
|
||||
})
|
||||
|
||||
it('can generate valid request method', () => {
|
||||
expect(request.method).toBe('POST')
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||
})
|
||||
})
|
||||
|
||||
it('can generate valid request data', () => {
|
||||
const result = request.data({ date, channel })
|
||||
expect(result.has('chanel')).toBe(true)
|
||||
expect(result.has('date')).toBe(true)
|
||||
expect(result.has('action')).toBe(true)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = `{"html":"\\t\\t\\t\\t\\t<table>\\r\\n\\t\\t\\t\\t\\t\\t<thead>\\r\\n\\t\\t\\t\\t\\t\\t\\t<tr>\\r\\n\\t\\t\\t\\t\\t\\t\\t\\t<th class=\\"extvs-table1-image\\">Image</th>\\r\\n\\t\\t\\t\\t\\t\\t\\t\\t<th class=\\"extvs-table1-time\\">Time</th>\\r\\n\\t\\t\\t\\t\\t\\t\\t\\t<th class=\\"extvs-table1-programme\\">Programme</th>\\r\\n\\t\\t\\t\\t\\t\\t\\t</tr>\\r\\n\\t\\t\\t\\t\\t\\t</thead>\\r\\n\\t\\t\\t\\t\\t\\t<tbody>\\r\\n\\r\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\r\\n<tr class=\\"\\">\\r\\n\\t<td class=\\"extvs-table1-image\\">\\r\\n\\t\\t\\t</td>\\r\\n\\t<td class=\\"extvs-table1-time\\"><span>12:00 am</span></td>\\r\\n\\t<td class=\\"extvs-table1-programme\\">\\r\\n\\t\\t<div class=\\"item-tvs\\">\\r\\n\\t\\t\\t<div class=\\"extvs-arrow\\">\\r\\n\\t\\t\\t\\t<figure class=\\"extvs-simple-sch\\">\\r\\n\\t\\t\\t\\t\\t<div class=\\"extvs-st2-plus\\"><div class=\\"extvs-icon-plus\\"></div></div>\\r\\n\\t\\t\\t\\t\\t<h3>Aljazeera</h3>\\r\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t</figure>\\r\\n\\t\\t\\t</div>\\r\\n\\t\\t\\t\\t\\t</div>\\r\\n\\t</td>\\r\\n</tr>\\t\\t\\t\\t\\t\\t\\t\\t\\t\\r\\n<tr class=\\"\\"> <td class=\\"extvs-table1-image\\"> </td><td class=\\"extvs-table1-time\\"><span>6:00 am</span></td><td class=\\"extvs-table1-programme\\"> <div class=\\"item-tvs\\"> <div class=\\"extvs-arrow\\"> <figure class=\\"extvs-simple-sch\\"> <div class=\\"extvs-st2-plus\\"><div class=\\"extvs-icon-plus\\"></div></div><h3>Move Fiji</h3> </figure> </div></div></td></tr></tbody></table>\\r\\n\\t\\t\\t\\t"}`
|
||||
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-20T12:00:00.000Z',
|
||||
stop: '2021-11-20T18:00:00.000Z',
|
||||
title: `Aljazeera`
|
||||
},
|
||||
{
|
||||
start: '2021-11-20T18:00:00.000Z',
|
||||
stop: '2021-11-20T18:30:00.000Z',
|
||||
title: `Move Fiji`
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: `{"html":"<p class=\\"ex-notice\\">No matching records found</p>"}`
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
Reference in New Issue
Block a user