mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
commit
042f9d58cc
2 changed files with 35 additions and 7 deletions
|
@ -51,20 +51,27 @@ function parseCategories(item) {
|
|||
}
|
||||
|
||||
function parseStart(item) {
|
||||
const media = item.Media.length ? item.Media[0] : null
|
||||
|
||||
return media ? dayjs.unix(media.beginsAt) : null
|
||||
return item.beginsAt ? dayjs.unix(item.beginsAt) : null
|
||||
}
|
||||
|
||||
function parseStop(item) {
|
||||
const media = item.Media.length ? item.Media[0] : null
|
||||
|
||||
return media ? dayjs.unix(media.endsAt) : null
|
||||
return item.endsAt ? dayjs.unix(item.endsAt) : null
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !data.MediaContainer || !Array.isArray(data.MediaContainer.Metadata)) return []
|
||||
const metadata = data.MediaContainer.Metadata
|
||||
const items = []
|
||||
metadata.forEach(item => {
|
||||
item.Media.forEach(media => {
|
||||
items.push({ ...item, ...media })
|
||||
})
|
||||
})
|
||||
|
||||
return data.MediaContainer.Metadata
|
||||
return items.sort((a, b) => {
|
||||
if (a.beginsAt > b.beginsAt) return 1
|
||||
if (a.beginsAt < b.beginsAt) return -1
|
||||
return 0
|
||||
})
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ it('can parse response', () => {
|
|||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(14)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-14T23:04:00.000Z',
|
||||
stop: '2022-11-15T00:47:00.000Z',
|
||||
|
@ -49,6 +50,26 @@ it('can parse response', () => {
|
|||
icon: 'https://metadata-static.plex.tv/4/gracenote/40b523ad60464f8232f93f861c161384.jpg',
|
||||
categories: ['Documentary', 'Movies']
|
||||
})
|
||||
|
||||
expect(results[10]).toMatchObject({
|
||||
start: '2022-11-15T16:45:00.000Z',
|
||||
stop: '2022-11-15T18:47:00.000Z',
|
||||
title: 'Antiviral',
|
||||
description:
|
||||
"Syd has to unravel the mystery surrounding Hannah's death before a virus kills him.",
|
||||
icon: 'https://metadata-static.plex.tv/5/gracenote/5ca8432a2e8fb2e8f8157ae142164ef7.jpg',
|
||||
categories: ['Horror', 'Science fiction', 'Thriller', 'Movies']
|
||||
})
|
||||
|
||||
expect(results[11]).toMatchObject({
|
||||
start: '2022-11-15T18:47:00.000Z',
|
||||
stop: '2022-11-15T20:36:00.000Z',
|
||||
title: 'Cold Weather',
|
||||
description:
|
||||
'Armed with a few clues and an in-depth knowledge of Sherlock Holmes lore, an ice-factory worker (Cris Lankenau) leads his sister and a co-worker on a search for his missing former lover.',
|
||||
icon: 'https://metadata-static.plex.tv/5/gracenote/5150185f3188dbefd10b5d388e8ba115.jpg',
|
||||
categories: ['Comedy', 'Mystery', 'Movies']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue