mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
commit
afd4ff6ece
2 changed files with 114 additions and 24 deletions
|
@ -1,5 +1,4 @@
|
|||
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')
|
||||
|
@ -15,27 +14,32 @@ module.exports = {
|
|||
return `https://mi.tv/${country}/async/channel/${id}/${date.format('YYYY-MM-DD')}/0`
|
||||
},
|
||||
logo({ content }) {
|
||||
const dom = new JSDOM(content)
|
||||
const img = dom.window.document.querySelector('#listings > div.channel-info > img')
|
||||
return img ? img.src : null
|
||||
const $ = cheerio.load(content)
|
||||
const imgSrc = $('#listings > div.channel-info > img').attr('src')
|
||||
|
||||
return imgSrc || null
|
||||
},
|
||||
parser({ content, date }) {
|
||||
let PM = false
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const title = parseTitle(item)
|
||||
let start = parseStart(item, date)
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date)
|
||||
if (!start) return
|
||||
if (start.hour() > 11) PM = true
|
||||
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||
const stop = start.add(1, 'h')
|
||||
if (programs.length) {
|
||||
programs[programs.length - 1].stop = start
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
|
||||
const stop = start.add(1, 'h')
|
||||
programs.push({
|
||||
title,
|
||||
title: parseTitle($item),
|
||||
category: parseCategory($item),
|
||||
description: parseDescription($item),
|
||||
icon: parseIcon($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
|
@ -45,20 +49,35 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
let time = (item.querySelector('a > div.content > span.time') || { textContent: '' }).textContent
|
||||
if (!time) return null
|
||||
time = `${date.format('MM/DD/YYYY')} ${time}`
|
||||
function parseStart($item, date) {
|
||||
const timeString = $item('a > div.content > span.time').text()
|
||||
if (!timeString) return null
|
||||
const dateString = `${date.format('MM/DD/YYYY')} ${timeString}`
|
||||
|
||||
return dayjs.utc(time, 'MM/DD/YYYY HH:mm')
|
||||
return dayjs.utc(dateString, 'MM/DD/YYYY HH:mm')
|
||||
}
|
||||
|
||||
function parseTitle(item) {
|
||||
return (item.querySelector('a > div.content > h2') || { textContent: '' }).textContent
|
||||
function parseTitle($item) {
|
||||
return $item('a > div.content > h2').text().trim()
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('a > div.content > span.sub-title').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('a > div.content > p.synopsis').text().trim()
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
const backgroundImage = $item('a > div.image-parent > div.image').css('background-image')
|
||||
const [_, icon] = backgroundImage.match(/url\(\'(.*)'\)/) || [null, null]
|
||||
|
||||
return icon
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const dom = new JSDOM(content)
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return dom.window.document.querySelectorAll('#listings > ul > li')
|
||||
return $('#listings > ul > li').toArray()
|
||||
}
|
||||
|
|
71
sites/mi.tv/mi.tv.test.js
Normal file
71
sites/mi.tv/mi.tv.test.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
// npx epg-grabber --config=sites/mi.tv/mi.tv.config.js --channels=sites/mi.tv/mi.tv_ar.channels.xml --output=.gh-pages/guides/ar/mi.tv.epg.xml --days=2
|
||||
|
||||
const { parser, url, logo } = require('./mi.tv.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: 'ar#24-7-canal-de-noticias',
|
||||
xmltv_id: '247CanaldeNoticias.ar'
|
||||
}
|
||||
const content = `<div id="listings"> <div class="channel-info"> <img src="https://cdn.mitvstatic.com/channels/ar_24-7-canal-de-noticias_m.png" alt="Programación 24/7 Canal de Noticias" title="24/7 Canal de Noticias" width="75" height="75"/> <h1>Programación 24/7 Canal de Noticias <span>Miércoles 24 de noviembre</span></h1> </div><ul class="broadcasts time24"> <li> <a href="/ar/programas/trasnoche-de-24-7" class="program-link"> <div class="image-parent"> <div class="image" style=" background-image: url('https://cdn.mitvstatic.com/programs/fallback_other_l_m.jpg'); " ></div></div><div class="content"> <span class="time">03:00</span> <h2>Trasnoche de 24/7</h2> <span class="sub-title">Interés general</span> <p class="synopsis">Lo más visto de la semana en nuestra pantalla.</p></div></a> </li><li class="native"> <div id="div-gpt-ad-1586617865827-0"></div></li><li> <a href="/ar/programas/noticiero-central-segunda-edicion" class="program-link"> <div class="image-parent"> <div class="image" style=" background-image: url('https://cdn.mitvstatic.com/programs/fallback_other_l_m.jpg'); " ></div></div><div class="content"> <span class="time">23:00</span> <h2>Noticiero central - Segunda edición</h2> <span class="sub-title">Noticiero</span> <p class="synopsis"> Cerramos el día con un completo resumen de los temas más relevantes con columnistas y análisis especiales para terminar el día. </p></div></a> </li><li> <a href="/ar/programas/plus-energetico" class="program-link"> <div class="image-parent"> <div class="image" style=" background-image: url('https://cdn.mitvstatic.com/programs/fallback_other_l_m.jpg'); " ></div></div><div class="content"> <span class="time">01:00</span> <h2>Plus energético</h2> <span class="sub-title">Cultural</span> <p class="synopsis"> La energía tiene mucho para mostrar. Este programa reúne a las principales empresas y protagonistas de la actividad que esta revolucionando la región. </p></div></a> </li></ul></div>`
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://mi.tv/ar/async/channel/24-7-canal-de-noticias/2021-11-24/0'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid logo url', () => {
|
||||
expect(logo({ content })).toBe(
|
||||
'https://cdn.mitvstatic.com/channels/ar_24-7-canal-de-noticias_m.png'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
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-24T03:00:00.000Z',
|
||||
stop: '2021-11-24T23:00:00.000Z',
|
||||
title: `Trasnoche de 24/7`,
|
||||
category: 'Interés general',
|
||||
description: 'Lo más visto de la semana en nuestra pantalla.',
|
||||
icon: 'https://cdn.mitvstatic.com/programs/fallback_other_l_m.jpg'
|
||||
},
|
||||
{
|
||||
start: '2021-11-24T23:00:00.000Z',
|
||||
stop: '2021-11-25T01:00:00.000Z',
|
||||
title: `Noticiero central - Segunda edición`,
|
||||
category: 'Noticiero',
|
||||
description: `Cerramos el día con un completo resumen de los temas más relevantes con columnistas y análisis especiales para terminar el día.`,
|
||||
icon: 'https://cdn.mitvstatic.com/programs/fallback_other_l_m.jpg'
|
||||
},
|
||||
{
|
||||
start: '2021-11-25T01:00:00.000Z',
|
||||
stop: '2021-11-25T02:00:00.000Z',
|
||||
title: `Plus energético`,
|
||||
category: 'Cultural',
|
||||
description: `La energía tiene mucho para mostrar. Este programa reúne a las principales empresas y protagonistas de la actividad que esta revolucionando la región.`,
|
||||
icon: 'https://cdn.mitvstatic.com/programs/fallback_other_l_m.jpg'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
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