From dfeca2a320a505852e24678dd6861e6208619254 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Sat, 2 Dec 2023 18:16:44 +0300 Subject: [PATCH] Adds allente.no --- SITES.md | 1 + sites/allente.no/allente.no.channels.xml | 87 ++++++++++++++++++++++++ sites/allente.no/allente.no.config.js | 65 ++++++++++++++++++ sites/allente.no/allente.no.test.js | 49 +++++++++++++ sites/allente.no/readme.md | 21 ++++++ 5 files changed, 223 insertions(+) create mode 100644 sites/allente.no/allente.no.channels.xml create mode 100644 sites/allente.no/allente.no.config.js create mode 100644 sites/allente.no/allente.no.test.js create mode 100644 sites/allente.no/readme.md diff --git a/SITES.md b/SITES.md index fa6e8fb0..84263bf7 100644 --- a/SITES.md +++ b/SITES.md @@ -6,6 +6,7 @@ | [abc.net.au](sites/abc.net.au) | 🟢 | | | [allente.dk](sites/allente.dk) | 🟢 | | | [allente.fi](sites/allente.fi) | 🟢 | | +| [allente.no](sites/allente.no) | 🟢 | | | [allente.se](sites/allente.se) | 🟢 | | | [andorradifusio.ad](sites/andorradifusio.ad) | 🟢 | | | [anteltv.com.uy](sites/anteltv.com.uy) | 🟢 | | diff --git a/sites/allente.no/allente.no.channels.xml b/sites/allente.no/allente.no.channels.xml new file mode 100644 index 00000000..2b02b2e3 --- /dev/null +++ b/sites/allente.no/allente.no.channels.xml @@ -0,0 +1,87 @@ + + + Cartoonito (T) + Nickelodeon (Nordic) (T) + TV2 Sport Premium 2 HD (N) (T) + Viasat Nature HD (T) + DR1 HD (T) + Sky News (T) + Horse & Country HD -IP + SF Kanalen (T) + SkyShowtime 2 (T) + SkyShowtime 1 (T) + HISTORY HD (N/D/F) (T) + HISTORY 2 HD (T) + Animal Planet HD (T) + Discovery Science (T) + DW English (T) + Bloomberg (T) + MOTORVISION TV HD (T) + Bilkanalen Auto Motor og Sport TV (N) (T) + ID Investigation Discovery (N/F) (T) + TLC Norge HD (T) + BBC Nordic HD (N) (T) + France 24 (T) + VGTV HD (T) + V sport Premier League HD (T) + V sport Premier League 1 HD (T) + V sport Premier League 2 HD (T) + Heim HD (T) + Stars HD (N) (T) + Hits HD (N) (T) + Al Jazeera English -OTT + BBC News (T) + Cartoon Network (T) + CNBC (T) + CNN (T) + Discovery Channel HD (N) (T) + DR2 HD (T) + Eurosport 1 HD (N) (T) + Eurosport Norge HD (T) + FEM HD (T) + Kunskapskanalen HD (T) + MAX HD (T) + MTV 00s (T) + MTV 80s (T) + MTV (Nordic) (T) + National Geographic HD (N) (T) + Nick Jr. (T) + Nicktoons (T) + NRK1 HD (T) + NRK2 HD (T) + NRK3/ NRK Super HD (T) + SVT1 HD (T) + SVT2 HD (T) + SVT Barn HD (T) + TV 2 HD (D) (T) + TV2 Direkte (N) (T) + TV2 Livsstil HD (N) (T) + TV2 Nyheter (N) (T) + TV2 Sport 1 HD (N) (T) + TV2 Sport 2 HD (N) (T) + TV2 Sport Premium HD (N) (T) + TV2 Zebra HD (N) (T) + TV3 HD (N) (T) + TV6 (N) (T) + TV Norge HD (T) + TV3+ (N) (T) + V film action HD (T) + V film family (T) + V film hits HD (T) + V film premiere HD (T) + Viasat Explore HD (T) + Viasat History HD (T) + VOX HD (T) + V series HD (T) + V sport 1 HD (N) (T) + V sport 2 HD (N) (T) + V sport 3 HD (N) (T) + V sport golf HD (T) + V sport live 1 (T) + V sport live 2 (T) + V sport live 3 (T) + V sport live 4 (T) + V sport live 5 (T) + V sport+ HD (N) (T) + V sport ultra HD (T) + diff --git a/sites/allente.no/allente.no.config.js b/sites/allente.no/allente.no.config.js new file mode 100644 index 00000000..ba4e9adf --- /dev/null +++ b/sites/allente.no/allente.no.config.js @@ -0,0 +1,65 @@ +const dayjs = require('dayjs') + +module.exports = { + site: 'allente.no', + days: 2, + request: { + cache: { + ttl: 60 * 60 * 1000 // 1 hour + } + }, + url({ date }) { + return `https://cs-vcb.allente.no/epg/events?date=${date.format('YYYY-MM-DD')}` + }, + parser({ content, channel }) { + let programs = [] + const items = parseItems(content, channel) + items.forEach(item => { + if (!item.details) return + const start = dayjs(item.time) + const stop = start.add(item.details.duration, 'm') + programs.push({ + title: item.title, + category: item.details.categories, + description: item.details.description, + icon: item.details.image, + season: parseSeason(item), + episode: parseEpisode(item), + start, + stop + }) + }) + + return programs + }, + async channels() { + const axios = require('axios') + const data = await axios + .get(`https://cs-vcb.allente.no/epg/events?date=${dayjs().format('YYYY-MM-DD')}`) + .then(r => r.data) + .catch(console.log) + + return data.channels.map(item => { + return { + lang: 'no', + site_id: item.id, + name: item.name + } + }) + } +} + +function parseItems(content, channel) { + const data = JSON.parse(content) + if (!data || !Array.isArray(data.channels)) return [] + const channelData = data.channels.find(i => i.id === channel.site_id) + + return channelData && Array.isArray(channelData.events) ? channelData.events : [] +} + +function parseSeason(item) { + return item.details.season || null +} +function parseEpisode(item) { + return item.details.episode || null +} diff --git a/sites/allente.no/allente.no.test.js b/sites/allente.no/allente.no.test.js new file mode 100644 index 00000000..204d0a10 --- /dev/null +++ b/sites/allente.no/allente.no.test.js @@ -0,0 +1,49 @@ +const { parser, url } = require('./allente.no.config.js') +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('2021-11-17', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '0148', + xmltv_id: 'SVT1.se' +} + +it('can generate valid url', () => { + expect(url({ date, channel })).toBe('https://cs-vcb.allente.no/epg/events?date=2021-11-17') +}) + +it('can parse response', () => { + const content = + '{"channels":[{"id":"0148","icon":"//images.ctfassets.net/989y85n5kcxs/5uT9g9pdQWRZeDPQXVI9g6/9cc44da567f591822ed645c99ecdcb64/SVT_1_black_new__2_.png","name":"SVT1 HD (T)","events":[{"id":"0086202208220710","live":false,"time":"2022-08-22T07:10:00Z","title":"Hemmagympa med Sofia","details":{"title":"Hemmagympa med Sofia","image":"https://viasatps.api.comspace.se/PS/channeldate/image/viasat.ps/21/2022-08-22/se.cs.svt1.event.A_41214031600.jpg?size=2560x1440","description":"Svenskt träningsprogram från 2021. Styrka. Sofia Åhman leder SVT:s hemmagympapass. Denna gång fokuserar vi på styrka.","season":4,"episode":1,"categories":["other"],"duration":"20"}}]}]}' + const result = parser({ content, channel }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-08-22T07:10:00.000Z', + stop: '2022-08-22T07:30:00.000Z', + title: 'Hemmagympa med Sofia', + category: ['other'], + description: + 'Svenskt träningsprogram från 2021. Styrka. Sofia Åhman leder SVT:s hemmagympapass. Denna gång fokuserar vi på styrka.', + icon: 'https://viasatps.api.comspace.se/PS/channeldate/image/viasat.ps/21/2022-08-22/se.cs.svt1.event.A_41214031600.jpg?size=2560x1440', + season: 4, + episode: 1 + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: '{"date":"2001-11-17","categories":[],"channels":[]}' + }) + expect(result).toMatchObject([]) +}) diff --git a/sites/allente.no/readme.md b/sites/allente.no/readme.md new file mode 100644 index 00000000..5beeacb0 --- /dev/null +++ b/sites/allente.no/readme.md @@ -0,0 +1,21 @@ +# allente.no + +https://www.allente.no/tv-guide/ + +### Download the guide + +```sh +npm run grab -- --site=allente.no +``` + +### Update channel list + +```sh +npm run channels:parse -- --config=./sites/allente.no/allente.no.config.js --output=./sites/allente.no/allente.no.channels.xml +``` + +### Test + +```sh +npm test -- allente.no +```