mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 17:10:07 -04:00
Create skylife.co.kr.config.js
This commit is contained in:
parent
ebee0d0b5f
commit
f94086afc7
1 changed files with 81 additions and 0 deletions
81
sites/skylife.co.kr/skylife.co.kr.config.js
Normal file
81
sites/skylife.co.kr/skylife.co.kr.config.js
Normal file
|
@ -0,0 +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
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue