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
b4dca359c9
commit
54b7be218f
1 changed files with 48 additions and 10 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
const axios = require('axios')
|
||||||
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')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
@ -5,18 +6,15 @@ const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
|
const API_ENDPOINT = 'https://www.dsmart.com.tr/api/v1/public/epg/schedules'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'dsmart.com.tr',
|
site: 'dsmart.com.tr',
|
||||||
days: 2,
|
days: 2,
|
||||||
request: {
|
|
||||||
cache: {
|
|
||||||
ttl: 60 * 1000 // 60 seconds response cache
|
|
||||||
}
|
|
||||||
},
|
|
||||||
url({ date, channel }) {
|
url({ date, channel }) {
|
||||||
return `https://www.dsmart.com.tr/api/v1/public/epg/schedules?page=1&limit=500&day=${date.format(
|
const [page] = channel.site_id.split('#')
|
||||||
'YYYY-MM-DD'
|
|
||||||
)}`
|
return `${API_ENDPOINT}?page=${page}&limit=1&day=${date.format('YYYY-MM-DD')}`
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel }) {
|
parser: function ({ content, channel }) {
|
||||||
let offset = -1
|
let offset = -1
|
||||||
|
@ -35,7 +33,7 @@ module.exports = {
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title: item.program_name,
|
title: item.program_name,
|
||||||
category: item.genre,
|
category: parseCategory(item),
|
||||||
description: item.description.trim(),
|
description: item.description.trim(),
|
||||||
start,
|
start,
|
||||||
stop
|
stop
|
||||||
|
@ -43,7 +41,46 @@ module.exports = {
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
|
},
|
||||||
|
async channels() {
|
||||||
|
const perPage = 1
|
||||||
|
const totalChannels = 210
|
||||||
|
const pages = Math.ceil(totalChannels / perPage)
|
||||||
|
|
||||||
|
const channels = []
|
||||||
|
for (let i in Array(pages).fill(0)) {
|
||||||
|
const page = parseInt(i) + 1
|
||||||
|
const url = `${API_ENDPOINT}?page=${page}&limit=${perPage}&day=${dayjs().format(
|
||||||
|
'YYYY-MM-DD'
|
||||||
|
)}`
|
||||||
|
let offset = i * perPage
|
||||||
|
await axios
|
||||||
|
.get(url)
|
||||||
|
.then(r => r.data)
|
||||||
|
.then(data => {
|
||||||
|
offset++
|
||||||
|
if (data && data.data && Array.isArray(data.data.channels)) {
|
||||||
|
data.data.channels.forEach((item, j) => {
|
||||||
|
const index = offset + j
|
||||||
|
channels.push({
|
||||||
|
lang: 'tr',
|
||||||
|
name: item.channel_name,
|
||||||
|
site_id: index + '#' + item._id
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return channels
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCategory(item) {
|
||||||
|
return item.genre !== '0' ? item.genre : null
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item, date) {
|
function parseStart(item, date) {
|
||||||
|
@ -59,9 +96,10 @@ function parseDuration(item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, channel) {
|
function parseItems(content, channel) {
|
||||||
|
const [, channelId] = channel.site_id.split('#')
|
||||||
const data = JSON.parse(content)
|
const data = JSON.parse(content)
|
||||||
if (!data || !data.data || !Array.isArray(data.data.channels)) return null
|
if (!data || !data.data || !Array.isArray(data.data.channels)) return null
|
||||||
const channelData = data.data.channels.find(i => i._id == channel.site_id)
|
const channelData = data.data.channels.find(i => i._id == channelId)
|
||||||
|
|
||||||
return channelData && Array.isArray(channelData.schedule) ? channelData.schedule : []
|
return channelData && Array.isArray(channelData.schedule) ? channelData.schedule : []
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue