mirror of
https://github.com/iptv-org/epg
synced 2026-04-30 06:26:59 -04:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,91 +1,91 @@
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
const API_ENDPOINT = 'https://epg.provider.plex.tv'
|
||||
|
||||
module.exports = {
|
||||
site: 'plex.tv',
|
||||
days: 2,
|
||||
request: {
|
||||
headers: {
|
||||
'x-plex-provider-version': '5.1'
|
||||
}
|
||||
},
|
||||
url: function ({ channel, date }) {
|
||||
const [, channelGridKey] = channel.site_id.split('-')
|
||||
|
||||
return `${API_ENDPOINT}/grid?channelGridKey=${channelGridKey}&date=${date.format('YYYY-MM-DD')}`
|
||||
},
|
||||
parser({ content }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
for (let item of items) {
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description: item.summary,
|
||||
categories: parseCategories(item),
|
||||
image: item.art,
|
||||
start: parseStart(item),
|
||||
stop: parseStop(item)
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ token }) {
|
||||
const data = await axios
|
||||
.get(`${API_ENDPOINT}/lineups/plex/channels?X-Plex-Token=${token}`)
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
return data.MediaContainer.Channel.map(c => {
|
||||
return {
|
||||
lang: 'en',
|
||||
site_id: c.id,
|
||||
name: c.title
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseCategories(item) {
|
||||
return Array.isArray(item.Genre) ? item.Genre.map(g => g.tag) : []
|
||||
}
|
||||
|
||||
function parseStart(item) {
|
||||
return item.beginsAt ? dayjs.unix(item.beginsAt) : null
|
||||
}
|
||||
|
||||
function parseStop(item) {
|
||||
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 => {
|
||||
let segments = []
|
||||
item.Media.sort(byTime).forEach(media => {
|
||||
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(byTime)
|
||||
|
||||
function byTime(a, b) {
|
||||
if (a.beginsAt > b.beginsAt) return 1
|
||||
if (a.beginsAt < b.beginsAt) return -1
|
||||
return 0
|
||||
}
|
||||
}
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
const API_ENDPOINT = 'https://epg.provider.plex.tv'
|
||||
|
||||
module.exports = {
|
||||
site: 'plex.tv',
|
||||
days: 2,
|
||||
request: {
|
||||
headers: {
|
||||
'x-plex-provider-version': '5.1'
|
||||
}
|
||||
},
|
||||
url: function ({ channel, date }) {
|
||||
const [, channelGridKey] = channel.site_id.split('-')
|
||||
|
||||
return `${API_ENDPOINT}/grid?channelGridKey=${channelGridKey}&date=${date.format('YYYY-MM-DD')}`
|
||||
},
|
||||
parser({ content }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
for (let item of items) {
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description: item.summary,
|
||||
categories: parseCategories(item),
|
||||
image: item.art,
|
||||
start: parseStart(item),
|
||||
stop: parseStop(item)
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ token }) {
|
||||
const data = await axios
|
||||
.get(`${API_ENDPOINT}/lineups/plex/channels?X-Plex-Token=${token}`)
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
return data.MediaContainer.Channel.map(c => {
|
||||
return {
|
||||
lang: 'en',
|
||||
site_id: c.id,
|
||||
name: c.title
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseCategories(item) {
|
||||
return Array.isArray(item.Genre) ? item.Genre.map(g => g.tag) : []
|
||||
}
|
||||
|
||||
function parseStart(item) {
|
||||
return item.beginsAt ? dayjs.unix(item.beginsAt) : null
|
||||
}
|
||||
|
||||
function parseStop(item) {
|
||||
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 => {
|
||||
let segments = []
|
||||
item.Media.sort(byTime).forEach(media => {
|
||||
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(byTime)
|
||||
|
||||
function byTime(a, b) {
|
||||
if (a.beginsAt > b.beginsAt) return 1
|
||||
if (a.beginsAt < b.beginsAt) return -1
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
const { parser, url, request } = require('./plex.tv.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2023-02-05', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '5e20b730f2f8d5003d739db7-5eea605674085f0040ddc7a6',
|
||||
xmltv_id: 'DarkMatterTV.us'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://epg.provider.plex.tv/grid?channelGridKey=5eea605674085f0040ddc7a6&date=2023-02-05'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'x-plex-provider-version': '5.1'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ content })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
// expect(results.length).toBe(15)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-02-04T23:31:14.000Z',
|
||||
stop: '2023-02-05T01:10:45.000Z',
|
||||
title: 'Violet & Daisy',
|
||||
description:
|
||||
'Two teenage assassins accept what they think will be a quick-and-easy job, until an unexpected target throws them off their plan.',
|
||||
image: 'https://provider-static.plex.tv/epg/images/ott_channels/arts/darkmatter-tv-about.jpg',
|
||||
categories: ['Movies']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||
const results = parser({ content })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
const { parser, url, request } = require('./plex.tv.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2023-02-05', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '5e20b730f2f8d5003d739db7-5eea605674085f0040ddc7a6',
|
||||
xmltv_id: 'DarkMatterTV.us'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://epg.provider.plex.tv/grid?channelGridKey=5eea605674085f0040ddc7a6&date=2023-02-05'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'x-plex-provider-version': '5.1'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ content })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
// expect(results.length).toBe(15)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-02-04T23:31:14.000Z',
|
||||
stop: '2023-02-05T01:10:45.000Z',
|
||||
title: 'Violet & Daisy',
|
||||
description:
|
||||
'Two teenage assassins accept what they think will be a quick-and-easy job, until an unexpected target throws them off their plan.',
|
||||
image: 'https://provider-static.plex.tv/epg/images/ott_channels/arts/darkmatter-tv-about.jpg',
|
||||
categories: ['Movies']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||
const results = parser({ content })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user