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

Fix plex.tv
This commit is contained in:
ajanes3 2023-02-06 11:06:22 -05:00 committed by GitHub
commit c9e1a063ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 36 deletions

File diff suppressed because one or more lines are too long

View file

@ -65,14 +65,26 @@ function parseItems(content) {
const metadata = data.MediaContainer.Metadata const metadata = data.MediaContainer.Metadata
const items = [] const items = []
metadata.forEach(item => { metadata.forEach(item => {
item.Media.forEach(media => { let segments = []
items.push({ ...item, ...media }) item.Media.sort(byTime).forEach((media, i) => {
let prevSegment = segments[segments.length - 1]
if (prevSegment && prevSegment.endsAt === media.beginsAt) {
prevSegment.endsAt = media.endsAt
} else {
segments.push(media)
}
})
segments.forEach(segment => {
items.push({ ...item, segments, beginsAt: segment.beginsAt, endsAt: segment.endsAt })
}) })
}) })
return items.sort((a, b) => { return items.sort(byTime)
function byTime(a, b) {
if (a.beginsAt > b.beginsAt) return 1 if (a.beginsAt > b.beginsAt) return 1
if (a.beginsAt < b.beginsAt) return -1 if (a.beginsAt < b.beginsAt) return -1
return 0 return 0
}) }
} }

View file

@ -13,15 +13,15 @@ dayjs.extend(utc)
jest.mock('axios') jest.mock('axios')
const date = dayjs.utc('2022-11-15', 'YYYY-MM-DD').startOf('d') const date = dayjs.utc('2023-02-05', 'YYYY-MM-DD').startOf('d')
const channel = { const channel = {
site_id: '5e20b730f2f8d5003d739db7-5fc705eb052f6f002ef46057', site_id: '5e20b730f2f8d5003d739db7-5eea605674085f0040ddc7a6',
xmltv_id: 'IFCFilmsPicks.us' xmltv_id: 'DarkMatterTV.us'
} }
it('can generate valid url', () => { it('can generate valid url', () => {
expect(url({ channel, date })).toBe( expect(url({ channel, date })).toBe(
'https://epg.provider.plex.tv/grid?channelGridKey=5fc705eb052f6f002ef46057&date=2022-11-15' 'https://epg.provider.plex.tv/grid?channelGridKey=5eea605674085f0040ddc7a6&date=2023-02-05'
) )
}) })
@ -40,35 +40,15 @@ it('can parse response', () => {
return p return p
}) })
expect(results.length).toBe(14) // expect(results.length).toBe(15)
expect(results[0]).toMatchObject({ expect(results[0]).toMatchObject({
start: '2022-11-14T23:04:00.000Z', start: '2023-02-04T23:31:14.000Z',
stop: '2022-11-15T00:47:00.000Z', stop: '2023-02-05T01:10:45.000Z',
title: 'Bound by Flesh', title: 'Violet & Daisy',
description: description:
'Conjoined twins Daisy and Violet Hilton were born in 1908, then were sold to a carnival sideshow as babies. They became huge stars of Vaudeville but never earned a penny until they sued for freedom in 1936.', 'Two teenage assassins accept what they think will be a quick-and-easy job, until an unexpected target throws them off their plan.',
icon: 'https://metadata-static.plex.tv/4/gracenote/40b523ad60464f8232f93f861c161384.jpg', icon: 'https://provider-static.plex.tv/epg/images/ott_channels/arts/darkmatter-tv-about.jpg',
categories: ['Documentary', 'Movies'] categories: ['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']
}) })
}) })