mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Fix raiplay.it test
This commit is contained in:
parent
6037099d31
commit
0fddd7c46b
2 changed files with 37 additions and 34 deletions
|
@ -10,7 +10,9 @@ dayjs.extend(timezone)
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'raiplay.it',
|
site: 'raiplay.it',
|
||||||
url: function ({ date, channel }) {
|
url: function ({ date, channel }) {
|
||||||
return `https://www.raiplay.it/palinsesto/app/${channel.site_id}/${date.format('DD-MM-YYYY')}.json`
|
return `https://www.raiplay.it/palinsesto/app/${channel.site_id}/${date.format(
|
||||||
|
'DD-MM-YYYY'
|
||||||
|
)}.json`
|
||||||
},
|
},
|
||||||
parser: function ({ content, date }) {
|
parser: function ({ content, date }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
|
@ -18,37 +20,35 @@ module.exports = {
|
||||||
if (!data.events) return programs
|
if (!data.events) return programs
|
||||||
|
|
||||||
data.events.forEach(item => {
|
data.events.forEach(item => {
|
||||||
if (item.name && item.hour && item.duration_in_minutes) {
|
if (!item.name || !item.hour || !item.duration_in_minutes) return
|
||||||
const startDate = dayjs.tz(item.hour, 'HH:mm','Europe/Rome')
|
const start = parseStart(item, date)
|
||||||
.set('D', date.get('D'))
|
const duration = parseInt(item.duration_in_minutes)
|
||||||
.set('M', date.get('M'))
|
const stop = start.add(duration, 'm')
|
||||||
.set('y', date.get('y'))
|
|
||||||
const start = startDate.toJSON()
|
|
||||||
const duration = parseInt(item.duration_in_minutes)
|
|
||||||
const stopDate = startDate.add(duration,'m')
|
|
||||||
const stop = stopDate.toJSON()
|
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title: item.name || item.program.name,
|
title: item.name || item.program.name,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
season: parseSeason(item) ,
|
season: parseSeason(item),
|
||||||
episode: parseEpisode(item),
|
episode: parseEpisode(item),
|
||||||
sub_title : item['episode_title'] || null,
|
sub_title: item['episode_title'] || null,
|
||||||
url : parseURL(item),
|
url: parseURL(item),
|
||||||
start,
|
start,
|
||||||
stop,
|
stop,
|
||||||
icon: parseIcon(item)
|
icon: parseIcon(item)
|
||||||
})
|
})
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseStart(item, date) {
|
||||||
|
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${item.hour}`, 'YYYY-MM-DD HH:mm', 'Europe/Rome')
|
||||||
|
}
|
||||||
|
|
||||||
function parseIcon(item) {
|
function parseIcon(item) {
|
||||||
let cover = null;
|
let cover = null
|
||||||
if(item.image){
|
if (item.image) {
|
||||||
cover = `https://www.raiplay.it${item.image}`
|
cover = `https://www.raiplay.it${item.image}`
|
||||||
}
|
}
|
||||||
return cover
|
return cover
|
||||||
|
@ -56,23 +56,23 @@ function parseIcon(item) {
|
||||||
|
|
||||||
function parseURL(item) {
|
function parseURL(item) {
|
||||||
let url = null
|
let url = null
|
||||||
if(item.weblink){
|
if (item.weblink) {
|
||||||
url = `https://www.raiplay.it${item.weblink}`
|
url = `https://www.raiplay.it${item.weblink}`
|
||||||
}
|
}
|
||||||
if(item.event_weblink){
|
if (item.event_weblink) {
|
||||||
url = `https://www.raiplay.it${item.event_weblink}`
|
url = `https://www.raiplay.it${item.event_weblink}`
|
||||||
}
|
}
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseSeason(item) {
|
function parseSeason(item) {
|
||||||
if (!item.season) return null
|
if (!item.season) return null
|
||||||
if (String(item.season).length > 2) return null
|
if (String(item.season).length > 2) return null
|
||||||
return item.season
|
return item.season
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseEpisode(item) {
|
function parseEpisode(item) {
|
||||||
if (!item.episode) return null
|
if (!item.episode) return null
|
||||||
if (String(item.episode).length > 3) return null
|
if (String(item.episode).length > 3) return null
|
||||||
return item.episode
|
return item.episode
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,16 @@ it('can generate valid url', () => {
|
||||||
it('can parse response', () => {
|
it('can parse response', () => {
|
||||||
const content = `{ "id": "Page-e120a813-1b92-4057-a214-15943d95aa68", "title": "Pagina Palinsesto", "channel": "Rai 2", "date": "03-05-2022", "events": [ { "id": "ContentItem-2f81030d-803b-456a-9ea5-40233234fd9d", "name": "The Good Doctor S3E5 - La prima volta", "episode_title": "La prima volta", "episode": "5", "season": "3", "description": "Shaun affronta il suo primo intervento. Il caso si rivela complicato e, nonostante Shaun abbia un'idea geniale, sarà Andrews a portare a termine l'operazione.", "channel": "Rai 2", "date": "03/05/2022", "hour": "19:40", "duration": "00:50:00", "duration_in_minutes": "50 min", "path_id": "", "weblink": "", "event_weblink": "/dirette/rai2/The-Good-Doctor-S3E5---La-prima-volta-2f81030d-803b-456a-9ea5-40233234fd9d.html", "has_video": false, "image": "/dl/img/2020/03/09/1583748471860_dddddd.jpg", "playlist_id": "11430689", "program": { "name": "The Good Doctor", "path_id": "/programmi/thegooddoctor.json", "info_url": "/programmi/info/757edeac-6fff-4dea-afcd-0bcb39f9ea83.json", "weblink": "/programmi/thegooddoctor" } } ], "track_info": { "id": "", "domain": "raiplay", "platform": "[platform]", "media_type": "", "page_type": "", "editor": "raiplay", "year": "2019", "edit_year": "", "section": "guida tv", "sub_section": "rai 2", "content": "guida tv", "title": "", "channel": "", "date": "2019-09-08", "typology": "", "genres": [], "sub_genres": [], "program_title": "", "program_typology": "", "program_genres": [], "program_sub_genres": [], "edition": "", "season": "", "episode_number": "", "episode_title": "", "form": "", "listaDateMo": [], "dfp": {} }}`
|
const content = `{ "id": "Page-e120a813-1b92-4057-a214-15943d95aa68", "title": "Pagina Palinsesto", "channel": "Rai 2", "date": "03-05-2022", "events": [ { "id": "ContentItem-2f81030d-803b-456a-9ea5-40233234fd9d", "name": "The Good Doctor S3E5 - La prima volta", "episode_title": "La prima volta", "episode": "5", "season": "3", "description": "Shaun affronta il suo primo intervento. Il caso si rivela complicato e, nonostante Shaun abbia un'idea geniale, sarà Andrews a portare a termine l'operazione.", "channel": "Rai 2", "date": "03/05/2022", "hour": "19:40", "duration": "00:50:00", "duration_in_minutes": "50 min", "path_id": "", "weblink": "", "event_weblink": "/dirette/rai2/The-Good-Doctor-S3E5---La-prima-volta-2f81030d-803b-456a-9ea5-40233234fd9d.html", "has_video": false, "image": "/dl/img/2020/03/09/1583748471860_dddddd.jpg", "playlist_id": "11430689", "program": { "name": "The Good Doctor", "path_id": "/programmi/thegooddoctor.json", "info_url": "/programmi/info/757edeac-6fff-4dea-afcd-0bcb39f9ea83.json", "weblink": "/programmi/thegooddoctor" } } ], "track_info": { "id": "", "domain": "raiplay", "platform": "[platform]", "media_type": "", "page_type": "", "editor": "raiplay", "year": "2019", "edit_year": "", "section": "guida tv", "sub_section": "rai 2", "content": "guida tv", "title": "", "channel": "", "date": "2019-09-08", "typology": "", "genres": [], "sub_genres": [], "program_title": "", "program_typology": "", "program_genres": [], "program_sub_genres": [], "edition": "", "season": "", "episode_number": "", "episode_title": "", "form": "", "listaDateMo": [], "dfp": {} }}`
|
||||||
const result = parser({ content, date }).map(p => {
|
const result = parser({ content, date }).map(p => {
|
||||||
|
p.start = p.start.toJSON()
|
||||||
|
p.stop = p.stop.toJSON()
|
||||||
|
|
||||||
return p
|
return p
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result).toMatchObject([
|
expect(result).toMatchObject([
|
||||||
{
|
{
|
||||||
start: '2022-05-03T18:40:00.000Z',
|
start: '2022-05-03T17:40:00.000Z',
|
||||||
stop: '2022-05-03T19:30:00.000Z',
|
stop: '2022-05-03T18:30:00.000Z',
|
||||||
title: 'The Good Doctor S3E5 - La prima volta',
|
title: 'The Good Doctor S3E5 - La prima volta',
|
||||||
description:
|
description:
|
||||||
"Shaun affronta il suo primo intervento. Il caso si rivela complicato e, nonostante Shaun abbia un'idea geniale, sarà Andrews a portare a termine l'operazione.",
|
"Shaun affronta il suo primo intervento. Il caso si rivela complicato e, nonostante Shaun abbia un'idea geniale, sarà Andrews a portare a termine l'operazione.",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue