-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2640 from iptv-org/add-mojmaxtv.hrvatskitelekom.hr
Add mojmaxtv.hrvatskitelekom.hr
- Loading branch information
Showing
7 changed files
with
460 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
246 changes: 246 additions & 0 deletions
246
sites/mojmaxtv.hrvatskitelekom.hr/mojmaxtv.hrvatskitelekom.hr.channels.xml
Large diffs are not rendered by default.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
sites/mojmaxtv.hrvatskitelekom.hr/mojmaxtv.hrvatskitelekom.hr.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
89 changes: 89 additions & 0 deletions
89
sites/mojmaxtv.hrvatskitelekom.hr/mojmaxtv.hrvatskitelekom.hr.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([]) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |