mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 10:26:41 -05:00
Replaced LF endings with CRLF
This commit is contained in:
@@ -1,110 +1,110 @@
|
||||
const doFetch = require('@ntlab/sfetch')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const { sortBy } = require('../../scripts/functions')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'mtel.ba',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
const [platform] = channel.site_id.split('#')
|
||||
|
||||
return `https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/epg?platform=tv-${platform}&pageSize=999&date=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}`
|
||||
},
|
||||
request: {
|
||||
timeout: 20000, // 20 seconds
|
||||
maxContentLength: 10000000, // 10 Mb
|
||||
cache: {
|
||||
interpretHeader: false,
|
||||
ttl: 24 * 60 * 60 * 1000 // 1 day
|
||||
}
|
||||
},
|
||||
parser({ content, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
categories: parseCategories(item),
|
||||
image: parseImage(item),
|
||||
start: parseStart(item),
|
||||
stop: parseStop(item)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ platform = 'msat' }) {
|
||||
const platforms = {
|
||||
msat: 'https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/search?pageSize=999&query=:relevantno:tv-kategorija:tv-msat',
|
||||
iptv: 'https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/search?pageSize=999&query=:relevantno:tv-kategorija:tv-iptv'
|
||||
}
|
||||
|
||||
const queue = [
|
||||
{
|
||||
platform,
|
||||
url: platforms[platform]
|
||||
}
|
||||
]
|
||||
|
||||
let channels = []
|
||||
await doFetch(queue, (req, data) => {
|
||||
if (data && data.pagination.currentPage < data.pagination.totalPages) {
|
||||
queue.push({
|
||||
platform: req.platform,
|
||||
url: platforms[req.platform]
|
||||
})
|
||||
}
|
||||
|
||||
data.products.forEach(channel => {
|
||||
channels.push({
|
||||
lang: 'bs',
|
||||
name: channel.name,
|
||||
site_id: `${req.platform}#${channel.code}`
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart(item) {
|
||||
return dayjs.tz(item.start, 'YYYY-MM-DD HH:mm', 'Europe/Sarajevo')
|
||||
}
|
||||
|
||||
function parseStop(item) {
|
||||
return dayjs.tz(item.end, 'YYYY-MM-DD HH:mm', 'Europe/Sarajevo')
|
||||
}
|
||||
|
||||
function parseCategories(item) {
|
||||
return item.category ? item.category.split(' / ') : []
|
||||
}
|
||||
|
||||
function parseImage(item) {
|
||||
return item?.picture?.url ? item.picture.url : null
|
||||
}
|
||||
|
||||
function parseItems(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 []
|
||||
// filter out programs that have the sentence "no program information available"
|
||||
channelData.programs = channelData.programs.filter(p => !p.title.includes('Nema informacija o programu'))
|
||||
return sortBy(channelData.programs, p => parseStart(p).valueOf())
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
const doFetch = require('@ntlab/sfetch')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const { sortBy } = require('../../scripts/functions')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'mtel.ba',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
const [platform] = channel.site_id.split('#')
|
||||
|
||||
return `https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/epg?platform=tv-${platform}&pageSize=999&date=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}`
|
||||
},
|
||||
request: {
|
||||
timeout: 20000, // 20 seconds
|
||||
maxContentLength: 10000000, // 10 Mb
|
||||
cache: {
|
||||
interpretHeader: false,
|
||||
ttl: 24 * 60 * 60 * 1000 // 1 day
|
||||
}
|
||||
},
|
||||
parser({ content, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
categories: parseCategories(item),
|
||||
image: parseImage(item),
|
||||
start: parseStart(item),
|
||||
stop: parseStop(item)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ platform = 'msat' }) {
|
||||
const platforms = {
|
||||
msat: 'https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/search?pageSize=999&query=:relevantno:tv-kategorija:tv-msat',
|
||||
iptv: 'https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/search?pageSize=999&query=:relevantno:tv-kategorija:tv-iptv'
|
||||
}
|
||||
|
||||
const queue = [
|
||||
{
|
||||
platform,
|
||||
url: platforms[platform]
|
||||
}
|
||||
]
|
||||
|
||||
let channels = []
|
||||
await doFetch(queue, (req, data) => {
|
||||
if (data && data.pagination.currentPage < data.pagination.totalPages) {
|
||||
queue.push({
|
||||
platform: req.platform,
|
||||
url: platforms[req.platform]
|
||||
})
|
||||
}
|
||||
|
||||
data.products.forEach(channel => {
|
||||
channels.push({
|
||||
lang: 'bs',
|
||||
name: channel.name,
|
||||
site_id: `${req.platform}#${channel.code}`
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart(item) {
|
||||
return dayjs.tz(item.start, 'YYYY-MM-DD HH:mm', 'Europe/Sarajevo')
|
||||
}
|
||||
|
||||
function parseStop(item) {
|
||||
return dayjs.tz(item.end, 'YYYY-MM-DD HH:mm', 'Europe/Sarajevo')
|
||||
}
|
||||
|
||||
function parseCategories(item) {
|
||||
return item.category ? item.category.split(' / ') : []
|
||||
}
|
||||
|
||||
function parseImage(item) {
|
||||
return item?.picture?.url ? item.picture.url : null
|
||||
}
|
||||
|
||||
function parseItems(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 []
|
||||
// filter out programs that have the sentence "no program information available"
|
||||
channelData.programs = channelData.programs.filter(p => !p.title.includes('Nema informacija o programu'))
|
||||
return sortBy(channelData.programs, p => parseStart(p).valueOf())
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
const { parser, url } = require('./mtel.ba.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2025-02-04', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = { site_id: 'msat#ch-11-rtrs' }
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/epg?platform=tv-msat&pageSize=999&date=2025-02-04'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ channel, content })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(38)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-02-03T22:38:00.000Z',
|
||||
stop: '2025-02-03T23:38:00.000Z',
|
||||
title: 'Neka pesma kaže',
|
||||
image:
|
||||
'https://medias.services.mtel.ba/medias/407368591.jpg?context=bWFzdGVyfHJvb3R8MTM2MTZ8aW1hZ2UvanBlZ3xhR1F5TDJnell5ODBOekExTmpFMk1qRTJNRFkzTUM4ME1EY3pOamcxT1RFdWFuQm58ZWM3Zjc4MDNlZTY5OWU1ZGJiZDI5N2UzMDg4ODA3NzQ1NWM0OThlMjdhYmU4MjI4NGJhOWE2YzYwMTc5ODM3NQ',
|
||||
description:
|
||||
'Zabavni-muzički program donosi nam divne zvukove prave, narodne muzike, u kojoj se izvođači oslanjaju na kvalitet i tradiciju.',
|
||||
categories: ['Music', 'Ballet', 'Dance']
|
||||
})
|
||||
expect(results[37]).toMatchObject({
|
||||
start: '2025-02-04T22:27:00.000Z',
|
||||
stop: '2025-02-04T23:58:00.000Z',
|
||||
title: 'Bitanga s plaže',
|
||||
image:
|
||||
'https://medias.services.mtel.ba/medias/117604203.jpg?context=bWFzdGVyfHJvb3R8MTY1MTZ8aW1hZ2UvanBlZ3xhRGd6TDJnek1DODBOekExTmpFMk16STNORGM0TWk4eE1UYzJNRFF5TURNdWFuQm58YmU5MjdkOTljMGE4YjIyNjg3ZmI1YWJjYWQ0ZDY5YjA0YWJiY2RlN2E0ZGVjOTdlYzM4MzI4MzYyMzFiODBlMg',
|
||||
description:
|
||||
'Film prati urnebesne avanture Moondoga, buntovnika i skitnicu koji svoj život živi isključivo prema vlastitim pravilima. Uz glumačke nastupe Snoop Dogga, Zaca Efrona i Isle Fisher, Bitanga s plaže osvježavajuće je originalna i subverzivna nova komedija scenarista i redatelja Harmonyja Korinea.',
|
||||
categories: ['Movie', 'Drama']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({
|
||||
channel,
|
||||
content: '{}'
|
||||
})
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./mtel.ba.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2025-02-04', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = { site_id: 'msat#ch-11-rtrs' }
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://mtel.ba/hybris/ecommerce/b2c/v1/products/channels/epg?platform=tv-msat&pageSize=999&date=2025-02-04'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ channel, content })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(38)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-02-03T22:38:00.000Z',
|
||||
stop: '2025-02-03T23:38:00.000Z',
|
||||
title: 'Neka pesma kaže',
|
||||
image:
|
||||
'https://medias.services.mtel.ba/medias/407368591.jpg?context=bWFzdGVyfHJvb3R8MTM2MTZ8aW1hZ2UvanBlZ3xhR1F5TDJnell5ODBOekExTmpFMk1qRTJNRFkzTUM4ME1EY3pOamcxT1RFdWFuQm58ZWM3Zjc4MDNlZTY5OWU1ZGJiZDI5N2UzMDg4ODA3NzQ1NWM0OThlMjdhYmU4MjI4NGJhOWE2YzYwMTc5ODM3NQ',
|
||||
description:
|
||||
'Zabavni-muzički program donosi nam divne zvukove prave, narodne muzike, u kojoj se izvođači oslanjaju na kvalitet i tradiciju.',
|
||||
categories: ['Music', 'Ballet', 'Dance']
|
||||
})
|
||||
expect(results[37]).toMatchObject({
|
||||
start: '2025-02-04T22:27:00.000Z',
|
||||
stop: '2025-02-04T23:58:00.000Z',
|
||||
title: 'Bitanga s plaže',
|
||||
image:
|
||||
'https://medias.services.mtel.ba/medias/117604203.jpg?context=bWFzdGVyfHJvb3R8MTY1MTZ8aW1hZ2UvanBlZ3xhRGd6TDJnek1DODBOekExTmpFMk16STNORGM0TWk4eE1UYzJNRFF5TURNdWFuQm58YmU5MjdkOTljMGE4YjIyNjg3ZmI1YWJjYWQ0ZDY5YjA0YWJiY2RlN2E0ZGVjOTdlYzM4MzI4MzYyMzFiODBlMg',
|
||||
description:
|
||||
'Film prati urnebesne avanture Moondoga, buntovnika i skitnicu koji svoj život živi isključivo prema vlastitim pravilima. Uz glumačke nastupe Snoop Dogga, Zaca Efrona i Isle Fisher, Bitanga s plaže osvježavajuće je originalna i subverzivna nova komedija scenarista i redatelja Harmonyja Korinea.',
|
||||
categories: ['Movie', 'Drama']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({
|
||||
channel,
|
||||
content: '{}'
|
||||
})
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user