mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Merge pull request #297 from iptv-org/update-vidio-com
Update vidio.com
This commit is contained in:
commit
fd719cc538
2 changed files with 87 additions and 49 deletions
|
@ -1,13 +1,12 @@
|
|||
const jsdom = require('jsdom')
|
||||
const { JSDOM } = jsdom
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'vidio.com',
|
||||
|
@ -15,19 +14,23 @@ module.exports = {
|
|||
return `https://www.vidio.com/live/${channel.site_id}/schedules`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
let PM = false
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
items.forEach(item => {
|
||||
const title = parseTitle(item)
|
||||
const start = parseStart(item, date)
|
||||
let stop = parseStop(item, date)
|
||||
if (!stop) return
|
||||
if (stop.hour() > 11) PM = true
|
||||
if (stop.hour() < 12 && PM) stop = stop.add(1, 'd')
|
||||
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date)
|
||||
if (prev && start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
let stop = parseStop($item, date)
|
||||
if (stop.isBefore(start)) {
|
||||
stop = stop.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
programs.push({
|
||||
title,
|
||||
title: parseTitle($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
|
@ -37,51 +40,32 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
function parseStop(item, date) {
|
||||
const time = (
|
||||
item.querySelector('div.b-livestreaming-daily-schedule__item-content-caption') || {
|
||||
textContent: ''
|
||||
}
|
||||
).textContent
|
||||
function parseStart($item, date) {
|
||||
const timeString = $item('div.b-livestreaming-daily-schedule__item-content-caption').text()
|
||||
const [_, start] = timeString.match(/(\d{2}:\d{2}) -/) || [null, null]
|
||||
const dateString = `${date.format('YYYY-MM-DD')} ${start}`
|
||||
|
||||
return dayjs.tz(
|
||||
date.format('YYYY-MM-DD ').concat(time.substring(8, 13)),
|
||||
'YYYY-MM-DD HH:mm',
|
||||
'Asia/Jakarta'
|
||||
)
|
||||
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Asia/Jakarta')
|
||||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
const time = (
|
||||
item.querySelector('div.b-livestreaming-daily-schedule__item-content-caption') || {
|
||||
textContent: ''
|
||||
}
|
||||
).textContent
|
||||
function parseStop($item, date) {
|
||||
const timeString = $item('div.b-livestreaming-daily-schedule__item-content-caption').text()
|
||||
const [_, stop] = timeString.match(/- (\d{2}:\d{2}) WIB/) || [null, null]
|
||||
const dateString = `${date.format('YYYY-MM-DD')} ${stop}`
|
||||
|
||||
return dayjs.tz(
|
||||
date.format('YYYY-MM-DD ').concat(time.substring(0, 5)),
|
||||
'YYYY-MM-DD HH:mm',
|
||||
'Asia/Jakarta'
|
||||
)
|
||||
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Asia/Jakarta')
|
||||
}
|
||||
|
||||
function parseTitle(item) {
|
||||
return (
|
||||
item.querySelector('div.b-livestreaming-daily-schedule__item-content-title') || {
|
||||
textContent: ''
|
||||
}
|
||||
).textContent
|
||||
function parseTitle($item) {
|
||||
return $item('div.b-livestreaming-daily-schedule__item-content-title').text()
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
const dom = new JSDOM(content)
|
||||
const list = dom.window.document.querySelector(
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $(
|
||||
`#schedule-content-${date.format(
|
||||
'YYYYMMDD'
|
||||
)} > .b-livestreaming-daily-schedule__scroll-container`
|
||||
)
|
||||
|
||||
if (!list) return []
|
||||
|
||||
return list.querySelectorAll('div.b-livestreaming-daily-schedule__item')
|
||||
)} > .b-livestreaming-daily-schedule__scroll-container .b-livestreaming-daily-schedule__item`
|
||||
).toArray()
|
||||
}
|
||||
|
|
54
sites/vidio.com/vidio.com.test.js
Normal file
54
sites/vidio.com/vidio.com.test.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
// npx epg-grabber --config=sites/vidio.com/vidio.com.config.js --channels=sites/vidio.com/vidio.com_id.channels.xml --output=.gh-pages/guides/id/vidio.com.epg.xml --days=2
|
||||
|
||||
const { parser, url } = require('./vidio.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-24', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '7464',
|
||||
xmltv_id: 'AjwaTV.id'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel })).toBe('https://www.vidio.com/live/7464/schedules')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = `<div class="b-livestreaming-daily-schedule__section b-livestreaming-daily-schedule__contents"> <div class="b-livestreaming-daily-schedule__content" id="schedule-content-20211124"> <div class="js-ahoy b-livestreaming-schedule__ahoy-impression" data-ahoy-component="Ahoy::Builder" data-ahoy-impression="true" data-ahoy-title="LIVESTREAMING" data-use-bounding-client-rect="true" ></div><div class="b-livestreaming-daily-schedule__scroll-container"> <a class="" href="/watch/2361692-30-hari-30-juz-24-november-2021" ><div class="b-livestreaming-daily-schedule__item js-ahoy" data-ahoy-click="true" data-ahoy-component="Ahoy::Builder" data-ahoy-props='{"section":"schedule","stream_type":"TvStream","livestreaming_id":7464,"schedule_day":-1,"schedule_id":1471806,"schedule_title":"30 Hari 30 Juz","action":"click"}' data-ahoy-title="LIVESTREAMING" id="schedule-item-1471806" > <div class="b-livestreaming-daily-schedule__item-icon"> <div class="b-livestreaming-daily-schedule__item-icon-play"></div></div><div class="b-livestreaming-daily-schedule__item-content"> <div class="b-livestreaming-daily-schedule__item-content-caption"> 00:30 - 01:30 WIB </div><div class="b-livestreaming-daily-schedule__item-content-title">30 Hari 30 Juz</div></div></div></a ><a class="" href="/watch/2361785-makkah-live-24-november-2021" ><div class="b-livestreaming-daily-schedule__item js-ahoy" data-ahoy-click="true" data-ahoy-component="Ahoy::Builder" data-ahoy-props='{"section":"schedule","stream_type":"TvStream","livestreaming_id":7464,"schedule_day":-1,"schedule_id":1471807,"schedule_title":"Makkah Live","action":"click"}' data-ahoy-title="LIVESTREAMING" id="schedule-item-1471807" > <div class="b-livestreaming-daily-schedule__item-icon"> <div class="b-livestreaming-daily-schedule__item-icon-play"></div></div><div class="b-livestreaming-daily-schedule__item-content"> <div class="b-livestreaming-daily-schedule__item-content-caption"> 01:30 - 04:00 WIB </div><div class="b-livestreaming-daily-schedule__item-content-title">Makkah Live</div></div></div></a ><a class="" href="/watch/2362889-ftv-islami-24-november-2021" ><div class="b-livestreaming-daily-schedule__item js-ahoy" data-ahoy-click="true" data-ahoy-component="Ahoy::Builder" data-ahoy-props='{"section":"schedule","stream_type":"TvStream","livestreaming_id":7464,"schedule_day":-1,"schedule_id":1473829,"schedule_title":"FTV Islami","action":"click"}' data-ahoy-title="LIVESTREAMING" id="schedule-item-1473829" > <div class="b-livestreaming-daily-schedule__item-icon"> <div class="b-livestreaming-daily-schedule__item-icon-play"></div></div><div class="b-livestreaming-daily-schedule__item-content"> <div class="b-livestreaming-daily-schedule__item-content-caption"> 22:30 - 00:30 WIB </div><div class="b-livestreaming-daily-schedule__item-content-title">FTV Islami</div></div></div></a > </div></div><div class="b-livestreaming-daily-schedule__content tab-active" id="schedule-content-20211125"> <div class="js-ahoy b-livestreaming-schedule__ahoy-impression" data-ahoy-component="Ahoy::Builder" data-ahoy-impression="true" data-ahoy-title="LIVESTREAMING" data-use-bounding-client-rect="true" ></div><div class="b-livestreaming-daily-schedule__scroll-container"> <a class="" href="/watch/2362921-30-hari-30-juz-25-november-2021" ><div class="b-livestreaming-daily-schedule__item js-ahoy" data-ahoy-click="true" data-ahoy-component="Ahoy::Builder" data-ahoy-props='{"section":"schedule","stream_type":"TvStream","livestreaming_id":7464,"schedule_day":0,"schedule_id":1473830,"schedule_title":"30 Hari 30 Juz","action":"click"}' data-ahoy-title="LIVESTREAMING" id="schedule-item-1473830" > <div class="b-livestreaming-daily-schedule__item-icon"> <div class="b-livestreaming-daily-schedule__item-icon-play"></div></div><div class="b-livestreaming-daily-schedule__item-content"> <div class="b-livestreaming-daily-schedule__item-content-caption"> 00:30 - 01:30 WIB </div><div class="b-livestreaming-daily-schedule__item-content-title">30 Hari 30 Juz</div></div></div></a > </div></div></div>`
|
||||
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-23T17:30:00.000Z',
|
||||
stop: '2021-11-23T18:30:00.000Z',
|
||||
title: `30 Hari 30 Juz`
|
||||
},
|
||||
{
|
||||
start: '2021-11-23T18:30:00.000Z',
|
||||
stop: '2021-11-23T21:00:00.000Z',
|
||||
title: `Makkah Live`
|
||||
},
|
||||
{
|
||||
start: '2021-11-24T15:30:00.000Z',
|
||||
stop: '2021-11-24T17:30:00.000Z',
|
||||
title: `FTV Islami`
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: `<!DOCTYPE html><html><head></head><body></body></html>`
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue