mirror of
https://github.com/iptv-org/epg
synced 2026-05-09 10:57:03 -04:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,97 +1,97 @@
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
module.exports = {
|
||||
site: 'movistarplus.es',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
return `https://www.movistarplus.es/programacion-tv/${channel.site_id}/${date.format('YYYY-MM-DD')}`
|
||||
},
|
||||
async parser({ content }) {
|
||||
let programs = []
|
||||
let items = parseItems(content)
|
||||
if (!items.length) return programs
|
||||
|
||||
const $ = cheerio.load(content)
|
||||
const programElements = $('div[id^="ele-"]').get()
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const el = items[i]
|
||||
let description = null
|
||||
|
||||
if (programElements[i]) {
|
||||
const programDiv = $(programElements[i])
|
||||
const programLink = programDiv.find('a').attr('href')
|
||||
|
||||
if (programLink) {
|
||||
const idMatch = programLink.match(/id=(\d+)/)
|
||||
if (idMatch && idMatch[1]) {
|
||||
description = await getProgramDescription(programLink).catch(() => null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title: el.item.name,
|
||||
description: description,
|
||||
start: dayjs(el.item.startDate),
|
||||
stop: dayjs(el.item.endDate)
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const html = await axios
|
||||
.get('https://www.movistarplus.es/programacion-tv')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(html)
|
||||
let scheme = $('script:contains(ItemList)').html()
|
||||
scheme = JSON.parse(scheme)
|
||||
|
||||
return scheme.itemListElement.map(el => {
|
||||
const urlParts = el.item.url.split('/')
|
||||
const site_id = urlParts.pop().toLowerCase()
|
||||
|
||||
return {
|
||||
lang: 'es',
|
||||
name: el.item.name,
|
||||
site_id
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
try {
|
||||
const $ = cheerio.load(content)
|
||||
let scheme = $('script:contains("@type": "ItemList")').html()
|
||||
scheme = JSON.parse(scheme)
|
||||
if (!scheme || !Array.isArray(scheme.itemListElement)) return []
|
||||
|
||||
return scheme.itemListElement
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
async function getProgramDescription(programUrl) {
|
||||
try {
|
||||
const response = await axios.get(programUrl, {
|
||||
headers: {
|
||||
'Referer': 'https://www.movistarplus.es/programacion-tv/'
|
||||
}
|
||||
})
|
||||
|
||||
const $ = cheerio.load(response.data)
|
||||
const description = $('.show-content .text p').first().text().trim() || null
|
||||
|
||||
return description
|
||||
} catch (error) {
|
||||
console.error(`Error fetching description from ${programUrl}:`, error.message)
|
||||
return null
|
||||
}
|
||||
}
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
module.exports = {
|
||||
site: 'movistarplus.es',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
return `https://www.movistarplus.es/programacion-tv/${channel.site_id}/${date.format('YYYY-MM-DD')}`
|
||||
},
|
||||
async parser({ content }) {
|
||||
let programs = []
|
||||
let items = parseItems(content)
|
||||
if (!items.length) return programs
|
||||
|
||||
const $ = cheerio.load(content)
|
||||
const programElements = $('div[id^="ele-"]').get()
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const el = items[i]
|
||||
let description = null
|
||||
|
||||
if (programElements[i]) {
|
||||
const programDiv = $(programElements[i])
|
||||
const programLink = programDiv.find('a').attr('href')
|
||||
|
||||
if (programLink) {
|
||||
const idMatch = programLink.match(/id=(\d+)/)
|
||||
if (idMatch && idMatch[1]) {
|
||||
description = await getProgramDescription(programLink).catch(() => null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title: el.item.name,
|
||||
description: description,
|
||||
start: dayjs(el.item.startDate),
|
||||
stop: dayjs(el.item.endDate)
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const html = await axios
|
||||
.get('https://www.movistarplus.es/programacion-tv')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(html)
|
||||
let scheme = $('script:contains(ItemList)').html()
|
||||
scheme = JSON.parse(scheme)
|
||||
|
||||
return scheme.itemListElement.map(el => {
|
||||
const urlParts = el.item.url.split('/')
|
||||
const site_id = urlParts.pop().toLowerCase()
|
||||
|
||||
return {
|
||||
lang: 'es',
|
||||
name: el.item.name,
|
||||
site_id
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
try {
|
||||
const $ = cheerio.load(content)
|
||||
let scheme = $('script:contains("@type": "ItemList")').html()
|
||||
scheme = JSON.parse(scheme)
|
||||
if (!scheme || !Array.isArray(scheme.itemListElement)) return []
|
||||
|
||||
return scheme.itemListElement
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
async function getProgramDescription(programUrl) {
|
||||
try {
|
||||
const response = await axios.get(programUrl, {
|
||||
headers: {
|
||||
'Referer': 'https://www.movistarplus.es/programacion-tv/'
|
||||
}
|
||||
})
|
||||
|
||||
const $ = cheerio.load(response.data)
|
||||
const description = $('.show-content .text p').first().text().trim() || null
|
||||
|
||||
return description
|
||||
} catch (error) {
|
||||
console.error(`Error fetching description from ${programUrl}:`, error.message)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
const { parser, url } = require('./movistarplus.es.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
const axios = require('axios')
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2025-05-30', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'sexta',
|
||||
xmltv_id: 'LaSexta.es'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.movistarplus.es/programacion-tv/sexta/2025-05-30'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (
|
||||
url ===
|
||||
'https://www.movistarplus.es/entretenimiento/venta-prime-t1/ficha?tipo=E&id=3414523'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/program1.html'))
|
||||
})
|
||||
} else if (
|
||||
url ===
|
||||
'https://www.movistarplus.es/deportes/programa/pokerstars-casino-1/ficha?tipo=E&id=2057641'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/program2.html'))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(23)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-05-30T03:15:00.000Z',
|
||||
stop: '2025-05-30T04:25:00.000Z',
|
||||
title: 'Venta Prime',
|
||||
description:
|
||||
'Espacio de televenta.'
|
||||
})
|
||||
expect(results[19]).toMatchObject({
|
||||
start: '2025-05-31T00:45:00.000Z',
|
||||
stop: '2025-05-31T01:25:00.000Z',
|
||||
title: 'Pokerstars casino',
|
||||
description:
|
||||
'El programa trae cada día toda la emoción de su ruleta en vivo, Spin & Win, una versión exclusiva del clásico juego de casino.'
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
const results = await parser({
|
||||
date,
|
||||
channel,
|
||||
content: '[]'
|
||||
})
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./movistarplus.es.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
const axios = require('axios')
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2025-05-30', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'sexta',
|
||||
xmltv_id: 'LaSexta.es'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.movistarplus.es/programacion-tv/sexta/2025-05-30'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (
|
||||
url ===
|
||||
'https://www.movistarplus.es/entretenimiento/venta-prime-t1/ficha?tipo=E&id=3414523'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/program1.html'))
|
||||
})
|
||||
} else if (
|
||||
url ===
|
||||
'https://www.movistarplus.es/deportes/programa/pokerstars-casino-1/ficha?tipo=E&id=2057641'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/program2.html'))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(23)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-05-30T03:15:00.000Z',
|
||||
stop: '2025-05-30T04:25:00.000Z',
|
||||
title: 'Venta Prime',
|
||||
description:
|
||||
'Espacio de televenta.'
|
||||
})
|
||||
expect(results[19]).toMatchObject({
|
||||
start: '2025-05-31T00:45:00.000Z',
|
||||
stop: '2025-05-31T01:25:00.000Z',
|
||||
title: 'Pokerstars casino',
|
||||
description:
|
||||
'El programa trae cada día toda la emoción de su ruleta en vivo, Spin & Win, una versión exclusiva del clásico juego de casino.'
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
const results = await parser({
|
||||
date,
|
||||
channel,
|
||||
content: '[]'
|
||||
})
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user