Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mojmaxtv.hrvatskitelekom.hr #2640

Merged
merged 5 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sites/mojmaxtv.hrvatskitelekom.hr/__data__/content_0.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sites/mojmaxtv.hrvatskitelekom.hr/__data__/content_21.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sites/mojmaxtv.hrvatskitelekom.hr/__data__/content_3.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const doFetch = require('@ntlab/sfetch')
const axios = require('axios')
const dayjs = require('dayjs')
const _ = require('lodash')

const cached = {}

module.exports = {
site: 'mojmaxtv.hrvatskitelekom.hr',
url({ date }) {
return `https://tv-hr-prod.yo-digital.com/hr-bifrost/epg/channel/schedules?date=${date.format(
'YYYY-MM-DD'
)}&hour_offset=0&hour_range=3&channelMap_id&filler=true&app_language=hr&natco_code=hr`
},
request: {
headers: {
app_key: 'GWaBW4RTloLwpUgYVzOiW5zUxFLmoMj5',
app_version: '02.0.1080',
'device-id': 'a78f079d-5527-46d8-af3f-9f0b6b6fb758',
'x-request-session-id': 'fc96c9de-7a3b-4b51-8b9d-5d9f9a3c3268',
'x-request-tracking-id': '05a8f0bc-f977-4754-b8ad-1d4d1bd742fb',
'x-user-agent': 'web|web|Chrome-128|02.0.1080|1'
},
cache: {
ttl: 24 * 60 * 60 * 1000 // 1 day
}
},
async parser({ content, channel, date }) {
const data = parseData(content)
if (!data) return []

let items = parseItems(data, channel)
if (!items.length) return []

const queue = [3, 6, 9, 12, 15, 18, 21]
.map(offset => {
const url = module.exports.url({ date }).replace('hour_offset=0', `hour_offset=${offset}`)
const params = module.exports.request

if (cached[url]) {
items = items.concat(parseItems(cached[url], channel))

return null
}

return { url, params }
})
.filter(Boolean)

await doFetch(queue, (_req, _data) => {
if (_data) {
cached[_req.url] = _data

items = items.concat(parseItems(_data, channel))
}
})

items = _.sortBy(items, i => dayjs(i.start_time).valueOf())

return items.map(item => ({
title: item.description,
categories: Array.isArray(item.genres) ? item.genres.map(g => g.name) : [],
season: item.season_number,
episode: item.episode_number ? parseInt(item.episode_number) : null,
date: item['release_year'] ? item['release_year'].toString() : null,
start: item.start_time,
stop: item.end_time
}))
},
async channels() {
const data = await axios
.get(
'https://tv-hr-prod.yo-digital.com/hr-bifrost/epg/channel?channelMap_id=&includeVirtualChannels=false&natco_key=l2lyvGVbUm2EKJE96ImQgcc8PKMZWtbE&app_language=hr&natco_code=hr',
module.exports.request
)
.then(r => r.data)
.catch(console.error)

return data.channels.map(channel => ({
lang: 'hr',
name: channel.title,
site_id: channel.station_id
}))
}
}

function parseData(content) {
try {
const data = JSON.parse(content)

return data || null
} catch {
return null
}
}

function parseItems(data, channel) {
if (!data.channels || !Array.isArray(data.channels[channel.site_id])) return []

return data.channels[channel.site_id]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const { parser, url, request } = require('./mojmaxtv.hrvatskitelekom.hr.config.js')
const fs = require('fs')
const path = require('path')
const axios = require('axios')
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-01-24', 'YYYY-MM-DD').startOf('d')
const channel = { site_id: '274913832105', xmltv_id: 'HRT1.hr' }

jest.mock('axios')

axios.get.mockImplementation(url => {
if (
url ===
'https://tv-hr-prod.yo-digital.com/hr-bifrost/epg/channel/schedules?date=2025-01-24&hour_offset=3&hour_range=3&channelMap_id&filler=true&app_language=hr&natco_code=hr'
) {
return Promise.resolve({
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/content_3.json')))
})
} else if (
url ===
'https://tv-hr-prod.yo-digital.com/hr-bifrost/epg/channel/schedules?date=2025-01-24&hour_offset=21&hour_range=3&channelMap_id&filler=true&app_language=hr&natco_code=hr'
) {
return Promise.resolve({
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/content_21.json')))
})
} else {
return Promise.resolve({
data: {}
})
}
})

it('can generate valid url', () => {
expect(url({ date })).toBe(
'https://tv-hr-prod.yo-digital.com/hr-bifrost/epg/channel/schedules?date=2025-01-24&hour_offset=0&hour_range=3&channelMap_id&filler=true&app_language=hr&natco_code=hr'
)
})

it('can generate valid request headers', () => {
expect(request.headers).toMatchObject({
app_key: 'GWaBW4RTloLwpUgYVzOiW5zUxFLmoMj5',
app_version: '02.0.1080',
'device-id': 'a78f079d-5527-46d8-af3f-9f0b6b6fb758',
'x-request-session-id': 'fc96c9de-7a3b-4b51-8b9d-5d9f9a3c3268',
'x-request-tracking-id': '05a8f0bc-f977-4754-b8ad-1d4d1bd742fb',
'x-user-agent': 'web|web|Chrome-128|02.0.1080|1'
})
})

it('can parse response', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_0.json'))

const results = await parser({ content, channel, date })

expect(results.length).toBe(17)
expect(results[0]).toMatchObject({
title: 'Planet Zemlja: Junaci',
categories: ['Dokumentarni'],
season: 3,
episode: 8,
date: '2023',
start: '2025-01-23T23:16:00.00Z',
stop: '2025-01-24T00:08:00.00Z'
})
expect(results[16]).toMatchObject({
title: 'Harry Haft, film',
categories: ['Film', 'Drama', 'Biografski'],
season: null,
episode: null,
date: '2021',
start: '2025-01-24T21:50:00.00Z',
stop: '2025-01-25T00:00:00.00Z'
})
})

it('can handle empty guide', async () => {
const results = await parser({
date,
channel,
content: '{}'
})

expect(results).toMatchObject([])
})
21 changes: 21 additions & 0 deletions sites/mojmaxtv.hrvatskitelekom.hr/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# mojmaxtv.hrvatskitelekom.hr

https://mojmaxtv.hrvatskitelekom.hr/epg

### Download the guide

```sh
npm run grab --- --site=mojmaxtv.hrvatskitelekom.hr
```

### Update channel list

```sh
npm run channels:parse --- --config=./sites/mojmaxtv.hrvatskitelekom.hr/mojmaxtv.hrvatskitelekom.hr.config.js --output=./sites/mojmaxtv.hrvatskitelekom.hr/mojmaxtv.hrvatskitelekom.hr.channels.xml
```

### Test

```sh
npm test --- mojmaxtv.hrvatskitelekom.hr
```
Loading