mirror of
https://github.com/iptv-org/epg
synced 2026-04-28 13:37:01 -04:00
Fix linter issues in sites/
This commit is contained in:
@@ -1,102 +1,104 @@
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
module.exports = {
|
||||
site: 'player.ee.co.uk',
|
||||
days: 2,
|
||||
url({ date, channel, hour = 0 }) {
|
||||
return `https://api.youview.tv/metadata/linear/v2/schedule/by-servicelocator?serviceLocator=${
|
||||
encodeURIComponent(channel.site_id)
|
||||
}&interval=${date.format('YYYY-MM-DD')}T${hour.toString().padStart(2,'0')}Z/PT12H`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
Referer: 'https://player.ee.co.uk/'
|
||||
}
|
||||
},
|
||||
async parser({ content, channel, date }) {
|
||||
const programs = []
|
||||
if (content) {
|
||||
const schedule = JSON.parse(content)
|
||||
// fetch next 12 hours schedule
|
||||
const { url, request } = module.exports
|
||||
const nextSchedule = await axios
|
||||
.get(url({ channel, date, hour: 12 }), { headers: request.headers })
|
||||
.then(response => response.data)
|
||||
.catch(console.error)
|
||||
|
||||
if (schedule?.items) {
|
||||
// merge schedules
|
||||
if (nextSchedule?.items) {
|
||||
schedule.items.push(...nextSchedule.items)
|
||||
}
|
||||
schedule.items.forEach(item => {
|
||||
let season, episode
|
||||
const start = dayjs.utc(item.publishedStartTime)
|
||||
const stop = start.add(item.publishedDuration, 's')
|
||||
const description = item.synopsis
|
||||
if (description) {
|
||||
const matches = description.trim().match(/\(?S(\d+)[\/\s]Ep(\d+)\)?/)
|
||||
if (matches) {
|
||||
if (matches[1]) {
|
||||
season = parseInt(matches[1])
|
||||
}
|
||||
if (matches[2]) {
|
||||
episode = parseInt(matches[2])
|
||||
}
|
||||
}
|
||||
}
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description,
|
||||
season,
|
||||
episode,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const token =
|
||||
'eyJkaXNjb3ZlcnlVc2VyR3JvdXBzIjpbIkFMTFVTRVJTIiwiYWxsIiwiaHR0cDovL3JlZmRhd' +
|
||||
'GEueW91dmlldy5jb20vbXBlZzdjcy9Zb3VWaWV3QXBwbGljYXRpb25QbGF5ZXJDUy8yMDIxLT' +
|
||||
'A5LTEwI2FuZHJvaWRfcnVudGltZS1wcm9maWxlMSIsInRhZzpidC5jb20sMjAxOC0wNy0xMTp' +
|
||||
'1c2VyZ3JvdXAjR0JSLWJ0X25vd1RWX211bHRpY2FzdCIsInRhZzpidC5jb20sMjAyMS0xMC0y' +
|
||||
'NTp1c2VyZ3JvdXAjR0JSLWJ0X2V1cm9zcG9ydCJdLCJyZWdpb25zIjpbIkFMTFJFR0lPTlMiL' +
|
||||
'CJHQlIiLCJHQlItRU5HIiwiR0JSLUVORy1sb25kb24iLCJhbGwiXSwic3Vic2V0IjoiMy41Lj' +
|
||||
'EvYW5kcm9pZF9ydW50aW1lLXByb2ZpbGUxL0JST0FEQ0FTVF9JUC9HQlItYnRfYnJvYWRiYW5' +
|
||||
'kIiwic3Vic2V0cyI6WyIvLy8iLCIvL0JST0FEQ0FTVF9JUC8iLCIzLjUvLy8iXX0='
|
||||
const extensions = [
|
||||
'LinearCategoriesExtension',
|
||||
'LogicalChannelNumberExtension',
|
||||
'BTSubscriptionCodesExtension'
|
||||
]
|
||||
const result = await axios
|
||||
.get(`https://api.youview.tv/metadata/linear/v2/linear-services`, {
|
||||
params: {
|
||||
contentTargetingToken: token,
|
||||
extensions: extensions.join(',')
|
||||
},
|
||||
headers: module.exports.request.headers
|
||||
})
|
||||
.then(response => response.data)
|
||||
.catch(console.error)
|
||||
|
||||
return result?.items
|
||||
.filter(channel => channel.contentTypes.indexOf('tv') >= 0)
|
||||
.map(channel => {
|
||||
return {
|
||||
lang: 'en',
|
||||
site_id: channel.serviceLocator,
|
||||
name: channel.fullName
|
||||
}
|
||||
}) || []
|
||||
}
|
||||
}
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
module.exports = {
|
||||
site: 'player.ee.co.uk',
|
||||
days: 2,
|
||||
url({ date, channel, hour = 0 }) {
|
||||
return `https://api.youview.tv/metadata/linear/v2/schedule/by-servicelocator?serviceLocator=${encodeURIComponent(
|
||||
channel.site_id
|
||||
)}&interval=${date.format('YYYY-MM-DD')}T${hour.toString().padStart(2, '0')}Z/PT12H`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
Referer: 'https://player.ee.co.uk/'
|
||||
}
|
||||
},
|
||||
async parser({ content, channel, date }) {
|
||||
const programs = []
|
||||
if (content) {
|
||||
const schedule = JSON.parse(content)
|
||||
// fetch next 12 hours schedule
|
||||
const { url, request } = module.exports
|
||||
const nextSchedule = await axios
|
||||
.get(url({ channel, date, hour: 12 }), { headers: request.headers })
|
||||
.then(response => response.data)
|
||||
.catch(console.error)
|
||||
|
||||
if (schedule?.items) {
|
||||
// merge schedules
|
||||
if (nextSchedule?.items) {
|
||||
schedule.items.push(...nextSchedule.items)
|
||||
}
|
||||
schedule.items.forEach(item => {
|
||||
let season, episode
|
||||
const start = dayjs.utc(item.publishedStartTime)
|
||||
const stop = start.add(item.publishedDuration, 's')
|
||||
const description = item.synopsis
|
||||
if (description) {
|
||||
const matches = description.trim().match(/\(?S(\d+)[/\s]Ep(\d+)\)?/)
|
||||
if (matches) {
|
||||
if (matches[1]) {
|
||||
season = parseInt(matches[1])
|
||||
}
|
||||
if (matches[2]) {
|
||||
episode = parseInt(matches[2])
|
||||
}
|
||||
}
|
||||
}
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description,
|
||||
season,
|
||||
episode,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const token =
|
||||
'eyJkaXNjb3ZlcnlVc2VyR3JvdXBzIjpbIkFMTFVTRVJTIiwiYWxsIiwiaHR0cDovL3JlZmRhd' +
|
||||
'GEueW91dmlldy5jb20vbXBlZzdjcy9Zb3VWaWV3QXBwbGljYXRpb25QbGF5ZXJDUy8yMDIxLT' +
|
||||
'A5LTEwI2FuZHJvaWRfcnVudGltZS1wcm9maWxlMSIsInRhZzpidC5jb20sMjAxOC0wNy0xMTp' +
|
||||
'1c2VyZ3JvdXAjR0JSLWJ0X25vd1RWX211bHRpY2FzdCIsInRhZzpidC5jb20sMjAyMS0xMC0y' +
|
||||
'NTp1c2VyZ3JvdXAjR0JSLWJ0X2V1cm9zcG9ydCJdLCJyZWdpb25zIjpbIkFMTFJFR0lPTlMiL' +
|
||||
'CJHQlIiLCJHQlItRU5HIiwiR0JSLUVORy1sb25kb24iLCJhbGwiXSwic3Vic2V0IjoiMy41Lj' +
|
||||
'EvYW5kcm9pZF9ydW50aW1lLXByb2ZpbGUxL0JST0FEQ0FTVF9JUC9HQlItYnRfYnJvYWRiYW5' +
|
||||
'kIiwic3Vic2V0cyI6WyIvLy8iLCIvL0JST0FEQ0FTVF9JUC8iLCIzLjUvLy8iXX0='
|
||||
const extensions = [
|
||||
'LinearCategoriesExtension',
|
||||
'LogicalChannelNumberExtension',
|
||||
'BTSubscriptionCodesExtension'
|
||||
]
|
||||
const result = await axios
|
||||
.get('https://api.youview.tv/metadata/linear/v2/linear-services', {
|
||||
params: {
|
||||
contentTargetingToken: token,
|
||||
extensions: extensions.join(',')
|
||||
},
|
||||
headers: module.exports.request.headers
|
||||
})
|
||||
.then(response => response.data)
|
||||
.catch(console.error)
|
||||
|
||||
return (
|
||||
result?.items
|
||||
.filter(channel => channel.contentTypes.indexOf('tv') >= 0)
|
||||
.map(channel => {
|
||||
return {
|
||||
lang: 'en',
|
||||
site_id: channel.serviceLocator,
|
||||
name: channel.fullName
|
||||
}
|
||||
}) || []
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +1,74 @@
|
||||
const { parser, url } = require('./player.ee.co.uk.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2023-12-13').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'dvb://233a..6d60',
|
||||
xmltv_id: 'HGTV.uk'
|
||||
}
|
||||
|
||||
axios.get.mockImplementation((url, opts) => {
|
||||
if (url === 'https://api.youview.tv/metadata/linear/v2/schedule/by-servicelocator?serviceLocator=dvb%3A%2F%2F233a..6d60&interval=2023-12-13T12Z/PT12H') {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/data1.json')))
|
||||
})
|
||||
}
|
||||
|
||||
return Promise.resolve({ data: '' })
|
||||
})
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://api.youview.tv/metadata/linear/v2/schedule/by-servicelocator?serviceLocator=dvb%3A%2F%2F233a..6d60&interval=2023-12-13T00Z/PT12H'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/data.json'))
|
||||
const result = (await parser({ content, channel, date }))
|
||||
.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
title: 'Bargain Mansions',
|
||||
description:
|
||||
'Tamara and her dad help a recent widow who loves to cook for her family design her dream kitchen, perfect for entertaining and large gatherings. S4/Ep1',
|
||||
season: 4,
|
||||
episode: 1,
|
||||
start: '2023-12-13T13:00:00.000Z',
|
||||
stop: '2023-12-13T14:00:00.000Z'
|
||||
},
|
||||
{
|
||||
title: 'Flip Or Flop',
|
||||
description:
|
||||
'Tarek and Christina are contacted by a cash strapped flipper who needs to unload a project house. S2/Ep2',
|
||||
season: 2,
|
||||
episode: 2,
|
||||
start: '2023-12-13T14:00:00.000Z',
|
||||
stop: '2023-12-13T14:30:00.000Z'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
const result = await parser({
|
||||
channel,
|
||||
date,
|
||||
content: ''
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./player.ee.co.uk.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2023-12-13').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'dvb://233a..6d60',
|
||||
xmltv_id: 'HGTV.uk'
|
||||
}
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (
|
||||
url ===
|
||||
'https://api.youview.tv/metadata/linear/v2/schedule/by-servicelocator?serviceLocator=dvb%3A%2F%2F233a..6d60&interval=2023-12-13T12Z/PT12H'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/data1.json')))
|
||||
})
|
||||
}
|
||||
|
||||
return Promise.resolve({ data: '' })
|
||||
})
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://api.youview.tv/metadata/linear/v2/schedule/by-servicelocator?serviceLocator=dvb%3A%2F%2F233a..6d60&interval=2023-12-13T00Z/PT12H'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/data.json'))
|
||||
const result = (await parser({ content, channel, date })).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
title: 'Bargain Mansions',
|
||||
description:
|
||||
'Tamara and her dad help a recent widow who loves to cook for her family design her dream kitchen, perfect for entertaining and large gatherings. S4/Ep1',
|
||||
season: 4,
|
||||
episode: 1,
|
||||
start: '2023-12-13T13:00:00.000Z',
|
||||
stop: '2023-12-13T14:00:00.000Z'
|
||||
},
|
||||
{
|
||||
title: 'Flip Or Flop',
|
||||
description:
|
||||
'Tarek and Christina are contacted by a cash strapped flipper who needs to unload a project house. S2/Ep2',
|
||||
season: 2,
|
||||
episode: 2,
|
||||
start: '2023-12-13T14:00:00.000Z',
|
||||
stop: '2023-12-13T14:30:00.000Z'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
const result = await parser({
|
||||
channel,
|
||||
date,
|
||||
content: ''
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user