mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update cosmote.gr.config.js
This commit is contained in:
parent
2d9431bd0b
commit
9e8bbfbae4
1 changed files with 57 additions and 28 deletions
|
@ -1,14 +1,14 @@
|
|||
const jsdom = require('jsdom')
|
||||
const { JSDOM } = jsdom
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
delay: 7000,
|
||||
site: 'cosmote.gr',
|
||||
url: function ({ date, channel }) {
|
||||
return `https://www.cosmote.gr/cosmotetv/residential/program/epg/programchannel?p_p_id=channelprogram_WAR_OTETVportlet&p_p_lifecycle=0&_channelprogram_WAR_OTETVportlet_platform=IPTV&_channelprogram_WAR_OTETVportlet_date=${date.format(
|
||||
|
@ -16,37 +16,30 @@ module.exports = {
|
|||
)}&_channelprogram_WAR_OTETVportlet_articleTitleUrl=${channel.site_id}`
|
||||
},
|
||||
logo: function ({ content }) {
|
||||
const dom = new JSDOM(content)
|
||||
const img = dom.window.document.querySelector('img.channel_program-banner')
|
||||
const $ = cheerio.load(content)
|
||||
const imgSrc = $('img.channel_program-banner').attr('src')
|
||||
|
||||
return img ? 'https://www.cosmote.gr' + img.src : null
|
||||
return imgSrc ? `https://www.cosmote.gr${imgSrc}` : null
|
||||
},
|
||||
parser: function ({ date, content }) {
|
||||
const dom = new JSDOM(content)
|
||||
const items = dom.window.document.querySelectorAll(
|
||||
'#_channelprogram_WAR_OTETVportlet_programs > tr.visible-xs'
|
||||
)
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const title = (item.querySelector('a') || { textContent: '' }).textContent
|
||||
const meta = (item.querySelector('td') || { innerHTML: '' }).innerHTML
|
||||
const startTime = (item.querySelector('.start-time') || { textContent: '' }).textContent
|
||||
const endTime = (item.querySelector('.end-time') || { textContent: '' }).textContent
|
||||
const category = meta.match(/\| (.+)<br>/)[1]
|
||||
const start = dayjs
|
||||
.utc(startTime, 'HH:mm')
|
||||
.set('D', date.get('D'))
|
||||
.set('M', date.get('M'))
|
||||
.set('y', date.get('y'))
|
||||
const stop = dayjs
|
||||
.utc(endTime, 'HH:mm')
|
||||
.set('D', date.get('D'))
|
||||
.set('M', date.get('M'))
|
||||
.set('y', date.get('y'))
|
||||
|
||||
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,
|
||||
category,
|
||||
title: parseTitle($item),
|
||||
category: parseCategory($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
|
@ -55,3 +48,39 @@ module.exports = {
|
|||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.channel_program-table--program > a').text()
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
const typeString = $item('.channel_program-table--program_type')
|
||||
.children()
|
||||
.remove()
|
||||
.end()
|
||||
.text()
|
||||
.trim()
|
||||
const [_, category] = typeString.match(/\| (.*)/) || [null, null]
|
||||
|
||||
return category
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const timeString = $item('span.start-time').text()
|
||||
const dateString = `${date.format('YYYY-MM-DD')} ${timeString}`
|
||||
|
||||
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Europe/Athens')
|
||||
}
|
||||
|
||||
function parseStop($item, date) {
|
||||
const timeString = $item('span.end-time').text()
|
||||
const dateString = `${date.format('YYYY-MM-DD')} ${timeString}`
|
||||
|
||||
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Europe/Athens')
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('#_channelprogram_WAR_OTETVportlet_programs > tr.visible-xs').toArray()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue