mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 17:40:07 -04:00
commit
9bdec66480
6 changed files with 36 additions and 25 deletions
File diff suppressed because one or more lines are too long
1
sites/ruv.is/__data__/content.json
Normal file
1
sites/ruv.is/__data__/content.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
sites/ruv.is/__data__/no_content.json
Normal file
1
sites/ruv.is/__data__/no_content.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"data":{"Schedule":{"events":null,"__typename":"Schedule"}}}
|
|
@ -12,11 +12,27 @@ module.exports = {
|
||||||
site: 'ruv.is',
|
site: 'ruv.is',
|
||||||
days: 2,
|
days: 2,
|
||||||
url({ channel, date }) {
|
url({ channel, date }) {
|
||||||
return `https://www.ruv.is/sjonvarp/dagskra/${channel.site_id}/${date.format('YYYY-MM-DD')}`
|
let params = new URLSearchParams()
|
||||||
|
params.append('operationName', 'getSchedule')
|
||||||
|
params.append(
|
||||||
|
'variables',
|
||||||
|
JSON.stringify({ channel: channel.site_id, date: date.format('YYYY-MM-DD') })
|
||||||
|
)
|
||||||
|
params.append(
|
||||||
|
'extensions',
|
||||||
|
JSON.stringify({
|
||||||
|
persistedQuery: {
|
||||||
|
version: 1,
|
||||||
|
sha256Hash: '7d133b9bd9e50127e90f2b3af1b41eb5e89cd386ed9b100b55169f395af350e6'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
return `https://www.ruv.is/gql/?${params.toString()}`
|
||||||
},
|
},
|
||||||
parser({ content, channel, date }) {
|
parser({ content, date }) {
|
||||||
let programs = []
|
let programs = []
|
||||||
const items = parseItems(content, channel, date)
|
const items = parseItems(content, date)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
let start = parseStart(item, date)
|
let start = parseStart(item, date)
|
||||||
let stop = parseStop(item, date)
|
let stop = parseStop(item, date)
|
||||||
|
@ -57,14 +73,8 @@ function parseStop(item, date) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, channel, date) {
|
function parseItems(content, channel, date) {
|
||||||
const $ = cheerio.load(content)
|
const data = JSON.parse(content)
|
||||||
const apollo = $('#apollo').html()
|
if (!data || !Array.isArray(data.data.Schedule.events)) return []
|
||||||
const [, state] = apollo.match(/window.__APOLLO_STATE__ = ([^;<]+)/) || [null, '']
|
|
||||||
const data = JSON.parse(state)
|
|
||||||
|
|
||||||
return (
|
return data.data.Schedule.events
|
||||||
data?.ROOT_QUERY?.[
|
|
||||||
`Schedule({"channel":"${channel.site_id}","date":"${date.format('YYYY-MM-DD')}"})`
|
|
||||||
]?.events || []
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,39 +9,40 @@ const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|
||||||
const date = dayjs.utc('2022-12-03', 'YYYY-MM-DD').startOf('d')
|
const date = dayjs.utc('2023-01-17', 'YYYY-MM-DD').startOf('d')
|
||||||
const channel = {
|
const channel = {
|
||||||
site_id: 'ruv',
|
site_id: 'ruv',
|
||||||
xmltv_id: 'RUV.is'
|
xmltv_id: 'RUV.is'
|
||||||
}
|
}
|
||||||
|
|
||||||
it('can generate valid url', () => {
|
it('can generate valid url', () => {
|
||||||
expect(url({ channel, date })).toBe('https://www.ruv.is/sjonvarp/dagskra/ruv/2022-12-03')
|
expect(url({ channel, date })).toBe(
|
||||||
|
'https://www.ruv.is/gql/?operationName=getSchedule&variables=%7B%22channel%22%3A%22ruv%22%2C%22date%22%3A%222023-01-17%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%227d133b9bd9e50127e90f2b3af1b41eb5e89cd386ed9b100b55169f395af350e6%22%7D%7D'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', () => {
|
||||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||||
let results = parser({ content, channel, date }).map(p => {
|
let results = parser({ content, date }).map(p => {
|
||||||
p.start = p.start.toJSON()
|
p.start = p.start.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
return p
|
return p
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(results[0]).toMatchObject({
|
expect(results[0]).toMatchObject({
|
||||||
start: '2022-12-03T07:05:00.000Z',
|
start: '2023-01-17T13:00:00.000Z',
|
||||||
stop: '2022-12-03T07:15:00.000Z',
|
stop: '2023-01-17T13:10:00.000Z',
|
||||||
title: `Smástund`,
|
title: `Heimaleikfimi`,
|
||||||
description:
|
description:
|
||||||
'Smástund hentar vel fyrir þau allra yngstu, í hverjum þætti lærum við orð, liti, tölur og tónlist. e.',
|
'Góð ráð og æfingar sem tilvalið er að gera heima. Íris Rut Garðarsdóttir sjúkraþjálfari hefur umsjón með leikfiminni. e.',
|
||||||
icon: 'https://d38kdhuogyllre.cloudfront.net/fit-in/480x/filters:quality(65)/hd_posters/a2kmk0-mcpf0o.jpg'
|
icon: 'https://d38kdhuogyllre.cloudfront.net/fit-in/480x/filters:quality(65)/hd_posters/91pvig-3p3hig.jpg'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can handle empty guide', () => {
|
it('can handle empty guide', () => {
|
||||||
const result = parser({
|
const result = parser({
|
||||||
date,
|
date,
|
||||||
channel,
|
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
|
||||||
})
|
})
|
||||||
expect(result).toMatchObject([])
|
expect(result).toMatchObject([])
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue