From 9c6978deba50ca480469a0892071e40718619bd0 Mon Sep 17 00:00:00 2001 From: Toha Date: Wed, 4 Dec 2024 12:59:29 +0700 Subject: [PATCH] Update tv.nu guide. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- sites/tv.nu/__data__/content.json | 1 + sites/tv.nu/__data__/no_content.json | 1 + sites/tv.nu/tv.nu.channels.xml | 165 +++++++++++++-------------- sites/tv.nu/tv.nu.config.js | 64 ++++++----- sites/tv.nu/tv.nu.test.js | 29 +++-- 5 files changed, 131 insertions(+), 129 deletions(-) create mode 100644 sites/tv.nu/__data__/content.json create mode 100644 sites/tv.nu/__data__/no_content.json diff --git a/sites/tv.nu/__data__/content.json b/sites/tv.nu/__data__/content.json new file mode 100644 index 00000000..4da359b6 --- /dev/null +++ b/sites/tv.nu/__data__/content.json @@ -0,0 +1 @@ +{"meta":{"status":200},"data":{"id":145,"name":"3sat","slug":"3sat","themedLogo":{"light":{"url":"https://new.static.tv.nu/19402383","isFallback":false},"dark":{"url":"https://new.static.tv.nu/59995595","isFallback":true}},"broadcasts":[{"type":"broadcast","id":"1TirWo-2l-dxVS","programId":"28689","isPlay":false,"isMovie":false,"isSeries":false,"isRerun":false,"isRecurring":false,"isLive":false,"title":"Natur im Garten","description":"Der Gartenbuchautor Karl Ploberger gibt in der Sendung Tipps und Tricks zur Gartenpflege.","year":2024,"genreNames":[],"genres":[{"name":"Konsument","slug":"konsument"},{"name":"Underhållning","slug":"underhallning"},{"name":"Trädgård","slug":"tradgard"}],"genreGroupNames":[],"genreGroups":[],"playProviders":[],"broadcast":{"id":"1TirWo-2l-dxVS","startTime":1733226600000,"endTime":1733228100000,"type":"broadcast"},"episodeNumber":9,"seasonNumber":29,"isIntermission":false}]}} \ No newline at end of file diff --git a/sites/tv.nu/__data__/no_content.json b/sites/tv.nu/__data__/no_content.json new file mode 100644 index 00000000..9a022d2e --- /dev/null +++ b/sites/tv.nu/__data__/no_content.json @@ -0,0 +1 @@ +{"meta":{"status":200},"data":{"broadcasts":[]}} \ No newline at end of file diff --git a/sites/tv.nu/tv.nu.channels.xml b/sites/tv.nu/tv.nu.channels.xml index e23e90f5..cd9b03c9 100644 --- a/sites/tv.nu/tv.nu.channels.xml +++ b/sites/tv.nu/tv.nu.channels.xml @@ -1,10 +1,83 @@ + DK4 + DK4 HD + DR1 + Kanal 4 + Kanal 5 Danmark + TV3 Danmark + 3sat + ARTE + Das Erste + DMAX + eSportsone + ProSieben + RTL + RTLZWEI + VOX + ZDF + Adult Channel + Al Jazeera English + BBC Earth + BBC Nordic + BraZZers TV Plus + China Global Television Network + CNBC + CNN International + CuriosityStream + E! + Euro News + Extreme Sports Channel + Fight Sports + France 24 English HD + FUEL TV + GINX eSports TV + GOD TV + High TV 3D + Hustler TV + Love Nature 4K UHD + Mezzo Live + MTV 90s + MTV Hits + MTV Live HD + Nautical Channel + NFL Network + NHK World Europe + OUTtv + Penthouse HD 1 + Penthouse HD 2 + Playboy TV Europe + History (UK) + Sky News + Stingray Classica + Djazz HD + Trace Urban HD + WILD TV HD + TV Chile + TVE Internacional + MTV3 + TV5 HD + TV Finland + Yle Teema & Fem + Yle TV1 + Yle TV2 + France 2 + TV5 Monde Europe + Rai 1 + Rai 2 + NRK1 + NRK3 + NRK Super / NRK3 HD + TV3 Norge + TV3+ + TV Norge HD + TVP Polonia Adult Channel Nightly BBC News Bloomberg TV HD (UK) - Curiosity Stream EU + CBS Reality MENA Disney Junior (lång tablå) + DW History HD (Internationell) Mitteldeutscher Rundfunk (MDF) MTV 00s Europe @@ -12,26 +85,16 @@ National Geographic HD National Geographic HD Nick JR (lång tablå) - True Crime - 3sat - Adult Channel - Al Jazeera English + V Sport Football Live 1 + V Sport Football Live 2 + V Sport Football Live 3 Animal Planet - ARTE ATG Live Axess TV - BBC Earth - BBC Nordic - BraZZers TV Plus Cartoonito Cartoon Network China Global Television Network 9 Documentary - China Global Television Network Club MTV - CNBC - CNN International - CuriosityStream - Das Erste Discovery Channel Discovery+ Extra 1 Discovery+ Extra 2 @@ -44,109 +107,56 @@ Discovery Science Disney Channel Disney Junior - DK4 - DK4 HD - DMAX - DR1 DR2 DR3 DR K DR Ramasjang DR Ultra - DW en alemán - E! - eSportsone - eSportsTV HD - Euro News Eurosport 1 Eurosport 2 - Expressen TV - Extreme Sports Channel FTV - Fight Sports - France 2 - France 24 English HD - FUEL TV - GINX eSports TV Godare - GOD TV - High TV 3D H2 History HD Horse & Country TV HRT1 - Hustler TV Investigation Discovery - Kanal 10 - Kanal 11 - Kanal 4 - Kanal 5 Danmark Kanal 5 Kanal 9 + Kanal 10 + Kanal 11 Kunskapskanalen - Love Nature 4K UHD Mezzo - Mezzo Live Motorvision TV Motorvision TV (DE) - MTV3 MTV 80s - MTV 90s MTV Aitio MTV - MTV Hits - MTV Live HD MTV Viihde National Geographic National Geographic Wild - Nautical Channel Nelonen - NFL Network - NHK World Europe Nickelodeon Nick JR Nicktoons - NRK1 NRK2 - NRK3 - NRK Super / NRK3 HD - OUTtv - Paramount Network - Penthouse HD 1 - Penthouse HD 2 Pink Plus - Playboy TV Europe - ProSieben - Rai 1 - Rai 2 - RTL Super RTL - RTLZWEI SF-Kanalen SF Kanalen Sjuan - History (UK) - Sky News SkyShowtime 1 SkyShowtime 2 - Stingray Classica - Djazz HD SVT1 SVT2 SVT24 SVT Barn TLC - Trace Urban HD Travel Channel - TV10 - TV12 TV2 TV2 (Norge) - TV3 Danmark - TV3 Norge TV3 3 Plus Danmark - TV3+ TV4 TV4 Fakta TV4 Film @@ -162,15 +172,10 @@ TV4 Sport Live 4 TV4 Stars TV4 Tennis - TV5 HD - TV5 Monde Europe TV6 TV8 - TV Chile - TVE Internacional - TV Finland - TV Norge HD - TVP Polonia + TV10 + TV12 Vision Sverige V Film Action V Film Family @@ -180,7 +185,6 @@ Viasat History Viasat Nature Viasat Sport HD - VOX V Series V Sport 1 V Sport Extra @@ -195,9 +199,4 @@ V Sport Premium V Sport Ultra HD V Sport Vinter - WILD TV HD - Yle Teema & Fem - Yle TV1 - Yle TV2 - ZDF - \ No newline at end of file + diff --git a/sites/tv.nu/tv.nu.config.js b/sites/tv.nu/tv.nu.config.js index ae33f360..9afa14ea 100644 --- a/sites/tv.nu/tv.nu.config.js +++ b/sites/tv.nu/tv.nu.config.js @@ -15,8 +15,7 @@ module.exports = { programs.push({ title: item.title, description: item.description, - image: item.imageLandscape, - category: item.genres, + category: Array.isArray(item.genres) ? item.genres.map(genre => genre.name) : null, season: item.seasonNumber || null, episode: item.episodeNumber || null, start: parseStart(item), @@ -27,38 +26,41 @@ module.exports = { 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) - // prettier-ignore - const modules = ['ch-51', 'ch-52', 'ch-60', 'ch-27', 'ch-63', 'ch-65', 'ch-64', 'ch-66', 'ch-67', 'ch-68', 'ch-70', 'ch-88', 'ch-45', 'ch-132', 'ch-30228', 'ch-49', 'ch-53', 'ch-30233', 'ch-55', 'ch-93', 'ch-47', 'ch-4', 'ch-134', 'ch-105', 'ch-104', 'ch-131', 'ch-125', 'ch-126', 'ch-30215', 'ch-151', 'ch-122', 'ch-123', 'ch-124', 'ch-30194', 'ch-101', 'ch-106', 'ch-108', 'ch-107', 'ch-136', 'ch-137', 'ch-140', 'ch-120', 'ch-139', 'ch-74', 'ch-71', 'ch-76', 'ch-33', 'ch-18', 'ch-6', 'ch-30197', 'ch-30152', 'ch-146', 'ch-142', 'ch-128', 'ch-30211', 'ch-46', 'ch-162', 'ch-75', 'ch-119', 'ch-57', 'ch-82', 'ch-21', 'ch-22', 'ch-26', 'ch-145', 'ch-38', 'ch-10', 'ch-23', 'ch-9', 'ch-129', 'ch-69', 'ch-12', 'ch-3', 'ch-7', 'ch-81', 'ch-72', 'ch-2', 'ch-111', 'ch-16', 'ch-43', 'ch-80', 'ch-141', 'ch-143', 'ch-164', 'ch-147', 'ch-58', 'ch-39', 'ch-36', 'ch-15', 'ch-154', 'ch-40', 'ch-159', 'ch-30123', 'ch-30132', 'ch-30130', 'ch-30133', 'ch-30125', 'ch-30127', 'ch-30126', 'ch-30134', 'ch-30128', 'ch-30129', 'ch-30124', 'ch-30138', 'ch-30147', 'ch-30146', 'ch-30145', 'ch-30149', 'ch-30151', 'ch-30150', 'ch-30137', 'ch-30136', 'ch-30139', 'ch-30140', 'ch-30142', 'ch-30141', 'ch-161', 'ch-35', 'ch-34', 'ch-32', 'ch-30', 'ch-54', 'ch-112', 'ch-1', 'ch-86', 'ch-84', 'ch-28', 'ch-25', 'ch-13', 'ch-14', 'ch-11', 'ch-8', 'ch-5', 'ch-20', 'ch-24', 'ch-19', 'ch-30168', 'ch-30175', 'ch-30154', 'ch-30225', 'ch-30178', 'ch-30184', 'ch-30185', 'ch-30186', 'ch-30187', 'ch-30189', 'ch-30191', 'ch-30192', 'ch-30216', 'ch-30193', 'ch-30195', 'ch-30196', 'ch-30200', 'ch-30209', 'ch-30231', 'ch-30213', 'ch-30230', 'ch-30214', 'ch-30226', 'ch-56', 'ch-153', 'ch-148', 'ch-41', 'ch-37', 'ch-30157', 'ch-30158', 'ch-30232', 'ch-30221', 'ch-30222', 'ch-30223', 'ch-30234', 'ch-91', 'ch-100', 'ch-30235', 'ch-30236', 'ch-30237', 'ch-30239', 'ch-30240', 'ch-30241', 'ch-30242', 'ch-30249', 'ch-30256', 'ch-30253', 'ch-30250', 'ch-30257', 'ch-30255', 'ch-30251', 'ch-30252', 'ch-30254', 'ch-30258', 'ch-30259', 'ch-30260', 'ch-30261', 'ch-30262', 'ch-30263', 'ch-30264', 'ch-30265', 'ch-30372', 'ch-30373', 'ch-30374', 'ch-30375', 'ch-30376'] + 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) - let channels = [] - - 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) - - console.log(data.data.nextOffset) - - data.data.modules.forEach(item => { - channels.push({ - lang: 'sv', - name: item.content.name, - site_id: item.content.slug - }) - }) - - offset = data.data.nextOffset + data.data.modules.forEach(item => { + channels.push({ + lang: 'sv', + name: item.content.name, + site_id: item.content.slug + }) + }) + offset = data.data.nextOffset + } + } } return channels diff --git a/sites/tv.nu/tv.nu.test.js b/sites/tv.nu/tv.nu.test.js index e5f9802a..8683ce5d 100644 --- a/sites/tv.nu/tv.nu.test.js +++ b/sites/tv.nu/tv.nu.test.js @@ -1,3 +1,5 @@ +const fs = require('fs') +const path = require('path') const { parser, url } = require('./tv.nu.config.js') const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') @@ -5,7 +7,7 @@ const customParseFormat = require('dayjs/plugin/customParseFormat') dayjs.extend(customParseFormat) dayjs.extend(utc) -const date = dayjs.utc('2022-03-06', 'YYYY-MM-DD').startOf('d') +const date = dayjs.utc('2024-12-03', 'YYYY-MM-DD').startOf('d') const channel = { site_id: '3sat', xmltv_id: '3sat.de' @@ -13,13 +15,12 @@ const channel = { it('can generate valid url', () => { expect(url({ channel, date })).toBe( - 'https://web-api.tv.nu/channels/3sat/schedule?date=2022-03-06&fullDay=true' + 'https://web-api.tv.nu/channels/3sat/schedule?date=2024-12-03&fullDay=true' ) }) it('can parse response', () => { - const content = - '{"meta":{"status":200},"data":{"id":30139,"name":"RTL","slug":"rtl","themedLogo":{"light":{"url":"https://new.static.tv.nu/19402170","isFallback":false},"dark":{"url":"https://new.static.tv.nu/59995595","isFallback":true}},"broadcasts":[{"type":"broadcast","id":"1OoSZY-7Q7-1DzQ","slug":"csi","programId":"2452","isPlay":true,"isMovie":false,"isSeries":true,"isLive":false,"title":"CSI: Den Tätern auf der Spur","description":"Hellseherin Sedona Wiley wird tot aufgefunden. Die Ermittlungen führen zu einem alten Mord. Gordon Wallace wurde vor 15 Jahren beschuldigt, seine Frau getötet zu haben, jedoch wurde nie eine Leiche gefunden.","imagePortrait":"https://new.static.tv.nu/16686512","imageLandscape":"https://new.static.tv.nu/13119997","year":2006,"genres":["Action","Kriminaldrama","Mysterium","Spänning","Thriller"],"imdb":{"rating":"7.7","link":"https://www.imdb.com/title/tt0247082"},"playProviders":[{"name":"Viaplay","slug":"viaplay","themedLogo":{"light":{"url":"https://new.static.tv.nu/17048879","isFallback":false},"dark":{"url":"https://new.static.tv.nu/119659437","isFallback":false}},"url":"https://viaplay.se/serier/csi-crime-scene-investigation/sasong-6/avsnitt-19?utm_source=tv.nu&utm_content=CSI%3A+Crime+Scene+Investigation"},{"name":"Tele2 Play","slug":"tele2play","themedLogo":{"light":{"url":"https://new.static.tv.nu/158747195","isFallback":false},"dark":{"url":"https://new.static.tv.nu/158747194","isFallback":false}},"url":"https://www.comhemplay.se/open/vod/SH016259780000?utm_source=tv.nu&utm_medium=partner&utm_campaign=tabla&utm_content=CSI%3A+Crime+Scene+Investigation"},{"name":"Prime Video","slug":"prime-video","themedLogo":{"light":{"url":"https://new.static.tv.nu/23085972","isFallback":false},"dark":{"url":"https://new.static.tv.nu/275111","isFallback":true}},"url":"https://app.primevideo.com/detail?gti=amzn1.dv.gti.54af67f9-e58f-e6db-4991-81eb4f2efa37&utm_source=tv.nu"}],"broadcast":{"id":"1OoSZY-7Q7-1DzQ","startTime":1660878900000,"endTime":1660881600000,"channel":{"name":"RTL","slug":"rtl","themedLogo":{"light":{"url":"https://new.static.tv.nu/19402170","isFallback":false},"dark":{"url":"https://new.static.tv.nu/59995595","isFallback":true}}}},"totalEpisodes":24,"episodeNumber":19,"seasonNumber":6}]}}' + const content = fs.readFileSync(path.join(__dirname, '__data__', 'content.json')) const result = parser({ content }).map(p => { p.start = p.start.toJSON() p.stop = p.stop.toJSON() @@ -28,22 +29,20 @@ it('can parse response', () => { expect(result).toMatchObject([ { - start: '2022-08-19T03:15:00.000Z', - stop: '2022-08-19T04:00:00.000Z', - title: 'CSI: Den Tätern auf der Spur', + start: '2024-12-03T11:50:00.000Z', + stop: '2024-12-03T12:15:00.000Z', + title: 'Natur im Garten', description: - 'Hellseherin Sedona Wiley wird tot aufgefunden. Die Ermittlungen führen zu einem alten Mord. Gordon Wallace wurde vor 15 Jahren beschuldigt, seine Frau getötet zu haben, jedoch wurde nie eine Leiche gefunden.', - image: 'https://new.static.tv.nu/13119997', - category: ['Action', 'Kriminaldrama', 'Mysterium', 'Spänning', 'Thriller'], - season: 6, - episode: 19 + 'Der Gartenbuchautor Karl Ploberger gibt in der Sendung Tipps und Tricks zur Gartenpflege.', + category: ['Konsument', 'Underhållning', 'Trädgård'], + season: 29, + episode: 9 } ]) }) it('can handle empty guide', () => { - const result = parser({ - content: '{"meta":{"status":200},"data":{"broadcasts":[]}}' - }) + const content = fs.readFileSync(path.join(__dirname, '__data__', 'no_content.json')) + const result = parser({ content }) expect(result).toMatchObject([]) })