mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update mts.rs.config.js
This commit is contained in:
parent
6010fc4978
commit
868a6f89a3
1 changed files with 31 additions and 81 deletions
|
@ -1,105 +1,55 @@
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
|
||||||
|
|
||||||
dayjs.extend(utc)
|
|
||||||
dayjs.extend(timezone)
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'mts.rs',
|
site: 'mts.rs',
|
||||||
days: 2,
|
days: 2,
|
||||||
url({ date, channel }) {
|
url({ date }) {
|
||||||
const [position] = channel.site_id.split('#')
|
return `https://mts.rs/hybris/ecommerce/b2c/v1/products/search?sort=pozicija-rastuce&searchQueryContext=CHANNEL_PROGRAM&query=:pozicija-rastuce:tip-kanala-radio:TV kanali:channelProgramDates:${date.format(
|
||||||
|
'YYYY-MM-DD'
|
||||||
return `https://mts.rs/oec/epg/program?date=${date.format('YYYY-MM-DD')}&position=${position}`
|
)}&pageSize=10000`
|
||||||
},
|
},
|
||||||
request: {
|
request: {
|
||||||
headers: {
|
maxContentLength: 10000000 // 10 Mb
|
||||||
'X-Requested-With': 'XMLHttpRequest'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel }) {
|
parser({ content, channel }) {
|
||||||
let programs = []
|
const items = parseItems(content, channel)
|
||||||
const data = parseContent(content, channel)
|
|
||||||
const items = parseItems(data)
|
return items.map(item => {
|
||||||
items.forEach(item => {
|
return {
|
||||||
programs.push({
|
|
||||||
title: item.title,
|
title: item.title,
|
||||||
category: item.category,
|
category: item.category,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
image: item.image,
|
image: item?.picture?.url || null,
|
||||||
start: parseStart(item),
|
start: dayjs(item.start),
|
||||||
stop: parseStop(item)
|
stop: dayjs(item.end)
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
|
||||||
},
|
},
|
||||||
async channels() {
|
async channels() {
|
||||||
let channels = []
|
const data = await axios
|
||||||
|
.get(module.exports.url({ date: dayjs() }))
|
||||||
|
.then(r => r.data)
|
||||||
|
.catch(console.error)
|
||||||
|
|
||||||
const totalPages = await getTotalPageCount()
|
return data.products.map(channel => ({
|
||||||
const pages = Array.from(Array(totalPages).keys())
|
lang: 'bs',
|
||||||
for (let page of pages) {
|
name: channel.name,
|
||||||
const data = await axios
|
site_id: encodeURIComponent(channel.code)
|
||||||
.get('https://mts.rs/oec/epg/program', {
|
}))
|
||||||
params: { page, date: dayjs().format('YYYY-MM-DD') },
|
|
||||||
headers: {
|
|
||||||
'X-Requested-With': 'XMLHttpRequest'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(r => r.data)
|
|
||||||
.catch(console.log)
|
|
||||||
|
|
||||||
data.channels.forEach(item => {
|
|
||||||
channels.push({
|
|
||||||
lang: 'bs',
|
|
||||||
site_id: `${item.position}#${item.id}`,
|
|
||||||
name: item.name
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return channels
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTotalPageCount() {
|
function parseItems(content, channel) {
|
||||||
const data = await axios
|
|
||||||
.get('https://mts.rs/oec/epg/program', {
|
|
||||||
params: { page: 0, date: dayjs().format('YYYY-MM-DD') },
|
|
||||||
headers: {
|
|
||||||
'X-Requested-With': 'XMLHttpRequest'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(r => r.data)
|
|
||||||
.catch(console.log)
|
|
||||||
|
|
||||||
return data.total_pages
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseContent(content, channel) {
|
|
||||||
const [, site_id] = channel.site_id.split('#')
|
|
||||||
let data
|
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(content)
|
const data = JSON.parse(content)
|
||||||
|
if (!data || !Array.isArray(data.products)) return []
|
||||||
|
|
||||||
|
const channelData = data.products.find(c => c.code === channel.site_id)
|
||||||
|
if (!channelData || !Array.isArray(channelData.programs)) return []
|
||||||
|
|
||||||
|
return channelData.programs
|
||||||
} catch {
|
} catch {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
if (!data || !data.channels || !data.channels.length) return null
|
|
||||||
|
|
||||||
return data.channels.find(c => c.id === site_id) || null
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStart(item) {
|
|
||||||
return dayjs.tz(item.full_start, 'Europe/Belgrade')
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStop(item) {
|
|
||||||
return dayjs.tz(item.full_end, 'Europe/Belgrade')
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseItems(data) {
|
|
||||||
return data && Array.isArray(data.items) ? data.items : []
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue