mirror of
https://github.com/iptv-org/epg
synced 2026-05-03 07:56:58 -04:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,89 +1,89 @@
|
||||
const cheerio = require('cheerio')
|
||||
const { DateTime } = require('luxon')
|
||||
|
||||
module.exports = {
|
||||
site: 'tivu.tv',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ date }) {
|
||||
const diff = date.diff(DateTime.now().toUTC().startOf('day'), 'd')
|
||||
|
||||
return `https://www.tivu.tv/epg_ajax_sat.aspx?d=${diff}`
|
||||
},
|
||||
parser: function ({ content, channel, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel, date)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart($item, date)
|
||||
if (!start) return
|
||||
if (prev) {
|
||||
if (start < prev.start) {
|
||||
start = start.plus({ days: 1 })
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.plus({ minutes: 30 })
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const html = await axios
|
||||
.get('https://www.tivu.tv/epg_ajax_sat.aspx?d=0')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
let channels = []
|
||||
|
||||
const $ = cheerio.load(html)
|
||||
$('.q').each((i, el) => {
|
||||
const site_id = $(el).attr('id')
|
||||
const name = $(el).find('a').first().data('channel')
|
||||
|
||||
if (!name) return
|
||||
|
||||
channels.push({
|
||||
lang: 'it',
|
||||
site_id,
|
||||
name
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
const [title] = $item('a').html().split('<br>')
|
||||
|
||||
return title
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const [, , time] = $item('a').html().split('<br>')
|
||||
if (!time) return null
|
||||
|
||||
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
|
||||
zone: 'Europe/Rome'
|
||||
}).toUTC()
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
if (!content) return []
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $(`.q[id="${channel.site_id}"] > .p`).toArray()
|
||||
}
|
||||
const cheerio = require('cheerio')
|
||||
const { DateTime } = require('luxon')
|
||||
|
||||
module.exports = {
|
||||
site: 'tivu.tv',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ date }) {
|
||||
const diff = date.diff(DateTime.now().toUTC().startOf('day'), 'd')
|
||||
|
||||
return `https://www.tivu.tv/epg_ajax_sat.aspx?d=${diff}`
|
||||
},
|
||||
parser: function ({ content, channel, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel, date)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart($item, date)
|
||||
if (!start) return
|
||||
if (prev) {
|
||||
if (start < prev.start) {
|
||||
start = start.plus({ days: 1 })
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.plus({ minutes: 30 })
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const html = await axios
|
||||
.get('https://www.tivu.tv/epg_ajax_sat.aspx?d=0')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
let channels = []
|
||||
|
||||
const $ = cheerio.load(html)
|
||||
$('.q').each((i, el) => {
|
||||
const site_id = $(el).attr('id')
|
||||
const name = $(el).find('a').first().data('channel')
|
||||
|
||||
if (!name) return
|
||||
|
||||
channels.push({
|
||||
lang: 'it',
|
||||
site_id,
|
||||
name
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
const [title] = $item('a').html().split('<br>')
|
||||
|
||||
return title
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const [, , time] = $item('a').html().split('<br>')
|
||||
if (!time) return null
|
||||
|
||||
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
|
||||
zone: 'Europe/Rome'
|
||||
}).toUTC()
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
if (!content) return []
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $(`.q[id="${channel.site_id}"] > .p`).toArray()
|
||||
}
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
const { parser, url } = require('./tivu.tv.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)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const channel = {
|
||||
site_id: '62',
|
||||
xmltv_id: 'Rai1HD.it'
|
||||
}
|
||||
|
||||
it('can generate valid url for today', () => {
|
||||
const date = dayjs.utc().startOf('d')
|
||||
expect(url({ date })).toBe('https://www.tivu.tv/epg_ajax_sat.aspx?d=0')
|
||||
})
|
||||
|
||||
it('can generate valid url for tomorrow', () => {
|
||||
const date = dayjs.utc().startOf('d').add(1, 'd')
|
||||
expect(url({ date })).toBe('https://www.tivu.tv/epg_ajax_sat.aspx?d=1')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const date = dayjs.utc('2022-10-04', 'YYYY-MM-DD').startOf('d')
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
|
||||
let results = parser({ content, channel, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-10-03T22:02:00.000Z',
|
||||
stop: '2022-10-03T22:45:00.000Z',
|
||||
title: 'Cose Nostre - La figlia del boss'
|
||||
})
|
||||
|
||||
expect(results[43]).toMatchObject({
|
||||
start: '2022-10-05T04:58:00.000Z',
|
||||
stop: '2022-10-05T05:28:00.000Z',
|
||||
title: 'Tgunomattina - in collaborazione con day'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const date = dayjs.utc('2022-10-04', 'YYYY-MM-DD').startOf('d')
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const result = parser({ content, channel, date })
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./tivu.tv.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)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const channel = {
|
||||
site_id: '62',
|
||||
xmltv_id: 'Rai1HD.it'
|
||||
}
|
||||
|
||||
it('can generate valid url for today', () => {
|
||||
const date = dayjs.utc().startOf('d')
|
||||
expect(url({ date })).toBe('https://www.tivu.tv/epg_ajax_sat.aspx?d=0')
|
||||
})
|
||||
|
||||
it('can generate valid url for tomorrow', () => {
|
||||
const date = dayjs.utc().startOf('d').add(1, 'd')
|
||||
expect(url({ date })).toBe('https://www.tivu.tv/epg_ajax_sat.aspx?d=1')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const date = dayjs.utc('2022-10-04', 'YYYY-MM-DD').startOf('d')
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
|
||||
let results = parser({ content, channel, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-10-03T22:02:00.000Z',
|
||||
stop: '2022-10-03T22:45:00.000Z',
|
||||
title: 'Cose Nostre - La figlia del boss'
|
||||
})
|
||||
|
||||
expect(results[43]).toMatchObject({
|
||||
start: '2022-10-05T04:58:00.000Z',
|
||||
stop: '2022-10-05T05:28:00.000Z',
|
||||
title: 'Tgunomattina - in collaborazione con day'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const date = dayjs.utc('2022-10-04', 'YYYY-MM-DD').startOf('d')
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const result = parser({ content, channel, date })
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user