mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -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 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 timezone = require('dayjs/plugin/timezone')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
delay: 7000,
|
|
||||||
site: 'cosmote.gr',
|
site: 'cosmote.gr',
|
||||||
url: function ({ date, channel }) {
|
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(
|
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}`
|
)}&_channelprogram_WAR_OTETVportlet_articleTitleUrl=${channel.site_id}`
|
||||||
},
|
},
|
||||||
logo: function ({ content }) {
|
logo: function ({ content }) {
|
||||||
const dom = new JSDOM(content)
|
const $ = cheerio.load(content)
|
||||||
const img = dom.window.document.querySelector('img.channel_program-banner')
|
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 }) {
|
parser: function ({ date, content }) {
|
||||||
const dom = new JSDOM(content)
|
|
||||||
const items = dom.window.document.querySelectorAll(
|
|
||||||
'#_channelprogram_WAR_OTETVportlet_programs > tr.visible-xs'
|
|
||||||
)
|
|
||||||
let programs = []
|
let programs = []
|
||||||
|
const items = parseItems(content)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = (item.querySelector('a') || { textContent: '' }).textContent
|
const prev = programs[programs.length - 1]
|
||||||
const meta = (item.querySelector('td') || { innerHTML: '' }).innerHTML
|
const $item = cheerio.load(item)
|
||||||
const startTime = (item.querySelector('.start-time') || { textContent: '' }).textContent
|
let start = parseStart($item, date)
|
||||||
const endTime = (item.querySelector('.end-time') || { textContent: '' }).textContent
|
if (prev && start.isBefore(prev.start)) {
|
||||||
const category = meta.match(/\| (.+)<br>/)[1]
|
start = start.add(1, 'd')
|
||||||
const start = dayjs
|
date = date.add(1, 'd')
|
||||||
.utc(startTime, 'HH:mm')
|
}
|
||||||
.set('D', date.get('D'))
|
let stop = parseStop($item, date)
|
||||||
.set('M', date.get('M'))
|
if (stop.isBefore(start)) {
|
||||||
.set('y', date.get('y'))
|
stop = stop.add(1, 'd')
|
||||||
const stop = dayjs
|
date = date.add(1, 'd')
|
||||||
.utc(endTime, 'HH:mm')
|
}
|
||||||
.set('D', date.get('D'))
|
|
||||||
.set('M', date.get('M'))
|
|
||||||
.set('y', date.get('y'))
|
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title,
|
title: parseTitle($item),
|
||||||
category,
|
category: parseCategory($item),
|
||||||
start,
|
start,
|
||||||
stop
|
stop
|
||||||
})
|
})
|
||||||
|
@ -55,3 +48,39 @@ module.exports = {
|
||||||
return programs
|
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