Merge pull request #1356 from iptv-org/fix-plex.tv

Fix plex.tv
This commit is contained in:
Aleksandr Statciuk 2022-11-18 14:36:00 +03:00 committed by GitHub
commit 042f9d58cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 7 deletions

View file

@ -51,20 +51,27 @@ function parseCategories(item) {
} }
function parseStart(item) { function parseStart(item) {
const media = item.Media.length ? item.Media[0] : null return item.beginsAt ? dayjs.unix(item.beginsAt) : null
return media ? dayjs.unix(media.beginsAt) : null
} }
function parseStop(item) { function parseStop(item) {
const media = item.Media.length ? item.Media[0] : null return item.endsAt ? dayjs.unix(item.endsAt) : null
return media ? dayjs.unix(media.endsAt) : null
} }
function parseItems(content) { function parseItems(content) {
const data = JSON.parse(content) const data = JSON.parse(content)
if (!data || !data.MediaContainer || !Array.isArray(data.MediaContainer.Metadata)) return [] 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
})
} }

View file

@ -40,6 +40,7 @@ it('can parse response', () => {
return p return p
}) })
expect(results.length).toBe(14)
expect(results[0]).toMatchObject({ expect(results[0]).toMatchObject({
start: '2022-11-14T23:04:00.000Z', start: '2022-11-14T23:04:00.000Z',
stop: '2022-11-15T00:47: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', icon: 'https://metadata-static.plex.tv/4/gracenote/40b523ad60464f8232f93f861c161384.jpg',
categories: ['Documentary', 'Movies'] 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', () => { it('can handle empty guide', () => {