Update movistarplus.es.config.js

This commit is contained in:
Aleksandr Statciuk 2022-03-11 21:22:41 +03:00
parent ec9f8026ef
commit ce79bee196

View file

@ -3,36 +3,40 @@ var customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
module.exports = { module.exports = {
site: 'movistarplus.es', site: 'movistarplus.es',
url: function ({ date }) { ignore: true, // removes the site from the list until the test is passed
return `https://www.movistarplus.es/programacion-tv/${date.format('YYYY-MM-DD')}?v=json` url: function ({ date }) {
}, return `https://www.movistarplus.es/programacion-tv/${date.format('YYYY-MM-DD')}?v=json`
parser({ content, channel, date }) { },
let programs = [] parser({ content, channel, date }) {
let items = parseItems(content, channel) let programs = []
if (!items.length) return programs let items = parseItems(content, channel)
let guideDate = date if (!items.length) return programs
items.forEach(item => { let guideDate = date
let startTime = dayjs(`${guideDate.format('YYYY-MM-DD')} ${item.HORA_INICIO}`,"YYYY-MM-DD HH:mm") items.forEach(item => {
let stopTime = dayjs(`${guideDate.format('YYYY-MM-DD')} ${item.HORA_FIN}`,"YYYY-MM-DD HH:mm") let startTime = dayjs(
if (stopTime.isBefore(startTime)) { `${guideDate.format('YYYY-MM-DD')} ${item.HORA_INICIO}`,
guideDate = guideDate.add(1, 'd') 'YYYY-MM-DD HH:mm'
stopTime = stopTime.add(1, 'd') )
} let stopTime = dayjs(`${guideDate.format('YYYY-MM-DD')} ${item.HORA_FIN}`, 'YYYY-MM-DD HH:mm')
programs.push({ if (stopTime.isBefore(startTime)) {
title: item.TITULO, guideDate = guideDate.add(1, 'd')
category: item.GENERO, stopTime = stopTime.add(1, 'd')
start: startTime.toJSON(), }
stop: stopTime.toJSON() programs.push({
}) title: item.TITULO,
category: item.GENERO,
start: startTime.toJSON(),
stop: stopTime.toJSON()
}) })
return programs })
} return programs
} }
}
function parseItems(content, channel) { function parseItems(content, channel) {
const json = typeof content === 'string' ? JSON.parse(content) : content const json = typeof content === 'string' ? JSON.parse(content) : content
if (!(`${channel.site_id}-CODE` in json.data)) return [] if (!(`${channel.site_id}-CODE` in json.data)) return []
const data = json.data[`${channel.site_id}-CODE`] const data = json.data[`${channel.site_id}-CODE`]
return data ? data.PROGRAMAS : [] return data ? data.PROGRAMAS : []
} }