mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 17:10: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 cheerio = require('cheerio')
|
||||||
const { JSDOM } = jsdom
|
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(customParseFormat)
|
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'vidio.com',
|
site: 'vidio.com',
|
||||||
|
@ -15,19 +14,23 @@ module.exports = {
|
||||||
return `https://www.vidio.com/live/${channel.site_id}/schedules`
|
return `https://www.vidio.com/live/${channel.site_id}/schedules`
|
||||||
},
|
},
|
||||||
parser({ content, date }) {
|
parser({ content, date }) {
|
||||||
let PM = false
|
|
||||||
const programs = []
|
const programs = []
|
||||||
const items = parseItems(content, date)
|
const items = parseItems(content, date)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = parseTitle(item)
|
const prev = programs[programs.length - 1]
|
||||||
const start = parseStart(item, date)
|
const $item = cheerio.load(item)
|
||||||
let stop = parseStop(item, date)
|
let start = parseStart($item, date)
|
||||||
if (!stop) return
|
if (prev && start.isBefore(prev.start)) {
|
||||||
if (stop.hour() > 11) PM = true
|
start = start.add(1, 'd')
|
||||||
if (stop.hour() < 12 && PM) stop = stop.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({
|
programs.push({
|
||||||
title,
|
title: parseTitle($item),
|
||||||
start,
|
start,
|
||||||
stop
|
stop
|
||||||
})
|
})
|
||||||
|
@ -37,51 +40,32 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStop(item, date) {
|
function parseStart($item, date) {
|
||||||
const time = (
|
const timeString = $item('div.b-livestreaming-daily-schedule__item-content-caption').text()
|
||||||
item.querySelector('div.b-livestreaming-daily-schedule__item-content-caption') || {
|
const [_, start] = timeString.match(/(\d{2}:\d{2}) -/) || [null, null]
|
||||||
textContent: ''
|
const dateString = `${date.format('YYYY-MM-DD')} ${start}`
|
||||||
}
|
|
||||||
).textContent
|
|
||||||
|
|
||||||
return dayjs.tz(
|
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Asia/Jakarta')
|
||||||
date.format('YYYY-MM-DD ').concat(time.substring(8, 13)),
|
|
||||||
'YYYY-MM-DD HH:mm',
|
|
||||||
'Asia/Jakarta'
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item, date) {
|
function parseStop($item, date) {
|
||||||
const time = (
|
const timeString = $item('div.b-livestreaming-daily-schedule__item-content-caption').text()
|
||||||
item.querySelector('div.b-livestreaming-daily-schedule__item-content-caption') || {
|
const [_, stop] = timeString.match(/- (\d{2}:\d{2}) WIB/) || [null, null]
|
||||||
textContent: ''
|
const dateString = `${date.format('YYYY-MM-DD')} ${stop}`
|
||||||
}
|
|
||||||
).textContent
|
|
||||||
|
|
||||||
return dayjs.tz(
|
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Asia/Jakarta')
|
||||||
date.format('YYYY-MM-DD ').concat(time.substring(0, 5)),
|
|
||||||
'YYYY-MM-DD HH:mm',
|
|
||||||
'Asia/Jakarta'
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle(item) {
|
function parseTitle($item) {
|
||||||
return (
|
return $item('div.b-livestreaming-daily-schedule__item-content-title').text()
|
||||||
item.querySelector('div.b-livestreaming-daily-schedule__item-content-title') || {
|
|
||||||
textContent: ''
|
|
||||||
}
|
|
||||||
).textContent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, date) {
|
function parseItems(content, date) {
|
||||||
const dom = new JSDOM(content)
|
const $ = cheerio.load(content)
|
||||||
const list = dom.window.document.querySelector(
|
|
||||||
|
return $(
|
||||||
`#schedule-content-${date.format(
|
`#schedule-content-${date.format(
|
||||||
'YYYYMMDD'
|
'YYYYMMDD'
|
||||||
)} > .b-livestreaming-daily-schedule__scroll-container`
|
)} > .b-livestreaming-daily-schedule__scroll-container .b-livestreaming-daily-schedule__item`
|
||||||
)
|
).toArray()
|
||||||
|
|
||||||
if (!list) return []
|
|
||||||
|
|
||||||
return list.querySelectorAll('div.b-livestreaming-daily-schedule__item')
|
|
||||||
}
|
}
|
||||||
|
|
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