mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 17:10:07 -04:00
Merge pull request #612 from iptv-org/fix-mncvision.id
Fix mncvision.id
This commit is contained in:
commit
d1271adde1
2 changed files with 72 additions and 39 deletions
|
@ -32,29 +32,24 @@ module.exports = {
|
||||||
},
|
},
|
||||||
async parser({ content, date, headers, channel }) {
|
async parser({ content, date, headers, channel }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
|
|
||||||
let items = parseItems(content)
|
let items = parseItems(content)
|
||||||
|
if (!items.length) return programs
|
||||||
|
|
||||||
const pages = parsePages(content)
|
const pages = parsePages(content)
|
||||||
const cookies = headers && headers['set-cookie'] ? headers['set-cookie'].join(';') : ''
|
const cookies = headers && headers['set-cookie'] ? headers['set-cookie'].join(';') : ''
|
||||||
for (let url of pages) {
|
for (let url of pages) {
|
||||||
const nextContent = await axios
|
items = items.concat(parseItems(await loadNextPage(url, cookies)))
|
||||||
.get(url, {
|
|
||||||
headers: {
|
|
||||||
Cookie: cookies
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(r => r.data)
|
|
||||||
.catch(console.log)
|
|
||||||
items = items.concat(parseItems(nextContent))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const langCookies = await loadLangCookies(channel)
|
||||||
|
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const start = parseStart(item, date)
|
const start = parseStart(item, date)
|
||||||
const duration = parseDuration(item)
|
const duration = parseDuration(item)
|
||||||
const stop = start.add(duration, 'm')
|
const stop = start.add(duration, 'm')
|
||||||
programs.push({
|
programs.push({
|
||||||
title: parseTitle(item),
|
title: parseTitle(item),
|
||||||
description: await loadDescription(item, channel),
|
description: await loadDescription(item, langCookies),
|
||||||
start,
|
start,
|
||||||
stop
|
stop
|
||||||
})
|
})
|
||||||
|
@ -84,17 +79,33 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadDescription(item, channel) {
|
async function loadNextPage(url, cookies) {
|
||||||
const cookies = {
|
return axios
|
||||||
en: 's1nd0vL=jgs82rfmntm362uvdbknng4l5n4lq4u4;',
|
.get(url, {
|
||||||
id: 's1nd0vL=bfh2v7qvrsso7ck6pama3ane6bfv5k5g;'
|
headers: {
|
||||||
}
|
Cookie: cookies
|
||||||
const cookie = cookies[channel.lang]
|
}
|
||||||
|
})
|
||||||
|
.then(r => r.data)
|
||||||
|
.catch(console.log)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadLangCookies(channel) {
|
||||||
|
const lang = channel.lang === 'en' ? 'english' : 'indonesia'
|
||||||
|
const url = `https://www.mncvision.id/language_switcher/setlang/${lang}/`
|
||||||
|
|
||||||
|
return axios
|
||||||
|
.get(url)
|
||||||
|
.then(r => r.headers['set-cookie'].join(';'))
|
||||||
|
.catch(console.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadDescription(item, cookies) {
|
||||||
const $item = cheerio.load(item)
|
const $item = cheerio.load(item)
|
||||||
const progUrl = $item('a').attr('href')
|
const progUrl = $item('a').attr('href')
|
||||||
if (!progUrl) return null
|
if (!progUrl) return null
|
||||||
const data = await axios
|
const data = await axios
|
||||||
.get(progUrl, { headers: { 'X-Requested-With': 'XMLHttpRequest', cookie } })
|
.get(progUrl, { headers: { 'X-Requested-With': 'XMLHttpRequest', Cookie: cookies } })
|
||||||
.then(r => r.data)
|
.then(r => r.data)
|
||||||
.catch(console.log)
|
.catch(console.log)
|
||||||
if (!data) return null
|
if (!data) return null
|
||||||
|
|
|
@ -26,6 +26,7 @@ const channelEN = {
|
||||||
const setCookie = [
|
const setCookie = [
|
||||||
's1nd0vL=0qpsmm7dpjmi7nt8d2h5epf16rmgg8a8; expires=Sat, 05-Mar-2022 15:44:22 GMT; Max-Age=7200; path=/; HttpOnly'
|
'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 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>`
|
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>`
|
||||||
|
|
||||||
|
@ -45,18 +46,12 @@ it('can generate valid request data', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response in Indonesian', done => {
|
it('can parse response in Indonesian', done => {
|
||||||
|
const setLangCookie = [
|
||||||
|
's1nd0vL=oj87dbpo7cqbg8fit3295075kodja8hl; expires=Fri, 11-Mar-2022 14:40:17 GMT; Max-Age=7200; path=/; HttpOnly'
|
||||||
|
]
|
||||||
|
|
||||||
axios.get.mockImplementation((url, options = {}) => {
|
axios.get.mockImplementation((url, options = {}) => {
|
||||||
if (
|
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'] === 's1nd0vL=bfh2v7qvrsso7ck6pama3ane6bfv5k5g;'
|
|
||||||
) {
|
|
||||||
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>`
|
|
||||||
})
|
|
||||||
} else if (
|
|
||||||
url === 'https://www.mncvision.id/schedule/table/startno/50' &&
|
url === 'https://www.mncvision.id/schedule/table/startno/50' &&
|
||||||
options.headers &&
|
options.headers &&
|
||||||
options.headers['Cookie'] === setCookie.join(';')
|
options.headers['Cookie'] === setCookie.join(';')
|
||||||
|
@ -64,6 +59,22 @@ it('can parse response in Indonesian', done => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
data: content50
|
data: content50
|
||||||
})
|
})
|
||||||
|
} else if (url === 'https://www.mncvision.id/language_switcher/setlang/indonesia/') {
|
||||||
|
return Promise.resolve({
|
||||||
|
headers: {
|
||||||
|
'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: '' })
|
return Promise.resolve({ data: '' })
|
||||||
|
@ -100,18 +111,12 @@ it('can parse response in Indonesian', done => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response in English', done => {
|
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 = {}) => {
|
axios.get.mockImplementation((url, options = {}) => {
|
||||||
if (
|
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'] === 's1nd0vL=jgs82rfmntm362uvdbknng4l5n4lq4u4;'
|
|
||||||
) {
|
|
||||||
return Promise.resolve({
|
|
||||||
data: `<!DOCTYPE html><html lang="en"><head></head><body><blockquote class="bloquet synopsis">
|
|
||||||
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://www.mncvision.id/schedule/table/startno/50' &&
|
url === 'https://www.mncvision.id/schedule/table/startno/50' &&
|
||||||
options.headers &&
|
options.headers &&
|
||||||
options.headers['Cookie'] === setCookie.join(';')
|
options.headers['Cookie'] === setCookie.join(';')
|
||||||
|
@ -119,6 +124,22 @@ it('can parse response in English', done => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
data: content50
|
data: content50
|
||||||
})
|
})
|
||||||
|
} else if (url === 'https://www.mncvision.id/language_switcher/setlang/english/') {
|
||||||
|
return Promise.resolve({
|
||||||
|
headers: {
|
||||||
|
'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">
|
||||||
|
While Castiel investigates the disappearance of a local teen, Sam and Dean are visited by an old friend. </blockquote></body></html>`
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({ data: '' })
|
return Promise.resolve({ data: '' })
|
||||||
|
@ -158,7 +179,8 @@ it('can handle empty guide', done => {
|
||||||
parser({
|
parser({
|
||||||
date,
|
date,
|
||||||
channel: channelID,
|
channel: channelID,
|
||||||
content: `<!DOCTYPE html><html lang="en"><head></head><body></body></html>`
|
content: `<!DOCTYPE html><html lang="en"><head></head><body></body></html>`,
|
||||||
|
headers: { 'set-cookie': setCookie }
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
expect(result).toMatchObject([])
|
expect(result).toMatchObject([])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue