mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
commit
6b3dea313e
5 changed files with 525 additions and 702 deletions
1
sites/mts.rs/__data__/content.json
Normal file
1
sites/mts.rs/__data__/content.json
Normal file
File diff suppressed because one or more lines are too long
1
sites/mts.rs/__data__/no_content.json
Normal file
1
sites/mts.rs/__data__/no_content.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"freeTextSearch":"","products":[],"sorts":[{"code":"pozicija-rastuce","name":"Pozicija - Rastuće","selected":true}],"pagination":{"pageSize":10000,"currentPage":0,"sort":"pozicija-rastuce","totalPages":0,"totalResults":0},"currentQuery":{"url":"/search?q=%3Apozicija-rastuce%3Atip-kanala-radio%3ATV%2Bkanali%3AchannelProgramDates%3A2026-01-23%3Atv-kategorija%3Airis-tv-paketi","query":{"value":":pozicija-rastuce:tip-kanala-radio:TV+kanali:channelProgramDates:2026-01-23:tv-kategorija:iris-tv-paketi"}},"breadcrumbs":[{"facetCode":"tip-kanala-radio","facetName":"Tip kanala","facetValueCode":"TV kanali","facetValueName":"TV kanali","removeQuery":{"url":"/search?q=%3Apozicija-rastuce%3AchannelProgramDates%3A2026-01-23%3Atv-kategorija%3Airis-tv-paketi","query":{"value":":pozicija-rastuce:channelProgramDates:2026-01-23:tv-kategorija:iris-tv-paketi"}},"truncateQuery":{"url":"/search?q=%3Apozicija-rastuce%3Atip-kanala-radio%3ATV%2Bkanali","query":{"value":":pozicija-rastuce:tip-kanala-radio:TV+kanali"}}},{"facetCode":"tv-kategorija","facetName":"Kategorija","facetValueCode":"iris-tv-paketi","facetValueName":"IRIS TV","removeQuery":{"url":"/search?q=%3Apozicija-rastuce%3Atip-kanala-radio%3ATV%2Bkanali%3AchannelProgramDates%3A2026-01-23","query":{"value":":pozicija-rastuce:tip-kanala-radio:TV+kanali:channelProgramDates:2026-01-23"}}}],"facets":[]}
|
File diff suppressed because it is too large
Load diff
|
@ -1,105 +1,55 @@
|
|||
const axios = require('axios')
|
||||
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}`
|
||||
url({ date }) {
|
||||
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'
|
||||
)}&pageSize=10000`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
maxContentLength: 10000000 // 10 Mb
|
||||
},
|
||||
parser: function ({ content, channel }) {
|
||||
let programs = []
|
||||
const data = parseContent(content, channel)
|
||||
const items = parseItems(data)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
parser({ content, channel }) {
|
||||
const items = parseItems(content, channel)
|
||||
|
||||
return items.map(item => {
|
||||
return {
|
||||
title: item.title,
|
||||
category: item.category,
|
||||
description: item.description,
|
||||
image: item.image,
|
||||
start: parseStart(item),
|
||||
stop: parseStop(item)
|
||||
image: item?.picture?.url || null,
|
||||
start: dayjs(item.start),
|
||||
stop: dayjs(item.end)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
let channels = []
|
||||
|
||||
const totalPages = await getTotalPageCount()
|
||||
const pages = Array.from(Array(totalPages).keys())
|
||||
for (let page of pages) {
|
||||
const data = await axios
|
||||
.get('https://mts.rs/oec/epg/program', {
|
||||
params: { page, date: dayjs().format('YYYY-MM-DD') },
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
})
|
||||
.get(module.exports.url({ date: dayjs() }))
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
.catch(console.error)
|
||||
|
||||
data.channels.forEach(item => {
|
||||
channels.push({
|
||||
return data.products.map(channel => ({
|
||||
lang: 'bs',
|
||||
site_id: `${item.position}#${item.id}`,
|
||||
name: item.name
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return channels
|
||||
name: channel.name,
|
||||
site_id: encodeURIComponent(channel.code)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
async function getTotalPageCount() {
|
||||
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
|
||||
function parseItems(content, channel) {
|
||||
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 {
|
||||
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 : []
|
||||
}
|
||||
|
|
|
@ -1,54 +1,59 @@
|
|||
const { parser, url, request } = require('./mts.rs.config.js')
|
||||
const { parser, url } = require('./mts.rs.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('2021-11-07', 'YYYY-MM-DD').startOf('d')
|
||||
const date = dayjs.utc('2025-01-23', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '101#597',
|
||||
xmltv_id: 'RTS1.rs'
|
||||
site_id: 'rts_1_hd',
|
||||
xmltv_id: 'RTS1HD.rs'
|
||||
}
|
||||
const content =
|
||||
'{"page":0,"total_pages":1,"date":"2021-11-07","channels":[{"id":"597","name":"RTS 1","description":null,"link":null,"image":"https://mts.rs/oec/images/tv_channels/904ddd8cd6720a4a1c23eae513b5b957.jpg","position":"101","positions":"101","items":[{"id_channel":"597","title":"Zaboravljeni zlo\u010din","description":"Novinarka-fotoreporter, D\u017ein, istra\u017euje okrutno i senzacionalno, nere\u0161eno ubistvo sekirom iz davne 1873. godine. Ubistvo koje koincidira sa nedavnim identi\u010dnim brutalnim dvostrukim ubistvom. Zaplet se odvija izme\u0111u pri\u010de o\u010devica iz toga doba - pri\u010de iz novinske arhive i D\u017einine privatne borbe sa ljubomorom i sumnjom koje prate njen brak.","start":"00:00:00","duration":"103.00","full_start":"2021-11-06 23:44:00","full_end":"2021-11-07 01:43:00","image":"https://mts.rs/oec/images/epg/2_abb81cc24d8ce957eece50f991a31e59780e4e53_E7D8ECDE568E84E3C86CCDBDB647355E.jpg","category":"Bioskopski film","subcategory":""}]}]}'
|
||||
|
||||
it('can generate valid url', () => {
|
||||
const result = url({ date, channel })
|
||||
expect(result).toBe('https://mts.rs/oec/epg/program?date=2021-11-07&position=101')
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
})
|
||||
expect(url({ date })).toBe(
|
||||
'https://mts.rs/hybris/ecommerce/b2c/v1/products/search?sort=pozicija-rastuce&searchQueryContext=CHANNEL_PROGRAM&query=:pozicija-rastuce:tip-kanala-radio:TV kanali:channelProgramDates:2025-01-23&pageSize=10000'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const result = parser({ date, channel, content }).map(p => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const results = parser({ channel, content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2021-11-06T22:44:00.000Z',
|
||||
stop: '2021-11-07T00:43:00.000Z',
|
||||
title: 'Zaboravljeni zlo\u010din',
|
||||
category: 'Bioskopski film',
|
||||
|
||||
expect(results.length).toBe(31)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-01-22T23:25:00.000Z',
|
||||
stop: '2025-01-23T00:15:00.000Z',
|
||||
title: 'Jeloustoun',
|
||||
category: 'Tv-serijali',
|
||||
image:
|
||||
'https://mts.rs/oec/images/epg/2_abb81cc24d8ce957eece50f991a31e59780e4e53_E7D8ECDE568E84E3C86CCDBDB647355E.jpg',
|
||||
'https://mediasb2c.mts.rs/medias/5-72517fcb4505f9d7809814598fed5ce6d84571a1-99415C04AED37264BC49C11115B94633.jpg?context=bWFzdGVyfHJvb3R8Nzc4MjN8aW1hZ2UvanBlZ3xhRFpsTDJoa01pODBOakF6T0RnME9UVTROVEU0TWk4MVh6Y3lOVEUzWm1OaU5EVXdOV1k1WkRjNE1EazRNVFExT1RobVpXUTFZMlUyWkRnME5UY3hZVEZmT1RrME1UVkRNRFJCUlVRek56STJORUpETkRsRE1URXhNVFZDT1RRMk16TXVhbkJufGUwZDIyMWU4MDIxZWVhZjY5MDY0ODQ0YjI5OWVjMGJjMDNlNWI3ZjMwNmE0MjYwMWJlMWQxNGFiMzNlMzU1NDE',
|
||||
description:
|
||||
'Novinarka-fotoreporter, D\u017ein, istra\u017euje okrutno i senzacionalno, nere\u0161eno ubistvo sekirom iz davne 1873. godine. Ubistvo koje koincidira sa nedavnim identi\u010dnim brutalnim dvostrukim ubistvom. Zaplet se odvija izme\u0111u pri\u010de o\u010devica iz toga doba - pri\u010de iz novinske arhive i D\u017einine privatne borbe sa ljubomorom i sumnjom koje prate njen brak.'
|
||||
}
|
||||
])
|
||||
'Serija prati život Džona Datona, koga tumači oskarovac Kevin Kostner, koji mora da se bori sa spoljnim i unutrašnjim pretnjama kako bi zaštitio svoju porodicu, ranč i imanje. Smeštena u divlje prostranstvo Montane, serija istražuje složene moralne dileme, borbe za opstanak i porodične sukobe u modernom zapadnom okruženju. Sa prelepim pejzažima i napetim zapletima, Jeloustoun nudi priču o ljubavi, lojalnosti, moći i borbi za očuvanje tradicije. Kevin Kostner nije samo glumac u seriji, već i jedan od producenata. Njegovo bogato iskustvo u filmskoj industriji, uključujući režiju i produkciju, pomoglo je da Jeloustoun bude verodostojan i autentičan prikaz života na ranču. Serija je dobila silne nagrade, a među njima i Zlatni globus za najbolju televizijsku seriju (drama) 2021. godine, dok je Kevin Kostner je osvojio nagradu za Najboljeg glumca u dramskoj televizijskoj seriji, iste godine godine. Nekoliko puta je bila nominovana za nagradu Emi.'
|
||||
})
|
||||
expect(results[30]).toMatchObject({
|
||||
start: '2025-01-23T23:30:00.000Z',
|
||||
stop: '2025-01-24T00:20:00.000Z',
|
||||
title: 'Jeloustoun',
|
||||
category: 'Tv-serijali',
|
||||
image:
|
||||
'https://mediasb2c.mts.rs/medias/5-72517fcb4505f9d7809814598fed5ce6d84571a1-99415C04AED37264BC49C11115B94633.jpg?context=bWFzdGVyfHJvb3R8Nzc4MjN8aW1hZ2UvanBlZ3xhRFpsTDJoa01pODBOakF6T0RnME9UVTROVEU0TWk4MVh6Y3lOVEUzWm1OaU5EVXdOV1k1WkRjNE1EazRNVFExT1RobVpXUTFZMlUyWkRnME5UY3hZVEZmT1RrME1UVkRNRFJCUlVRek56STJORUpETkRsRE1URXhNVFZDT1RRMk16TXVhbkJufGUwZDIyMWU4MDIxZWVhZjY5MDY0ODQ0YjI5OWVjMGJjMDNlNWI3ZjMwNmE0MjYwMWJlMWQxNGFiMzNlMzU1NDE',
|
||||
description:
|
||||
'Serija prati život Džona Datona, koga tumači oskarovac Kevin Kostner, koji mora da se bori sa spoljnim i unutrašnjim pretnjama kako bi zaštitio svoju porodicu, ranč i imanje. Smeštena u divlje prostranstvo Montane, serija istražuje složene moralne dileme, borbe za opstanak i porodične sukobe u modernom zapadnom okruženju. Sa prelepim pejzažima i napetim zapletima, Jeloustoun nudi priču o ljubavi, lojalnosti, moći i borbi za očuvanje tradicije. Kevin Kostner nije samo glumac u seriji, već i jedan od producenata. Njegovo bogato iskustvo u filmskoj industriji, uključujući režiju i produkciju, pomoglo je da Jeloustoun bude verodostojan i autentičan prikaz života na ranču. Serija je dobila silne nagrade, a među njima i Zlatni globus za najbolju televizijsku seriju (drama) 2021. godine, dok je Kevin Kostner je osvojio nagradu za Najboljeg glumca u dramskoj televizijskoj seriji, iste godine godine. Nekoliko puta je bila nominovana za nagradu Emi.'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: '{"message":"Nema rezultata."}'
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue