mirror of
https://github.com/iptv-org/epg
synced 2026-09-10 05:46:54 -04:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,81 +1,81 @@
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
module.exports = {
|
||||
site: 'tv-spored.siol.net',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
return `https://tv-spored.siol.net/kanal/${channel.site_id}/datum/${date.format('YYYYMMDD')}`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
Accept: 'text/html'
|
||||
}
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const items = parseItems(content, date)
|
||||
|
||||
return items.map(item => ({
|
||||
title: item.title,
|
||||
category: item.category,
|
||||
season: item.season,
|
||||
episode: item.episode,
|
||||
start: item.startDateTime,
|
||||
stop: item.stopDateTime
|
||||
}))
|
||||
},
|
||||
async channels() {
|
||||
const content = await axios
|
||||
.get('https://tv-spored.siol.net/', {
|
||||
headers: {
|
||||
Accept: 'text/html'
|
||||
}
|
||||
})
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(content)
|
||||
const script = $('script:contains(tvChannelsAsJson)').text()
|
||||
const func = new Function(`const self = { __next_f: [] };${script};return self.__next_f`)
|
||||
const __next_f = func()
|
||||
if (!__next_f[0] || !__next_f[0][1]) return []
|
||||
const [, dataString] = __next_f[0][1].split(/:(.*)/s)
|
||||
const data = JSON.parse(dataString)
|
||||
const tvChannelsAsJson = findByKey(data, 'tvChannelsAsJson')
|
||||
|
||||
return tvChannelsAsJson.map(item => ({
|
||||
name: item.name,
|
||||
site_id: item.externalId.toLowerCase(),
|
||||
lang: 'sl'
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
try {
|
||||
const $ = cheerio.load(content)
|
||||
const script = $('script:contains(channelsAsJson)').text()
|
||||
const func = new Function(`const self = { __next_f: [] };${script};return self.__next_f`)
|
||||
const __next_f = func()
|
||||
if (!__next_f[0] || !__next_f[0][1]) return []
|
||||
const [, dataString] = __next_f[0][1].split(/:(.*)/s)
|
||||
const data = JSON.parse(dataString)
|
||||
const channelsAsJson = findByKey(data, 'channelsAsJson')
|
||||
|
||||
if (!channelsAsJson[0] || !Array.isArray(channelsAsJson[0].events)) return []
|
||||
|
||||
return channelsAsJson[0].events.filter(p => date.isSame(p.startDateTime, 'day'))
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
function findByKey(arr, key) {
|
||||
if (!Array.isArray(arr)) return
|
||||
return arr.reduce((a, item) => {
|
||||
if (a) return a
|
||||
if (item && item[key]) return item[key]
|
||||
if (item && item.children) return findByKey(item.children, key)
|
||||
if (Array.isArray(item)) return findByKey(item, key)
|
||||
}, null)
|
||||
}
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
module.exports = {
|
||||
site: 'tv-spored.siol.net',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
return `https://tv-spored.siol.net/kanal/${channel.site_id}/datum/${date.format('YYYYMMDD')}`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
Accept: 'text/html'
|
||||
}
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const items = parseItems(content, date)
|
||||
|
||||
return items.map(item => ({
|
||||
title: item.title,
|
||||
category: item.category,
|
||||
season: item.season,
|
||||
episode: item.episode,
|
||||
start: item.startDateTime,
|
||||
stop: item.stopDateTime
|
||||
}))
|
||||
},
|
||||
async channels() {
|
||||
const content = await axios
|
||||
.get('https://tv-spored.siol.net/', {
|
||||
headers: {
|
||||
Accept: 'text/html'
|
||||
}
|
||||
})
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(content)
|
||||
const script = $('script:contains(tvChannelsAsJson)').text()
|
||||
const func = new Function(`const self = { __next_f: [] };${script};return self.__next_f`)
|
||||
const __next_f = func()
|
||||
if (!__next_f[0] || !__next_f[0][1]) return []
|
||||
const [, dataString] = __next_f[0][1].split(/:(.*)/s)
|
||||
const data = JSON.parse(dataString)
|
||||
const tvChannelsAsJson = findByKey(data, 'tvChannelsAsJson')
|
||||
|
||||
return tvChannelsAsJson.map(item => ({
|
||||
name: item.name,
|
||||
site_id: item.externalId.toLowerCase(),
|
||||
lang: 'sl'
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
try {
|
||||
const $ = cheerio.load(content)
|
||||
const script = $('script:contains(channelsAsJson)').text()
|
||||
const func = new Function(`const self = { __next_f: [] };${script};return self.__next_f`)
|
||||
const __next_f = func()
|
||||
if (!__next_f[0] || !__next_f[0][1]) return []
|
||||
const [, dataString] = __next_f[0][1].split(/:(.*)/s)
|
||||
const data = JSON.parse(dataString)
|
||||
const channelsAsJson = findByKey(data, 'channelsAsJson')
|
||||
|
||||
if (!channelsAsJson[0] || !Array.isArray(channelsAsJson[0].events)) return []
|
||||
|
||||
return channelsAsJson[0].events.filter(p => date.isSame(p.startDateTime, 'day'))
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
function findByKey(arr, key) {
|
||||
if (!Array.isArray(arr)) return
|
||||
return arr.reduce((a, item) => {
|
||||
if (a) return a
|
||||
if (item && item[key]) return item[key]
|
||||
if (item && item.children) return findByKey(item.children, key)
|
||||
if (Array.isArray(item)) return findByKey(item, key)
|
||||
}, null)
|
||||
}
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
const { parser, url, request } = require('./tv-spored.siol.net.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 date = dayjs.utc('2025-01-15', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'exodustv',
|
||||
xmltv_id: 'ExodusTV.si'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe('https://tv-spored.siol.net/kanal/exodustv/datum/20250115')
|
||||
})
|
||||
|
||||
it('can generate request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
Accept: 'text/html'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date })
|
||||
|
||||
expect(results.length).toBe(41)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-01-15T00:00:00.000Z',
|
||||
stop: '2025-01-15T00:30:00.000Z',
|
||||
title: 'Novice iz Svete dežele',
|
||||
category: 'informativni',
|
||||
season: null,
|
||||
episode: null
|
||||
})
|
||||
|
||||
expect(results[40]).toMatchObject({
|
||||
start: '2025-01-15T23:00:00.000Z',
|
||||
stop: '2025-01-15T23:45:00.000Z',
|
||||
title: 'Sveta maša',
|
||||
category: 'ostalo',
|
||||
season: null,
|
||||
episode: null
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
content: '<!DOCTYPE html><html><head></head><body></body></html>'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
const { parser, url, request } = require('./tv-spored.siol.net.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 date = dayjs.utc('2025-01-15', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'exodustv',
|
||||
xmltv_id: 'ExodusTV.si'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe('https://tv-spored.siol.net/kanal/exodustv/datum/20250115')
|
||||
})
|
||||
|
||||
it('can generate request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
Accept: 'text/html'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date })
|
||||
|
||||
expect(results.length).toBe(41)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-01-15T00:00:00.000Z',
|
||||
stop: '2025-01-15T00:30:00.000Z',
|
||||
title: 'Novice iz Svete dežele',
|
||||
category: 'informativni',
|
||||
season: null,
|
||||
episode: null
|
||||
})
|
||||
|
||||
expect(results[40]).toMatchObject({
|
||||
start: '2025-01-15T23:00:00.000Z',
|
||||
stop: '2025-01-15T23:45:00.000Z',
|
||||
title: 'Sveta maša',
|
||||
category: 'ostalo',
|
||||
season: null,
|
||||
episode: null
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
content: '<!DOCTYPE html><html><head></head><body></body></html>'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user