Files
epg/sites/mts.rs/mts.rs.config.js

106 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-11-22 17:12:48 +03:00
const axios = require('axios')
2023-10-15 14:08:23 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(timezone)
module.exports = {
site: 'mts.rs',
days: 2,
url({ date, channel }) {
const [position] = channel.site_id.split('#')
return `https://mts.rs/oec/epg/program?date=${date.format('YYYY-MM-DD')}&position=${position}`
},
request: {
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
},
parser: function ({ content, channel }) {
let programs = []
const data = parseContent(content, channel)
const items = parseItems(data)
items.forEach(item => {
programs.push({
title: item.title,
category: item.category,
description: item.description,
2024-06-24 16:49:35 +03:00
image: item.image,
2023-10-15 14:08:23 +03:00
start: parseStart(item),
stop: parseStop(item)
})
})
return programs
2023-11-22 17:12:48 +03:00
},
async channels() {
let channels = []
const totalPages = await getTotalPageCount()
const pages = Array.from(Array(totalPages).keys())
for (let page of pages) {
const data = await axios
2025-01-01 12:27:22 +03:00
.get('https://mts.rs/oec/epg/program', {
2023-11-22 17:12:48 +03:00
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
2023-10-15 14:08:23 +03:00
}
}
2023-11-22 17:12:48 +03:00
async function getTotalPageCount() {
const data = await axios
2025-01-01 12:27:22 +03:00
.get('https://mts.rs/oec/epg/program', {
2023-11-22 17:12:48 +03:00
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
}
2023-10-15 14:08:23 +03:00
function parseContent(content, channel) {
const [, site_id] = channel.site_id.split('#')
let data
try {
data = JSON.parse(content)
2025-01-01 12:27:22 +03:00
} catch {
return []
2023-10-15 14:08:23 +03:00
}
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 : []
}