Merge pull request #2085 from iptv-org/fix-cosmote.gr

Fix cosmote.gr
This commit is contained in:
PopeyeTheSai10r authored and GitHub committed 2023-06-11 02:24:02 -07:00
commit b66b2fa300
4 files changed
+11063 -43

No files matched your search

File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+14 -17
View File
@@ -1,35 +1,32 @@
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)
const { DateTime } = require('luxon')
module.exports = {
site: 'cosmote.gr',
days: 2,
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.cosmotetv.gr/portal/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(
'DD-MM-YYYY'
)}&_channelprogram_WAR_OTETVportlet_articleTitleUrl=${channel.site_id}`
},
parser: function ({ date, content }) {
let programs = []
const items = parseItems(content)
items.forEach(item => {
items.forEach((item, i) => {
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')
if (i === 0 && start.hour > 12 && start.hour < 21) {
date = date.subtract(1, 'd')
start = start.minus({ days: 1 })
}
if (prev && start < prev.start) {
start = start.plus({ days: 1 })
date = date.add(1, 'd')
}
let stop = parseStop($item, date)
if (stop.isBefore(start)) {
stop = stop.add(1, 'd')
if (stop < start) {
stop = stop.plus({ days: 1 })
date = date.add(1, 'd')
}
programs.push({
@@ -64,18 +61,18 @@ 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')
return DateTime.fromFormat(dateString, 'yyyy-MM-dd HH:mm', { zone: 'Europe/Athens' }).toUTC()
}
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')
return DateTime.fromFormat(dateString, 'yyyy-MM-dd HH:mm', { zone: 'Europe/Athens' }).toUTC()
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('#_channelprogram_WAR_OTETVportlet_programs > tr.visible-xs').toArray()
return $('#_channelprogram_WAR_OTETVportlet_programs > tr.d-sm-table-row').toArray()
}
+43 -26
View File
@@ -1,6 +1,8 @@
// npx epg-grabber --config=sites/cosmote.gr/cosmote.gr.config.js --channels=sites/cosmote.gr/cosmote.gr.channels.xml --output=guide.xml --days=2
// npx epg-grabber --config=sites/cosmote.gr/cosmote.gr.config.js --channels=sites/cosmote.gr/cosmote.gr.channels.xml --output=guide.xml
const { parser, url } = require('./cosmote.gr.config.js')
const fs = require('fs')
const path = require('path')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
@@ -10,52 +12,67 @@ dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
const date = dayjs.utc('2021-11-25', 'YYYY-MM-DD').startOf('d')
const date = dayjs.utc('2023-06-08', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '4e',
xmltv_id: '4E.gr'
}
const content = `<!DOCTYPE html><html class="aui ltr" dir="ltr" lang="el-GR"> <head></head> <body> <div id="page-wrap"> <section id="main-content" class="container-fluid homepage-layout" role="main"> <div class="row-fluid no-space"> <div class="portlet-column portlet-column-only col-xs-12" id="column-5"> <div class="portlet-dropzone portlet-column-content portlet-column-content-only" id="layout-column_column-5" > <div class=" portlet-boundary portlet-boundary_channelprogram_WAR_OTETVportlet_ portlet-static portlet-static-end channel-program-portlet " id="p_p_id_channelprogram_WAR_OTETVportlet_" > <section class="portlet" id="portlet_channelprogram_WAR_OTETVportlet"> <div class="portlet-content"> <div class="portlet-content-container"> <div class="portlet-body"> <section class="channel_program"> <div class="tabbable"> <div class="tab-content limiter"> <div class="tab-pane fade active in" id="broadband"> <div class="row"> <div class="col-sm-2"> <img class="channel_program-banner" alt="4Ε" title="4Ε" src="/portal/image/journal/article?img_id=56014332&t=1544180299920"/> </div><div class="col-sm-10"> <table class="channel_program-table table"> <tbody id="_channelprogram_WAR_OTETVportlet_programs"> <tr class="hidden-xs"> <td class="channel_program-table--program"> <a href="https://www.cosmote.gr/cosmotetv/residential/program/epg/closeupepg?p_p_id=epgcloseup_WAR_OTETVportlet&p_p_lifecycle=0&p_p_col_id=column-5&p_p_col_count=1&_epgcloseup_WAR_OTETVportlet_articleId=119045589&_epgcloseup_WAR_OTETVportlet_redirect=https%253A%252F%252Fwww.cosmote.gr%252Fportal%252Fresidential%252Fprogram%252Fepg%252Fprogramchannel" >Μαθαίνω να Είμαι Γονιός</a >&nbsp; </td><td class=" channel_program-table--time channel_program-table--program_type " > <span class="start-time">01:15</span> - <span class="end-time">01:50</span> (<span class="duration" >35'</span >) | Ντοκιμαντέρ </td></tr><tr class="visible-xs"> <td class=" channel_program-table--program channel_program-table--time channel_program-table--program_type " colspan="2" > <span class="start-time">01:15</span> - <span class="end-time">01:50</span> (<span class="duration" >35'</span >) | Ντοκιμαντέρ<br/> <a href="https://www.cosmote.gr/cosmotetv/residential/program/epg/closeupepg?p_p_id=epgcloseup_WAR_OTETVportlet&p_p_lifecycle=0&p_p_col_id=column-5&p_p_col_count=1&_epgcloseup_WAR_OTETVportlet_articleId=119045589&_epgcloseup_WAR_OTETVportlet_redirect=https%253A%252F%252Fwww.cosmote.gr%252Fportal%252Fresidential%252Fprogram%252Fepg%252Fprogramchannel" >Μαθαίνω να Είμαι Γονιός</a >&nbsp; </td></tr><tr class="hidden"></tr><tr class="hidden-xs"> <td class="channel_program-table--program"> <a href="https://www.cosmote.gr/cosmotetv/residential/program/epg/closeupepg?p_p_id=epgcloseup_WAR_OTETVportlet&p_p_lifecycle=0&p_p_col_id=column-5&p_p_col_count=1&_epgcloseup_WAR_OTETVportlet_articleId=119045942&_epgcloseup_WAR_OTETVportlet_redirect=https%253A%252F%252Fwww.cosmote.gr%252Fportal%252Fresidential%252Fprogram%252Fepg%252Fprogramchannel" >Μικρό Απόδειπνο</a >&nbsp; </td><td class=" channel_program-table--time channel_program-table--program_type " > <span class="start-time">23:00</span> - <span class="end-time">23:45</span> (<span class="duration" >45'</span >) | Special </td></tr><tr class="visible-xs"> <td class=" channel_program-table--program channel_program-table--time channel_program-table--program_type " colspan="2" > <span class="start-time">23:00</span> - <span class="end-time">23:45</span> (<span class="duration" >45'</span >) | Special<br/> <a href="https://www.cosmote.gr/cosmotetv/residential/program/epg/closeupepg?p_p_id=epgcloseup_WAR_OTETVportlet&p_p_lifecycle=0&p_p_col_id=column-5&p_p_col_count=1&_epgcloseup_WAR_OTETVportlet_articleId=119045942&_epgcloseup_WAR_OTETVportlet_redirect=https%253A%252F%252Fwww.cosmote.gr%252Fportal%252Fresidential%252Fprogram%252Fepg%252Fprogramchannel" >Μικρό Απόδειπνο</a >&nbsp; </td></tr><tr class="hidden"></tr><tr class="hidden-xs"> <td class="channel_program-table--program"> <a href="https://www.cosmote.gr/cosmotetv/residential/program/epg/closeupepg?p_p_id=epgcloseup_WAR_OTETVportlet&p_p_lifecycle=0&p_p_col_id=column-5&p_p_col_count=1&_epgcloseup_WAR_OTETVportlet_articleId=119045955&_epgcloseup_WAR_OTETVportlet_redirect=https%253A%252F%252Fwww.cosmote.gr%252Fportal%252Fresidential%252Fprogram%252Fepg%252Fprogramchannel" >Πανηγυρική Αρχιερατική Θεία Λειτουργία</a >&nbsp; </td><td class=" channel_program-table--time channel_program-table--program_type " > <span class="start-time">23:45</span> - <span class="end-time">03:00</span> (<span class="duration" >195'</span >) | Special </td></tr><tr class="visible-xs"> <td class=" channel_program-table--program channel_program-table--time channel_program-table--program_type " colspan="2" > <span class="start-time">23:45</span> - <span class="end-time">03:00</span> (<span Line truncated
it('can generate valid url', () => {
expect(url({ channel, date })).toBe(
'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=25-11-2021&_channelprogram_WAR_OTETVportlet_articleTitleUrl=4e'
'https://www.cosmotetv.gr/portal/residential/program/epg/programchannel?p_p_id=channelprogram_WAR_OTETVportlet&p_p_lifecycle=0&_channelprogram_WAR_OTETVportlet_platform=IPTV&_channelprogram_WAR_OTETVportlet_date=08-06-2023&_channelprogram_WAR_OTETVportlet_articleTitleUrl=4e'
)
})
it('can parse response', () => {
const result = parser({ content, channel, date }).map(p => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content1.html'))
const results = parser({ content, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2021-11-24T23:15:00.000Z',
stop: '2021-11-24T23:50:00.000Z',
title: `Μαθαίνω να Είμαι Γονιός`,
category: 'Ντοκιμαντέρ'
},
{
start: '2021-11-25T21:00:00.000Z',
stop: '2021-11-25T21:45:00.000Z',
title: `Μικρό Απόδειπνο`,
category: 'Special'
},
{
start: '2021-11-25T21:45:00.000Z',
stop: '2021-11-26T01:00:00.000Z',
title: `Πανηγυρική Αρχιερατική Θεία Λειτουργία`,
category: 'Special'
}
])
expect(results[0]).toMatchObject({
start: '2023-06-07T20:30:00.000Z',
stop: '2023-06-07T21:45:00.000Z',
title: `Τηλεφημερίδα`,
category: 'Εκπομπή - Μαγκαζίνο'
})
expect(results[30]).toMatchObject({
start: '2023-06-08T19:45:00.000Z',
stop: '2023-06-08T20:30:00.000Z',
title: `Μικρό Απόδειπνο`,
category: 'Special'
})
})
it('can parse response when the guide starting before midnight', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content2.html'))
const results = parser({ content, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2023-06-07T21:30:00.000Z',
stop: '2023-06-07T22:30:00.000Z',
title: `Καλύτερα Αργά`,
category: 'Ψυχαγωγική Εκπομπή'
})
expect(results[22]).toMatchObject({
start: '2023-06-08T19:00:00.000Z',
stop: '2023-06-08T21:30:00.000Z',
title: `Πίσω Από Τις Γραμμές`,
category: 'Εκπομπή - Μαγκαζίνο'
})
})
it('can handle empty guide', () => {
const result = parser({
date,
channel,
content: `<!DOCTYPE html><html><head></head><body></body></html>`
})
expect(result).toMatchObject([])