mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Update dsmart.com.tr.config.js
This commit is contained in:
parent
30613510af
commit
e1a2b274cd
1 changed files with 26 additions and 21 deletions
|
@ -1,7 +1,9 @@
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'dsmart.com.tr',
|
site: 'dsmart.com.tr',
|
||||||
|
@ -16,23 +18,27 @@ module.exports = {
|
||||||
'YYYY-MM-DD'
|
'YYYY-MM-DD'
|
||||||
)}`
|
)}`
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel, date }) {
|
parser: function ({ content, channel }) {
|
||||||
let offset = -1
|
let offset = -1
|
||||||
let programs = []
|
let programs = []
|
||||||
const items = parseItems(content, channel)
|
const items = parseItems(content, channel)
|
||||||
items.forEach(item => {
|
items.forEach((item, i) => {
|
||||||
let start = parseStart(item, date)
|
const prev = programs[programs.length - 1]
|
||||||
if (offset === -1 && start.hour() > 18) start = start.subtract(1, 'd')
|
let start
|
||||||
let stop = parseStop(item, date)
|
if (prev) {
|
||||||
if (offset === -1 && stop.hour() > 18) stop = stop.subtract(1, 'd')
|
start = parseStart(item, prev.stop)
|
||||||
if (start.hour() < 18 || stop.hour() < 18) offset = 0
|
} else {
|
||||||
|
start = parseStart(item, dayjs.utc(item.day))
|
||||||
|
}
|
||||||
|
let duration = parseDuration(item)
|
||||||
|
let stop = start.add(duration, 's')
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title: item.program_name,
|
title: item.program_name,
|
||||||
category: item.genre,
|
category: item.genre,
|
||||||
description: item.description,
|
description: item.description.trim(),
|
||||||
start: start.toJSON(),
|
start,
|
||||||
stop: stop.toJSON()
|
stop
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -41,22 +47,21 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item, date) {
|
function parseStart(item, date) {
|
||||||
return dayjs.utc(item.start_date).set('date', date.get('date'))
|
const time = dayjs.utc(item.start_date)
|
||||||
|
|
||||||
|
return dayjs.utc(`${date.format('YYYY-MM-DD')} ${time.format('HH:mm:ss')}`, 'YYYY-MM-DD HH:mm:ss')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStop(item, date) {
|
function parseDuration(item) {
|
||||||
return dayjs.utc(item.end_date).set('date', date.get('date'))
|
const [_, H, mm, ss] = item.duration.match(/(\d+):(\d+):(\d+)$/)
|
||||||
}
|
|
||||||
|
|
||||||
function parseContent(content, channel) {
|
return parseInt(H) * 3600 + parseInt(mm) * 60 + parseInt(ss)
|
||||||
const data = JSON.parse(content)
|
|
||||||
if (!data || !data.data || !Array.isArray(data.data.channels)) return null
|
|
||||||
|
|
||||||
return data.data.channels.find(i => i._id == channel.site_id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, channel) {
|
function parseItems(content, channel) {
|
||||||
const data = parseContent(content, channel)
|
const data = JSON.parse(content)
|
||||||
|
if (!data || !data.data || !Array.isArray(data.data.channels)) return null
|
||||||
|
const channelData = data.data.channels.find(i => i._id == channel.site_id)
|
||||||
|
|
||||||
return data ? data.schedule : []
|
return channelData && Array.isArray(channelData.schedule) ? channelData.schedule : []
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue