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 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 : []
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(utc)
|
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 = {
|
const channel = {
|
||||||
site_id: '101#597',
|
site_id: 'rts_1_hd',
|
||||||
xmltv_id: 'RTS1.rs'
|
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', () => {
|
it('can generate valid url', () => {
|
||||||
const result = url({ date, channel })
|
expect(url({ date })).toBe(
|
||||||
expect(result).toBe('https://mts.rs/oec/epg/program?date=2021-11-07&position=101')
|
'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 generate valid request headers', () => {
|
|
||||||
expect(request.headers).toMatchObject({
|
|
||||||
'X-Requested-With': 'XMLHttpRequest'
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response', () => {
|
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.start = p.start.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
return p
|
return p
|
||||||
})
|
})
|
||||||
expect(result).toMatchObject([
|
|
||||||
{
|
expect(results.length).toBe(31)
|
||||||
start: '2021-11-06T22:44:00.000Z',
|
expect(results[0]).toMatchObject({
|
||||||
stop: '2021-11-07T00:43:00.000Z',
|
start: '2025-01-22T23:25:00.000Z',
|
||||||
title: 'Zaboravljeni zlo\u010din',
|
stop: '2025-01-23T00:15:00.000Z',
|
||||||
category: 'Bioskopski film',
|
title: 'Jeloustoun',
|
||||||
image:
|
category: 'Tv-serijali',
|
||||||
'https://mts.rs/oec/images/epg/2_abb81cc24d8ce957eece50f991a31e59780e4e53_E7D8ECDE568E84E3C86CCDBDB647355E.jpg',
|
image:
|
||||||
description:
|
'https://mediasb2c.mts.rs/medias/5-72517fcb4505f9d7809814598fed5ce6d84571a1-99415C04AED37264BC49C11115B94633.jpg?context=bWFzdGVyfHJvb3R8Nzc4MjN8aW1hZ2UvanBlZ3xhRFpsTDJoa01pODBOakF6T0RnME9UVTROVEU0TWk4MVh6Y3lOVEUzWm1OaU5EVXdOV1k1WkRjNE1EazRNVFExT1RobVpXUTFZMlUyWkRnME5UY3hZVEZmT1RrME1UVkRNRFJCUlVRek56STJORUpETkRsRE1URXhNVFZDT1RRMk16TXVhbkJufGUwZDIyMWU4MDIxZWVhZjY5MDY0ODQ0YjI5OWVjMGJjMDNlNWI3ZjMwNmE0MjYwMWJlMWQxNGFiMzNlMzU1NDE',
|
||||||
'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.'
|
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.'
|
||||||
])
|
})
|
||||||
|
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', () => {
|
it('can handle empty guide', () => {
|
||||||
const result = parser({
|
const result = parser({
|
||||||
date,
|
|
||||||
channel,
|
channel,
|
||||||
content: '{"message":"Nema rezultata."}'
|
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||||
})
|
})
|
||||||
expect(result).toMatchObject([])
|
expect(result).toMatchObject([])
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue