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,81 +1,81 @@
|
||||
const dayjs = require('dayjs')
|
||||
const axios = require('axios')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'skylife.co.kr',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ date }) {
|
||||
return `https://www.skylife.co.kr/api/api/public/tv/schedule/${date.format('YYYYMMDD')}`
|
||||
},
|
||||
parser: function ({ content, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.name,
|
||||
description: item.summary,
|
||||
category: item.mainCategory,
|
||||
actors: parseCast(item.cast),
|
||||
start: parseTime(item.startTime),
|
||||
stop: parseTime(item.endTime)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
let channels = []
|
||||
|
||||
const url = `https://www.skylife.co.kr/api/api/public/tv/schedule/${dayjs().format('YYYYMMDD')}`
|
||||
const data = await axios
|
||||
.get(url)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
for (let category of data) {
|
||||
for (let channel of category.channels) {
|
||||
channels.push({
|
||||
name: channel.name,
|
||||
site_id: `${category.code}#${channel.id}`,
|
||||
lang: 'ko'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseCast(cast) {
|
||||
if (!cast) return []
|
||||
|
||||
return cast.split(',')
|
||||
}
|
||||
|
||||
function parseTime(time) {
|
||||
return dayjs.tz(time, 'YYYYMMDDHHmmss', 'Asia/Seoul')
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
const [categoryCode, channelId] = channel.site_id.split('#')
|
||||
const data = JSON.parse(content)
|
||||
if (!Array.isArray(data)) return []
|
||||
const category = data.find(_category => _category.code === categoryCode)
|
||||
if (!category || !Array.isArray(category.channels)) return []
|
||||
const channelData = category.channels.find(_channel => _channel.id === channelId)
|
||||
if (!channelData || !Array.isArray(channelData.programs)) return []
|
||||
|
||||
return channelData.programs
|
||||
}
|
||||
const dayjs = require('dayjs')
|
||||
const axios = require('axios')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'skylife.co.kr',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ date }) {
|
||||
return `https://www.skylife.co.kr/api/api/public/tv/schedule/${date.format('YYYYMMDD')}`
|
||||
},
|
||||
parser: function ({ content, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.name,
|
||||
description: item.summary,
|
||||
category: item.mainCategory,
|
||||
actors: parseCast(item.cast),
|
||||
start: parseTime(item.startTime),
|
||||
stop: parseTime(item.endTime)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
let channels = []
|
||||
|
||||
const url = `https://www.skylife.co.kr/api/api/public/tv/schedule/${dayjs().format('YYYYMMDD')}`
|
||||
const data = await axios
|
||||
.get(url)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
for (let category of data) {
|
||||
for (let channel of category.channels) {
|
||||
channels.push({
|
||||
name: channel.name,
|
||||
site_id: `${category.code}#${channel.id}`,
|
||||
lang: 'ko'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseCast(cast) {
|
||||
if (!cast) return []
|
||||
|
||||
return cast.split(',')
|
||||
}
|
||||
|
||||
function parseTime(time) {
|
||||
return dayjs.tz(time, 'YYYYMMDDHHmmss', 'Asia/Seoul')
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
const [categoryCode, channelId] = channel.site_id.split('#')
|
||||
const data = JSON.parse(content)
|
||||
if (!Array.isArray(data)) return []
|
||||
const category = data.find(_category => _category.code === categoryCode)
|
||||
if (!category || !Array.isArray(category.channels)) return []
|
||||
const channelData = category.channels.find(_channel => _channel.id === channelId)
|
||||
if (!channelData || !Array.isArray(channelData.programs)) return []
|
||||
|
||||
return channelData.programs
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
const { parser, url } = require('./skylife.co.kr.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)
|
||||
|
||||
const date = dayjs.utc('2024-06-26', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '4003#798',
|
||||
xmltv_id: 'EBS.kr'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date })).toBe('https://www.skylife.co.kr/api/api/public/tv/schedule/20240626')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ content, channel }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[20]).toMatchObject({
|
||||
start: '2024-06-26T00:40:00.000Z', // 20240626094000
|
||||
stop: '2024-06-26T01:30:00.000Z', // 20240626103000
|
||||
title: '세상에 나쁜 개는 없다',
|
||||
description: '문제 있는 반려견들의 행동을 알아 보고 원인을 찾아나가는 프로그램',
|
||||
category: '교양/정보',
|
||||
actors: ['박영진', '강형욱']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||
const result = parser({ content, channel })
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./skylife.co.kr.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)
|
||||
|
||||
const date = dayjs.utc('2024-06-26', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '4003#798',
|
||||
xmltv_id: 'EBS.kr'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date })).toBe('https://www.skylife.co.kr/api/api/public/tv/schedule/20240626')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ content, channel }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[20]).toMatchObject({
|
||||
start: '2024-06-26T00:40:00.000Z', // 20240626094000
|
||||
stop: '2024-06-26T01:30:00.000Z', // 20240626103000
|
||||
title: '세상에 나쁜 개는 없다',
|
||||
description: '문제 있는 반려견들의 행동을 알아 보고 원인을 찾아나가는 프로그램',
|
||||
category: '교양/정보',
|
||||
actors: ['박영진', '강형욱']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||
const result = parser({ content, channel })
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user