mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Update mncvision.id.test.js
This commit is contained in:
parent
8cc1a46276
commit
84b8aeda42
1 changed files with 101 additions and 142 deletions
|
@ -1,8 +1,10 @@
|
||||||
|
// npx epg-grabber --config=sites/mncvision.id/mncvision.id.config.js --channels=sites/mncvision.id/mncvision.id_id-id.channels.xml --output=guide.xml --timeout=30000 --days=2
|
||||||
|
// npx epg-grabber --config=sites/mncvision.id/mncvision.id.config.js --channels=sites/mncvision.id/mncvision.id_id-en.channels.xml --output=guide.xml --timeout=30000 --days=2
|
||||||
// node ./scripts/channels.js --config=./sites/mncvision.id/mncvision.id.config.js --output=./sites/mncvision.id/mncvision.id_id.channels.xml
|
// node ./scripts/channels.js --config=./sites/mncvision.id/mncvision.id.config.js --output=./sites/mncvision.id/mncvision.id_id.channels.xml
|
||||||
// npx epg-grabber --config=sites/mncvision.id/mncvision.id.config.js --channels=sites/mncvision.id/mncvision.id_id-id.channels.xml --output=guide.xml --days=2
|
|
||||||
// npx epg-grabber --config=sites/mncvision.id/mncvision.id.config.js --channels=sites/mncvision.id/mncvision.id_id-en.channels.xml --output=guide.xml --days=2
|
|
||||||
|
|
||||||
const { parser, url, request } = require('./mncvision.id.config.js')
|
const { parser, url, request } = require('./mncvision.id.config.js')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
@ -12,181 +14,138 @@ dayjs.extend(utc)
|
||||||
|
|
||||||
jest.mock('axios')
|
jest.mock('axios')
|
||||||
|
|
||||||
const date = dayjs.utc('2021-11-12', 'YYYY-MM-DD').startOf('d')
|
const date = dayjs.utc('2022-10-05', 'YYYY-MM-DD').startOf('d')
|
||||||
const channelID = {
|
const channel = {
|
||||||
site_id: '203',
|
site_id: '38',
|
||||||
xmltv_id: 'AnimalPlanetSoutheastAsia.us',
|
xmltv_id: 'MiaoMi.hk',
|
||||||
lang: 'id'
|
lang: 'id'
|
||||||
}
|
}
|
||||||
const channelEN = {
|
const headers = {
|
||||||
site_id: '203',
|
'set-cookie': [
|
||||||
xmltv_id: 'AnimalPlanetSoutheastAsia.us',
|
's1nd0vL=05e9pr6gi112tdmutsn7big93o75r0b0; expires=Wed, 05-Oct-2022 14:18:22 GMT; Max-Age=7200; path=/; HttpOnly'
|
||||||
lang: 'en'
|
]
|
||||||
}
|
}
|
||||||
const setCookie = [
|
|
||||||
's1nd0vL=0qpsmm7dpjmi7nt8d2h5epf16rmgg8a8; expires=Sat, 05-Mar-2022 15:44:22 GMT; Max-Age=7200; path=/; HttpOnly'
|
|
||||||
]
|
|
||||||
|
|
||||||
const content0 = `<!DOCTYPE html><html lang="en"> <head></head> <body> <div id="id-content-schedule-table" class="lang-indonesia tm-content-container"> <div class="container content-schedule-table"> <h1 class="page-header tm">Jadwal Tayang Cari</h1> <div id="schedule" class="schedule_table panel tm tm-block tm-block-1"> <div class="schedule_search_result_container"> <div class='schedule_search_desc_container'><span class="subpage-title">Jadwal Tayang</span> Channel: <span class='label label-default'>41</span> Tanggal: <span class='label label-default'>2022-03-05</span></div><table class="table table-striped table-bordered table-hover table-condensed" cellspacing="0" cellpadding="0" border="0"> <tr> <th width='10%'>Jam Tayang</th> <th width='80%' align='left'>Program Acara</th> <th width='10%'>Durasi</th> </tr><tr valign="top"> <td class="text-center">00:00</td><td><a href="https://www.mncvision.id/schedule/detail/2022030500000041/Hey-Duggee-S3-Ep-22/1" title="Hey Duggee S3, Ep 22" rel="facebox">Hey Duggee S3, Ep 22</a></td><td class="text-center">00:07</td></tr></table> <div align="center" class="box well">page: <strong>1</strong><a href="https://www.mncvision.id/schedule/table/startno/50" data-ci-pagination-page="2">2</a><a href="https://www.mncvision.id/schedule/table/startno/50" data-ci-pagination-page="2" rel="next">></a></div></div></div></div></div></body></html>`
|
|
||||||
const content50 = `<!DOCTYPE html><html lang="en"> <head></head> <body> <div id="id-content-schedule-table" class="lang-indonesia tm-content-container"> <div class="container content-schedule-table"> <h1 class="page-header tm">Jadwal Tayang Cari</h1> <div id="schedule" class="schedule_table panel tm tm-block tm-block-1"> <div class="schedule_search_result_container"> <div class='schedule_search_desc_container'><span class="subpage-title">Jadwal Tayang</span> Channel: <span class='label label-default'>41</span> Tanggal: <span class='label label-default'>2022-03-05</span></div><table class="table table-striped table-bordered table-hover table-condensed" cellspacing="0" cellpadding="0" border="0"> <tr> <th width='10%'>Jam Tayang</th> <th width='80%' align='left'>Program Acara</th> <th width='10%'>Durasi</th> </tr><tr valign="top"> <td class="text-center">08:25</td><td><a href="https://www.mncvision.id/schedule/detail/2022030508250041/Hey-Duggee-S1-Ep-46/1" title="Hey Duggee S1, Ep 46" rel="facebox">Hey Duggee S1, Ep 46</a></td><td class="text-center">00:07</td></tr></table> <div align="center" class="box well">page: <a href="https://www.mncvision.id/schedule/table/startno/" data-ci-pagination-page="1" rel="prev"><</a><a href="https://www.mncvision.id/schedule/table/startno/" data-ci-pagination-page="1" rel="start">1</a><strong>2</strong><a href="https://www.mncvision.id/schedule/table/startno/100" data-ci-pagination-page="3" rel="next">></a></div></div></div></div></div></body></html>`
|
|
||||||
|
|
||||||
it('can generate valid url', () => {
|
it('can generate valid url', () => {
|
||||||
expect(url).toBe('https://mncvision.id/schedule/table')
|
expect(url).toBe('https://mncvision.id/schedule/table')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('can generate valid request method', () => {
|
||||||
|
expect(request.method).toBe('POST')
|
||||||
|
})
|
||||||
|
|
||||||
it('can generate valid request headers', () => {
|
it('can generate valid request headers', () => {
|
||||||
expect(request.headers).toMatchObject({
|
expect(request.headers).toMatchObject({
|
||||||
'Content-Type': 'multipart/form-data; boundary=X-EPG-BOUNDARY'
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can generate valid request data', () => {
|
it('can generate valid request data', () => {
|
||||||
const result = request.data({ channel: channelID, date })
|
const data = request.data({ channel, date })
|
||||||
expect(result._boundary).toBe('X-EPG-BOUNDARY')
|
expect(data.get('search_model')).toBe('channel')
|
||||||
|
expect(data.get('af0rmelement')).toBe('aformelement')
|
||||||
|
expect(data.get('fdate')).toBe('2022-10-05')
|
||||||
|
expect(data.get('fchannel')).toBe('38')
|
||||||
|
expect(data.get('submit')).toBe('Search')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response in Indonesian', done => {
|
it('can parse response', async () => {
|
||||||
const setLangCookie = [
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||||
's1nd0vL=oj87dbpo7cqbg8fit3295075kodja8hl; expires=Fri, 11-Mar-2022 14:40:17 GMT; Max-Age=7200; path=/; HttpOnly'
|
const indonesiaHeaders = {
|
||||||
]
|
'set-cookie': [
|
||||||
|
's1nd0vL=e3vjb0oaf9vijiqsg7cml4i7fdkq16db; expires=Wed, 05-Oct-2022 14:54:16 GMT; Max-Age=7200; path=/; HttpOnly'
|
||||||
axios.get.mockImplementation((url, options = {}) => {
|
]
|
||||||
|
}
|
||||||
|
const englishHeaders = {
|
||||||
|
'set-cookie': [
|
||||||
|
's1nd0vL=hfd6hpnpr6gvgart0d8rf7ef6t4gi7nr; expires=Wed, 05-Oct-2022 15:08:55 GMT; Max-Age=7200; path=/; HttpOnly'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
axios.get.mockImplementation((url, opts) => {
|
||||||
if (
|
if (
|
||||||
url === 'https://www.mncvision.id/schedule/table/startno/50' &&
|
url === 'https://www.mncvision.id/schedule/table/startno/50' &&
|
||||||
options.headers &&
|
opts.headers['Cookie'] === headers['set-cookie'][0]
|
||||||
options.headers['Cookie'] === setCookie.join(';')
|
|
||||||
) {
|
) {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
data: content50
|
data: fs.readFileSync(path.resolve(__dirname, '__data__/content_p2.html'))
|
||||||
})
|
})
|
||||||
} else if (url === 'https://www.mncvision.id/language_switcher/setlang/indonesia/') {
|
} else if (url === 'https://www.mncvision.id/language_switcher/setlang/indonesia/') {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
headers: {
|
headers: indonesiaHeaders
|
||||||
'set-cookie': setLangCookie
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else if (
|
|
||||||
url === 'https://www.mncvision.id/schedule/detail/2022030500000041/Hey-Duggee-S3-Ep-22/1' &&
|
|
||||||
options.headers &&
|
|
||||||
options.headers['X-Requested-With'] === 'XMLHttpRequest' &&
|
|
||||||
options.headers['Cookie'] === setLangCookie.join(';')
|
|
||||||
) {
|
|
||||||
return Promise.resolve({
|
|
||||||
data: `<!DOCTYPE html><html lang="en"><head></head><body><blockquote class="bloquet synopsis">
|
|
||||||
Nikmati suasana kehidupan koloni anjing laut di kawasan pantai barat Afrika Selatan. </blockquote></body></html>`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve({ data: '' })
|
|
||||||
})
|
|
||||||
|
|
||||||
parser({ date, content: content0, headers: { 'set-cookie': setCookie }, channel: channelID })
|
|
||||||
.then(result => {
|
|
||||||
result = result.map(p => {
|
|
||||||
p.start = p.start.toJSON()
|
|
||||||
p.stop = p.stop.toJSON()
|
|
||||||
return p
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result).toMatchObject([
|
|
||||||
{
|
|
||||||
start: '2021-11-11T17:00:00.000Z',
|
|
||||||
stop: '2021-11-11T17:07:00.000Z',
|
|
||||||
title: 'Hey Duggee S3, Ep 22',
|
|
||||||
description:
|
|
||||||
'Nikmati suasana kehidupan koloni anjing laut di kawasan pantai barat Afrika Selatan.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
start: '2021-11-12T01:25:00.000Z',
|
|
||||||
stop: '2021-11-12T01:32:00.000Z',
|
|
||||||
title: 'Hey Duggee S1, Ep 46',
|
|
||||||
description: null
|
|
||||||
}
|
|
||||||
])
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
done(error)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can parse response in English', done => {
|
|
||||||
const setLangCookie = [
|
|
||||||
's1nd0vL=4li9qu3olhjl9djrl971opl2tgb27p1v; expires=Fri, 11-Mar-2022 14:26:55 GMT; Max-Age=7200; path=/; HttpOnly'
|
|
||||||
]
|
|
||||||
|
|
||||||
axios.get.mockImplementation((url, options = {}) => {
|
|
||||||
if (
|
|
||||||
url === 'https://www.mncvision.id/schedule/table/startno/50' &&
|
|
||||||
options.headers &&
|
|
||||||
options.headers['Cookie'] === setCookie.join(';')
|
|
||||||
) {
|
|
||||||
return Promise.resolve({
|
|
||||||
data: content50
|
|
||||||
})
|
})
|
||||||
} else if (url === 'https://www.mncvision.id/language_switcher/setlang/english/') {
|
} else if (url === 'https://www.mncvision.id/language_switcher/setlang/english/') {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
headers: {
|
headers: englishHeaders
|
||||||
'set-cookie': setLangCookie
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} else if (
|
} else if (
|
||||||
url === 'https://www.mncvision.id/schedule/detail/2022030500000041/Hey-Duggee-S3-Ep-22/1' &&
|
url ===
|
||||||
options.headers &&
|
'https://mncvision.id/schedule/detail/2022100500000038/Adventures-With-Miao-Mi-Ep-1/1' &&
|
||||||
options.headers['X-Requested-With'] === 'XMLHttpRequest' &&
|
opts.headers['Cookie'] === indonesiaHeaders['set-cookie'][0]
|
||||||
options.headers['Cookie'] === setLangCookie.join(';')
|
|
||||||
) {
|
) {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
data: `<!DOCTYPE html><html lang="en"><head></head><body><blockquote class="bloquet synopsis">
|
data: fs.readFileSync(path.resolve(__dirname, '__data__/program_id.html'))
|
||||||
While Castiel investigates the disappearance of a local teen, Sam and Dean are visited by an old friend. </blockquote></body></html>`
|
})
|
||||||
|
} else if (
|
||||||
|
url ===
|
||||||
|
'https://mncvision.id/schedule/detail/2022100500000038/Adventures-With-Miao-Mi-Ep-1/1' &&
|
||||||
|
opts.headers['Cookie'] === englishHeaders['set-cookie'][0]
|
||||||
|
) {
|
||||||
|
return Promise.resolve({
|
||||||
|
data: fs.readFileSync(path.resolve(__dirname, '__data__/program_en.html'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({ data: '' })
|
return Promise.resolve({ data: '' })
|
||||||
})
|
})
|
||||||
|
|
||||||
parser({ date, content: content0, headers: { 'set-cookie': setCookie }, channel: channelEN })
|
let indonesiaResults = await parser({ date, content, channel, headers })
|
||||||
.then(result => {
|
indonesiaResults = indonesiaResults.map(p => {
|
||||||
result = result.map(p => {
|
p.start = p.start.toJSON()
|
||||||
p.start = p.start.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
return p
|
||||||
return p
|
})
|
||||||
})
|
|
||||||
|
expect(indonesiaResults[0]).toMatchObject({
|
||||||
expect(result).toMatchObject([
|
start: '2022-10-04T17:00:00.000Z',
|
||||||
{
|
stop: '2022-10-04T17:06:00.000Z',
|
||||||
start: '2021-11-11T17:00:00.000Z',
|
title: 'Adventures With Miao Mi, Ep 1',
|
||||||
stop: '2021-11-11T17:07:00.000Z',
|
episode: 1,
|
||||||
title: 'Hey Duggee S3, Ep 22',
|
description:
|
||||||
description:
|
'Ketika anak-anak mulai menghilang, sekelompok anak kecil harus menghadapi ketakutan terbesar mereka ketika mereka melawan sesosok badut pembunuh yang jahat.'
|
||||||
'While Castiel investigates the disappearance of a local teen, Sam and Dean are visited by an old friend.'
|
})
|
||||||
},
|
|
||||||
{
|
expect(indonesiaResults[4]).toMatchObject({
|
||||||
start: '2021-11-12T01:25:00.000Z',
|
start: '2022-10-04T17:33:00.000Z',
|
||||||
stop: '2021-11-12T01:32:00.000Z',
|
stop: '2022-10-04T17:46:00.000Z',
|
||||||
title: 'Hey Duggee S1, Ep 46',
|
title: 'Leo Wildlife Ranger S2, Ep 27',
|
||||||
description: null
|
season: 2,
|
||||||
}
|
episode: 27
|
||||||
])
|
})
|
||||||
done()
|
|
||||||
})
|
let englishResults = await parser({ date, content, channel: { ...channel, lang: 'en' }, headers })
|
||||||
.catch(error => {
|
englishResults = englishResults.map(p => {
|
||||||
done(error)
|
p.start = p.start.toJSON()
|
||||||
})
|
p.stop = p.stop.toJSON()
|
||||||
})
|
return p
|
||||||
|
})
|
||||||
it('can handle empty guide', done => {
|
|
||||||
parser({
|
expect(englishResults[0]).toMatchObject({
|
||||||
date,
|
start: '2022-10-04T17:00:00.000Z',
|
||||||
channel: channelID,
|
stop: '2022-10-04T17:06:00.000Z',
|
||||||
content: `<!DOCTYPE html><html lang="en"><head></head><body></body></html>`,
|
title: 'Adventures With Miao Mi, Ep 1',
|
||||||
headers: { 'set-cookie': setCookie }
|
episode: 1,
|
||||||
|
description:
|
||||||
|
'When children begin to disappear, a group of young kids have to face their biggest fears when they square off against a murderous, evil clown.'
|
||||||
})
|
})
|
||||||
.then(result => {
|
})
|
||||||
expect(result).toMatchObject([])
|
|
||||||
done()
|
it('can handle empty guide', async () => {
|
||||||
})
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||||
.catch(error => {
|
let results = await parser({
|
||||||
done(error)
|
date,
|
||||||
})
|
channel,
|
||||||
|
content,
|
||||||
|
headers
|
||||||
|
})
|
||||||
|
expect(results).toMatchObject([])
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue