mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update mtel.ba.config.js
This commit is contained in:
parent
ac67940233
commit
a9f0012c23
1 changed files with 61 additions and 51 deletions
|
@ -1,23 +1,33 @@
|
||||||
const axios = require('axios')
|
const _ = require('lodash')
|
||||||
|
const doFetch = require('@ntlab/sfetch')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
|
const utc = require('dayjs/plugin/utc')
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
|
dayjs.extend(utc)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'mtel.ba',
|
site: 'mtel.ba',
|
||||||
days: 2,
|
days: 2,
|
||||||
url: function ({ channel, date }) {
|
url({ channel, date }) {
|
||||||
const [position] = channel.site_id.split('#')
|
const [platform] = channel.site_id.split('#')
|
||||||
|
|
||||||
return `https://mtel.ba/oec/epg/program?date=${date.format('YYYY-MM-DD')}&position=${position}`
|
return `https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/epg?platform=tv-${platform}¤tPage=0&pageSize=1000&date=${date.format(
|
||||||
|
'YYYY-MM-DD'
|
||||||
|
)}`
|
||||||
},
|
},
|
||||||
request: {
|
request: {
|
||||||
headers: {
|
timeout: 20000, // 20 seconds
|
||||||
'X-Requested-With': 'XMLHttpRequest'
|
maxContentLength: 10000000, // 10 Mb
|
||||||
|
cache: {
|
||||||
|
interpretHeader: false,
|
||||||
|
ttl: 24 * 60 * 60 * 1000 // 1 day
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel }) {
|
parser({ content, channel }) {
|
||||||
let programs = []
|
let programs = []
|
||||||
const items = parseItems(content, channel)
|
const items = parseItems(content, channel)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
|
@ -25,76 +35,76 @@ module.exports = {
|
||||||
programs.push({
|
programs.push({
|
||||||
title: item.title,
|
title: item.title,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
category: item.category,
|
categories: parseCategories(item),
|
||||||
image: item.image,
|
image: parseImage(item),
|
||||||
start: parseStart(item).toJSON(),
|
start: parseStart(item),
|
||||||
stop: parseStop(item).toJSON()
|
stop: parseStop(item)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
},
|
},
|
||||||
async channels() {
|
async channels({ platform = 'msat' }) {
|
||||||
|
const platforms = {
|
||||||
|
msat: 'https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/search?pageSize=100¤tPage=<CURRENT_PAGE>&query=:relevantno:tv-kategorija:tv-msat',
|
||||||
|
iptv: 'https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/search?pageSize=100¤tPage=<CURRENT_PAGE>&query=:relevantno:tv-kategorija:tv-iptv:tv-iptv-paket:Svi+kanali'
|
||||||
|
}
|
||||||
|
|
||||||
|
const queue = [
|
||||||
|
{
|
||||||
|
platform,
|
||||||
|
url: platforms[platform].replace('<CURRENT_PAGE>', 0)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
let channels = []
|
let channels = []
|
||||||
|
await doFetch(queue, (req, data) => {
|
||||||
const totalPages = await getTotalPageCount()
|
if (data && data.pagination.currentPage < data.pagination.totalPages) {
|
||||||
const pages = Array.from(Array(totalPages).keys())
|
queue.push({
|
||||||
for (let page of pages) {
|
platform: req.platform,
|
||||||
const data = await axios
|
url: platforms[req.platform].replace('<CURRENT_PAGE>', ++data.pagination.currentPage)
|
||||||
.get('https://mtel.ba/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 => {
|
data.products.forEach(channel => {
|
||||||
channels.push({
|
channels.push({
|
||||||
lang: 'bs',
|
lang: 'bs',
|
||||||
site_id: `${item.position}#${item.id}`,
|
name: channel.name,
|
||||||
name: item.name
|
site_id: `${req.platform}#${channel.code}`
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
|
||||||
return channels
|
return channels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTotalPageCount() {
|
|
||||||
const data = await axios
|
|
||||||
.get('https://mtel.ba/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 parseStart(item) {
|
function parseStart(item) {
|
||||||
return dayjs.tz(item.full_start, 'Europe/Sarajevo')
|
return dayjs.tz(item.start, 'YYYY-MM-DD HH:mm', 'Europe/Sarajevo')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStop(item) {
|
function parseStop(item) {
|
||||||
return dayjs.tz(item.full_end, 'Europe/Sarajevo')
|
return dayjs.tz(item.end, 'YYYY-MM-DD HH:mm', 'Europe/Sarajevo')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseContent(content, channel) {
|
function parseCategories(item) {
|
||||||
const [, channelId] = channel.site_id.split('#')
|
return item.category ? item.category.split(' / ') : []
|
||||||
const data = JSON.parse(content)
|
}
|
||||||
if (!data || !Array.isArray(data.channels)) return null
|
|
||||||
|
|
||||||
return data.channels.find(i => i.id === channelId)
|
function parseImage(item) {
|
||||||
|
return item?.picture?.url ? item.picture.url : null
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, channel) {
|
function parseItems(content, channel) {
|
||||||
const data = parseContent(content, channel)
|
try {
|
||||||
|
const data = JSON.parse(content)
|
||||||
|
if (!data || !Array.isArray(data.products)) return []
|
||||||
|
const [, channelId] = channel.site_id.split('#')
|
||||||
|
const channelData = data.products.find(channel => channel.code === channelId)
|
||||||
|
if (!channelData || !Array.isArray(channelData.programs)) return []
|
||||||
|
|
||||||
return data ? data.items : []
|
return _.sortBy(channelData.programs, p => parseStart(p).valueOf())
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue