mirror of
https://github.com/iptv-org/epg
synced 2026-05-04 16:37:02 -04:00
Test: ```sh npm test -- tv.nu > test > run-script-os tv.nu > test:win32 > SET "TZ=Pacific/Nauru" && npx jest --runInBand tv.nu PASS sites/tv.nu/tv.nu.test.js (6.72 s) √ can generate valid url (5 ms) √ can parse response (7 ms) √ can handle empty guide (1 ms) Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 0 total Time: 7.246 s Ran all test suites matching /tv.nu/i. ``` Grab: ```sh npm run grab -- --site=tv.nu > grab > npx tsx scripts/commands/epg/grab.ts --site=tv.nu starting... config: output: guide.xml maxConnections: 1 gzip: false site: tv.nu loading channels... found 199 channel(s) run #1: [1/398] tv.nu (da) - dk4.dk - Dec 4, 2024 (41 programs) [2/398] tv.nu (da) - dk4.dk - Dec 5, 2024 (43 programs) ... [397/398] tv.nu (sv) - VSportUltraHD.se - Dec 4, 2024 (7 programs) [398/398] tv.nu (sv) - VSportUltraHD.se - Dec 5, 2024 (7 programs) saving to "guide.xml"... done in 00h 02m 40s ``` Signed-off-by: Toha <tohenk@yahoo.com>
88 lines
2.4 KiB
JavaScript
88 lines
2.4 KiB
JavaScript
const dayjs = require('dayjs')
|
|
|
|
module.exports = {
|
|
site: 'tv.nu',
|
|
days: 2,
|
|
url: function ({ channel, date }) {
|
|
return `https://web-api.tv.nu/channels/${channel.site_id}/schedule?date=${date.format(
|
|
'YYYY-MM-DD'
|
|
)}&fullDay=true`
|
|
},
|
|
parser: function ({ content }) {
|
|
let programs = []
|
|
const items = parseItems(content)
|
|
items.forEach(item => {
|
|
programs.push({
|
|
title: item.title,
|
|
description: item.description,
|
|
category: Array.isArray(item.genres) ? item.genres.map(genre => genre.name) : null,
|
|
season: item.seasonNumber || null,
|
|
episode: item.episodeNumber || null,
|
|
start: parseStart(item),
|
|
stop: parseStop(item)
|
|
})
|
|
})
|
|
|
|
return programs
|
|
},
|
|
async channels() {
|
|
const channels = []
|
|
const axios = require('axios')
|
|
const result = await axios
|
|
.get('https://www.tv.nu/alla-kanaler')
|
|
.then(response => response.data)
|
|
.catch(console.error)
|
|
|
|
if (result) {
|
|
const [, data] = result.match(/\\"allModules\\":(\[(.*?)\])/i) || [null, null]
|
|
const modules = JSON.parse(data.replace(/\\/g, ''))
|
|
if (Array.isArray(modules) && modules.length) {
|
|
let offset = 0
|
|
while (offset !== undefined) {
|
|
const data = await axios
|
|
.get(`https://web-api.tv.nu/tableauLinearChannels`, {
|
|
params: {
|
|
modules,
|
|
date: dayjs().format('YYYY-MM-DD'),
|
|
limit: 12,
|
|
offset
|
|
}
|
|
})
|
|
.then(r => r.data)
|
|
.catch(console.error)
|
|
|
|
data.data.modules.forEach(item => {
|
|
channels.push({
|
|
lang: 'sv',
|
|
name: item.content.name,
|
|
site_id: item.content.slug
|
|
})
|
|
})
|
|
offset = data.data.nextOffset
|
|
}
|
|
}
|
|
}
|
|
|
|
return channels
|
|
}
|
|
}
|
|
|
|
function parseStart(item) {
|
|
if (!item.broadcast || !item.broadcast.startTime) return null
|
|
|
|
return dayjs(item.broadcast.startTime)
|
|
}
|
|
|
|
function parseStop(item) {
|
|
if (!item.broadcast || !item.broadcast.endTime) return null
|
|
|
|
return dayjs(item.broadcast.endTime)
|
|
}
|
|
|
|
function parseItems(content) {
|
|
const data = JSON.parse(content)
|
|
if (!data || !data.data || !Array.isArray(data.data.broadcasts)) return []
|
|
|
|
return data.data.broadcasts
|
|
}
|