mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 10:26:41 -05:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,68 +1,68 @@
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
module.exports = {
|
||||
site: 'singtel.com',
|
||||
days: 3,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ date }) {
|
||||
return `https://www.singtel.com/etc/singtel/public/tv/epg-parsed-data/${date.format(
|
||||
'DDMMYYYY'
|
||||
)}.json`
|
||||
},
|
||||
parser({ content, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
items.forEach(item => {
|
||||
const start = dayjs.tz(item.startDateTime, 'Asia/Singapore')
|
||||
const stop = start.add(item.duration, 's')
|
||||
programs.push({
|
||||
title: item.program.title,
|
||||
category: item.program.subCategory,
|
||||
description: item.program.description,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
const data = await axios
|
||||
.get('https://www.singtel.com/personal/products-services/tv/tv-programme-guide')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(data)
|
||||
let datamodel = $('ux-tv-channel-epg').attr('datamodel')
|
||||
datamodel = JSON.parse(datamodel)
|
||||
|
||||
return datamodel.tvChannelLists.map(item => {
|
||||
return {
|
||||
lang: 'en',
|
||||
site_id: item.epgChannelId,
|
||||
name: item.title.trim()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
try {
|
||||
const data = JSON.parse(content)
|
||||
return data && data[channel.site_id] ? data[channel.site_id] : []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
module.exports = {
|
||||
site: 'singtel.com',
|
||||
days: 3,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ date }) {
|
||||
return `https://www.singtel.com/etc/singtel/public/tv/epg-parsed-data/${date.format(
|
||||
'DDMMYYYY'
|
||||
)}.json`
|
||||
},
|
||||
parser({ content, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
items.forEach(item => {
|
||||
const start = dayjs.tz(item.startDateTime, 'Asia/Singapore')
|
||||
const stop = start.add(item.duration, 's')
|
||||
programs.push({
|
||||
title: item.program.title,
|
||||
category: item.program.subCategory,
|
||||
description: item.program.description,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
const data = await axios
|
||||
.get('https://www.singtel.com/personal/products-services/tv/tv-programme-guide')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(data)
|
||||
let datamodel = $('ux-tv-channel-epg').attr('datamodel')
|
||||
datamodel = JSON.parse(datamodel)
|
||||
|
||||
return datamodel.tvChannelLists.map(item => {
|
||||
return {
|
||||
lang: 'en',
|
||||
site_id: item.epgChannelId,
|
||||
name: item.title.trim()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
try {
|
||||
const data = JSON.parse(content)
|
||||
return data && data[channel.site_id] ? data[channel.site_id] : []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
const { parser, url } = require('./singtel.com.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-01-29', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '5418',
|
||||
xmltv_id: 'ParamountNetworkSingapore.sg'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.singtel.com/etc/singtel/public/tv/epg-parsed-data/29012023.json'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ content, channel })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(23)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-01-28T16:00:00.000Z',
|
||||
stop: '2023-01-28T17:30:00.000Z',
|
||||
title: 'Hip Hop Family Christmas Wedding',
|
||||
description:
|
||||
'Hip Hop\'s most famous family is back, and this time Christmas wedding bells are ringing! Jessica and Jayson are getting ready to say their "I do\'s".',
|
||||
category: 'Specials'
|
||||
})
|
||||
|
||||
expect(results[10]).toMatchObject({
|
||||
start: '2023-01-29T01:00:00.000Z',
|
||||
stop: '2023-01-29T01:30:00.000Z',
|
||||
title: 'The Daily Show',
|
||||
description:
|
||||
'The Daily Show correspondents tackle the biggest stories in news, politics and pop culture.',
|
||||
category: 'English Entertainment'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const results = parser({ content, channel })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./singtel.com.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-01-29', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '5418',
|
||||
xmltv_id: 'ParamountNetworkSingapore.sg'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.singtel.com/etc/singtel/public/tv/epg-parsed-data/29012023.json'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ content, channel })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(23)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-01-28T16:00:00.000Z',
|
||||
stop: '2023-01-28T17:30:00.000Z',
|
||||
title: 'Hip Hop Family Christmas Wedding',
|
||||
description:
|
||||
'Hip Hop\'s most famous family is back, and this time Christmas wedding bells are ringing! Jessica and Jayson are getting ready to say their "I do\'s".',
|
||||
category: 'Specials'
|
||||
})
|
||||
|
||||
expect(results[10]).toMatchObject({
|
||||
start: '2023-01-29T01:00:00.000Z',
|
||||
stop: '2023-01-29T01:30:00.000Z',
|
||||
title: 'The Daily Show',
|
||||
description:
|
||||
'The Daily Show correspondents tackle the biggest stories in news, politics and pop culture.',
|
||||
category: 'English Entertainment'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const results = parser({ content, channel })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user