From f501229b65cb13b01f0552ea3e16603caedbb4b1 Mon Sep 17 00:00:00 2001 From: fraudiay79 Date: Thu, 19 Dec 2024 14:54:34 -0500 Subject: [PATCH 1/8] Add stod2.is Add stod2.is guide --- sites/stod2.is/readme.md | 21 ++++++++++ sites/stod2.is/stod2.is.channels.xml | 14 +++++++ sites/stod2.is/stod2.is.config.js | 62 ++++++++++++++++++++++++++++ sites/stod2.is/stod2.is.test.js | 30 ++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 sites/stod2.is/readme.md create mode 100644 sites/stod2.is/stod2.is.channels.xml create mode 100644 sites/stod2.is/stod2.is.config.js create mode 100644 sites/stod2.is/stod2.is.test.js diff --git a/sites/stod2.is/readme.md b/sites/stod2.is/readme.md new file mode 100644 index 00000000..843613e0 --- /dev/null +++ b/sites/stod2.is/readme.md @@ -0,0 +1,21 @@ +# stod2.is + +https://stod2.is/framundan-i-beinni/ + +### Download the guide + +```sh +npm run grab --- --site=stod2.is +``` + +### Update channel list + +```sh +npm run channels:parse --- --config=./sites/stod2.is/stod2.is.config.js --output=./sites/stod2.is/stod2.is.channels.xml +``` + +### Test + +```sh +npm test --- stod2.is +``` diff --git a/sites/stod2.is/stod2.is.channels.xml b/sites/stod2.is/stod2.is.channels.xml new file mode 100644 index 00000000..def4dd24 --- /dev/null +++ b/sites/stod2.is/stod2.is.channels.xml @@ -0,0 +1,14 @@ + + + Stöð 2 + Stöð 2 Fjölskylda + Stöð 2 Sport + Stöð 2 Sport 2 + Stöð 2 Sport 3 + Stöð 2 Sport 4 + Stöð 2 Sport 5 + Stöð 2 Sport 6 + Besta01 + Besta02 + Besta03 + diff --git a/sites/stod2.is/stod2.is.config.js b/sites/stod2.is/stod2.is.config.js new file mode 100644 index 00000000..24632fd9 --- /dev/null +++ b/sites/stod2.is/stod2.is.config.js @@ -0,0 +1,62 @@ +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') + +dayjs.extend(utc) + +module.exports = { + site: 'stod2.is', + channels: 'stod2.is.channels.xml', + days: 7, + request: { + cache: { + ttl: 60 * 60 * 1000 // 1 hour + } + }, + url({ channel, date }) { + return `https://api.stod2.is/dagskra/api/${channel.site_id}/${date.format('YYYY-MM-DD')}` + }, + parser({ content }) { + let programs = [] + const items = parseItems(content) + + items.forEach(item => { + if (!item) return + const start = dayjs.utc(item.upphaf) + const stop = start.add(item.slott, 'm') + + programs.push({ + title: item.isltitill, + sub_title: item.undirtitill, + description: item.lysing, + actors: item.adalhlutverk, + directors: item.leikstjori, + start, + stop + }) + }) + + return programs; + }, + async channels() { + const axios = require('axios') + try { + const response = await axios.get(`https://api.stod2.is/dagskra/api`) + return response.data.channels.map(item => { + return { + lang: 'is', + name: item.nafn, // Assuming 'nafn' is the name of the channel + site_id: item.id + } + }) + } catch (error) { + console.error('Error fetching channels:', error) + return [] + } + } +}; + +function parseItems(content) { + const data = JSON.parse(content) + if (!data || !Array.isArray(data)) return [] + return data +} \ No newline at end of file diff --git a/sites/stod2.is/stod2.is.test.js b/sites/stod2.is/stod2.is.test.js new file mode 100644 index 00000000..68642d84 --- /dev/null +++ b/sites/stod2.is/stod2.is.test.js @@ -0,0 +1,30 @@ +const { url, parser } = require('./stod2.is.config.js') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +dayjs.extend(utc) + +const date = dayjs.utc('2024-12-19', 'YYYY-MM-DD').startOf('d') +const channel = { site_id: 'stod2', xmltv_id: 'Stod2.is', lang: 'is' } + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe('https://api.stod2.is/dagskra/api/stod2/2024-12-19') +}) + +it('can parse response', () => { + const content = `[{"start":"2024-12-19T08:00:00Z","stop":"2024-12-19T08:15:00Z","title":"Heimsókn"}]` + const results = parser({ content }) + + expect(results).toMatchObject([ + { + start: '2024-12-19T08:00:00Z', + stop: '2024-12-19T08:15:00Z', + title: 'Heimsókn' + } + ]) +}) + +it('can handle empty guide', () => { + const results = parser({ content: '' }) + + expect(results).toMatchObject([]) +}) \ No newline at end of file From 01419410ebe1505c4f816a658cd8211ffe175c31 Mon Sep 17 00:00:00 2001 From: fraudiay79 <60631277+fraudiay79@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:59:01 -0500 Subject: [PATCH 2/8] Create stod2.is.config.js --- sites/stod2.is/stod2.is.config.js | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 sites/stod2.is/stod2.is.config.js diff --git a/sites/stod2.is/stod2.is.config.js b/sites/stod2.is/stod2.is.config.js new file mode 100644 index 00000000..46eb685d --- /dev/null +++ b/sites/stod2.is/stod2.is.config.js @@ -0,0 +1,68 @@ +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const axios = require('axios') + +dayjs.extend(utc) + +module.exports = { + site: 'stod2.is', + channels: 'stod2.is.channels.xml', + days: 7, + request: { + cache: { + ttl: 60 * 60 * 1000 // 1 hour + } + }, + url({ channel, date }) { + return `https://api.stod2.is/dagskra/api/${channel.site_id}/${date.format('YYYY-MM-DD')}` + }, + parser: function ({ content }) { + let data + try { + data = JSON.parse(content) + } catch (error) { + console.error('Error parsing JSON:', error) + return [] + } + + const programs = [] + + if (data && Array.isArray(data)) { + data.forEach(item => { + if (!item) return + const start = dayjs.utc(item.upphaf) + const stop = start.add(item.slott, 'm') + + programs.push({ + title: item.isltitill, + sub_title: item.undirtitill, + description: item.lysing, + actors: item.adalhlutverk, + directors: item.leikstjori, + start: start.toISOString, + stop: stop.toISOString + }) + }) + } + + return programs + }, + async channels() { + try { + const response = await axios.get('https://api.stod2.is/dagskra/api') + if (!response.data || !Array.isArray(response.data)) { + console.error('Error: No channels data found') + return [] + } + return response.data.map(item => { + return { + lang: 'is', + site_id: item + } + }) + } catch (error) { + console.error('Error fetching channels:', error) + return [] + } + } +} From c5ee8a7597ecd56ce63e2fd9af95cb77ef802ca3 Mon Sep 17 00:00:00 2001 From: fraudiay79 <60631277+fraudiay79@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:59:54 -0500 Subject: [PATCH 3/8] Create stod2.is.channels.xml --- sites/stod2.is/stod2.is.channels.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 sites/stod2.is/stod2.is.channels.xml diff --git a/sites/stod2.is/stod2.is.channels.xml b/sites/stod2.is/stod2.is.channels.xml new file mode 100644 index 00000000..50a9e062 --- /dev/null +++ b/sites/stod2.is/stod2.is.channels.xml @@ -0,0 +1,15 @@ + + + Stöð 2 + Stöð 2 Fjölskylda + Stöð 2 Sport + Stöð 2 Sport 2 + Stöð 2 Sport 3 + Stöð 2 Sport 4 + Stöð 2 Sport 5 + Stöð 2 Sport 6 + Besta01 + Besta02 + Besta03 + Vodafone Sport + From 711d85309a5a0f4584573cf47893fe0ee9e71cc3 Mon Sep 17 00:00:00 2001 From: fraudiay79 <60631277+fraudiay79@users.noreply.github.com> Date: Fri, 3 Jan 2025 12:00:18 -0500 Subject: [PATCH 4/8] Create stod2.is.test.js --- sites/stod2.is/stod2.is.test.js | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 sites/stod2.is/stod2.is.test.js diff --git a/sites/stod2.is/stod2.is.test.js b/sites/stod2.is/stod2.is.test.js new file mode 100644 index 00000000..97d0d2ad --- /dev/null +++ b/sites/stod2.is/stod2.is.test.js @@ -0,0 +1,82 @@ +const { parser, url } = require('./stod2.is.config.js') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const customParseFormat = require('dayjs/plugin/customParseFormat') +const timezone = require('dayjs/plugin/timezone') +const axios = require('axios') + +dayjs.extend(utc) +dayjs.extend(customParseFormat) +dayjs.extend(timezone) + +jest.mock('axios') + +const date = dayjs.utc('2025-01-03', 'YYYY-MM-DD').startOf('day') +const channel = { site_id: 'stod2', xmltv_id: 'Stod2.is' } + +const mockEpgData = JSON.stringify([ + { + "midill": "STOD2", + "midill_heiti": "Stöð 2", + "dagsetning": "2025-01-03T00:00:00Z", + "upphaf": "2025-01-03T08:00:00Z", + "titill": "Telma Borgþórsdóttir", + "isltitill": "Heimsókn", + "undirtitill": "Telma Borgþórsdóttir", + "seria": 8, + "thattur": 5, + "thattafjoldi": 10, + "birta_thatt": 1, + "opin": 0, + "beint": 0, + "frumsyning": 0, + "framundan_i_beinni": 0, + "tegund": "SER", + "flokkur": "Icelandic", + "adalhlutverk": "", + "leikstjori": "", + "ar": "2019", + "bannad": "Green", + "recidefni": 592645105, + "recidlidur": 592645184, + "recidsyning": null, + "refno": null, + "frelsi": 0, + "netdagar": 0, + "lysing": "Frábærir þættir með Sindra Sindrasyni sem lítur inn hjá íslenskum fagurkerum. Heimilin eru jafn ólík og þau eru mörg en eiga það þó eitt sameiginlegt að vera sett saman af alúð og smekklegheitum. Sindri hefur líka einstakt lag á að ná fram því besta í viðmælendum sínum.", + "slott": 15, + "slotlengd": "00:15" + } +]) + +it('can generate valid url', () => { + const generatedUrl = url({ date, channel }) + console.log('Generated URL:', generatedUrl) + expect(generatedUrl).toBe('https://api.stod2.is/dagskra/api/stod2/2025-01-03') +}) + +it('can parse response', () => { + const content = mockEpgData + const result = parser({ content }).map(p => { + p.start = p.start.toISOString() + p.stop = p.stop.toISOString() + return p + }) + + expect(result).toMatchObject([ + { + title: "Heimsókn", + sub_title: "Telma Borgþórsdóttir", + description: "Frábærir þættir með Sindra Sindrasyni sem lítur inn hjá íslenskum fagurkerum. Heimilin eru jafn ólík og þau eru mörg en eiga það þó eitt sameiginlegt að vera sett saman af alúð og smekklegheitum. Sindri hefur líka einstakt lag á að ná fram því besta í viðmælendum sínum.", + actors: "", + directors: "", + start: "2025-01-03T08:00:00.000Z", + stop: "2025-01-03T08:15:00.000Z" + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ content: '[]' }) + expect(result).toMatchObject([]) +}) From f4d5719e7e87b1882b2dd649565aa45918888ca7 Mon Sep 17 00:00:00 2001 From: fraudiay79 <60631277+fraudiay79@users.noreply.github.com> Date: Fri, 3 Jan 2025 12:00:41 -0500 Subject: [PATCH 5/8] Create readme.md --- sites/stod2.is/readme.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 sites/stod2.is/readme.md diff --git a/sites/stod2.is/readme.md b/sites/stod2.is/readme.md new file mode 100644 index 00000000..843613e0 --- /dev/null +++ b/sites/stod2.is/readme.md @@ -0,0 +1,21 @@ +# stod2.is + +https://stod2.is/framundan-i-beinni/ + +### Download the guide + +```sh +npm run grab --- --site=stod2.is +``` + +### Update channel list + +```sh +npm run channels:parse --- --config=./sites/stod2.is/stod2.is.config.js --output=./sites/stod2.is/stod2.is.channels.xml +``` + +### Test + +```sh +npm test --- stod2.is +``` From 89e0fe5306f6563b49073b73e00b268c6754537b Mon Sep 17 00:00:00 2001 From: fraudiay79 <60631277+fraudiay79@users.noreply.github.com> Date: Fri, 3 Jan 2025 12:04:36 -0500 Subject: [PATCH 6/8] Update readme.md --- sites/stod2.is/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sites/stod2.is/readme.md b/sites/stod2.is/readme.md index 843613e0..1011404a 100644 --- a/sites/stod2.is/readme.md +++ b/sites/stod2.is/readme.md @@ -1,6 +1,6 @@ # stod2.is -https://stod2.is/framundan-i-beinni/ +https://stod2.is/dagskra/ ### Download the guide From d156add197ea6195e4a41e69ecfd0b92125c8189 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Sat, 4 Jan 2025 17:01:53 +0300 Subject: [PATCH 7/8] Update stod2.is.test.js --- sites/stod2.is/stod2.is.test.js | 77 +++++++++++++++++---------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/sites/stod2.is/stod2.is.test.js b/sites/stod2.is/stod2.is.test.js index 97d0d2ad..2a9efee5 100644 --- a/sites/stod2.is/stod2.is.test.js +++ b/sites/stod2.is/stod2.is.test.js @@ -16,42 +16,42 @@ const channel = { site_id: 'stod2', xmltv_id: 'Stod2.is' } const mockEpgData = JSON.stringify([ { - "midill": "STOD2", - "midill_heiti": "Stöð 2", - "dagsetning": "2025-01-03T00:00:00Z", - "upphaf": "2025-01-03T08:00:00Z", - "titill": "Telma Borgþórsdóttir", - "isltitill": "Heimsókn", - "undirtitill": "Telma Borgþórsdóttir", - "seria": 8, - "thattur": 5, - "thattafjoldi": 10, - "birta_thatt": 1, - "opin": 0, - "beint": 0, - "frumsyning": 0, - "framundan_i_beinni": 0, - "tegund": "SER", - "flokkur": "Icelandic", - "adalhlutverk": "", - "leikstjori": "", - "ar": "2019", - "bannad": "Green", - "recidefni": 592645105, - "recidlidur": 592645184, - "recidsyning": null, - "refno": null, - "frelsi": 0, - "netdagar": 0, - "lysing": "Frábærir þættir með Sindra Sindrasyni sem lítur inn hjá íslenskum fagurkerum. Heimilin eru jafn ólík og þau eru mörg en eiga það þó eitt sameiginlegt að vera sett saman af alúð og smekklegheitum. Sindri hefur líka einstakt lag á að ná fram því besta í viðmælendum sínum.", - "slott": 15, - "slotlengd": "00:15" + midill: 'STOD2', + midill_heiti: 'Stöð 2', + dagsetning: '2025-01-03T00:00:00Z', + upphaf: '2025-01-03T08:00:00Z', + titill: 'Telma Borgþórsdóttir', + isltitill: 'Heimsókn', + undirtitill: 'Telma Borgþórsdóttir', + seria: 8, + thattur: 5, + thattafjoldi: 10, + birta_thatt: 1, + opin: 0, + beint: 0, + frumsyning: 0, + framundan_i_beinni: 0, + tegund: 'SER', + flokkur: 'Icelandic', + adalhlutverk: '', + leikstjori: '', + ar: '2019', + bannad: 'Green', + recidefni: 592645105, + recidlidur: 592645184, + recidsyning: null, + refno: null, + frelsi: 0, + netdagar: 0, + lysing: + 'Frábærir þættir með Sindra Sindrasyni sem lítur inn hjá íslenskum fagurkerum. Heimilin eru jafn ólík og þau eru mörg en eiga það þó eitt sameiginlegt að vera sett saman af alúð og smekklegheitum. Sindri hefur líka einstakt lag á að ná fram því besta í viðmælendum sínum.', + slott: 15, + slotlengd: '00:15' } ]) it('can generate valid url', () => { const generatedUrl = url({ date, channel }) - console.log('Generated URL:', generatedUrl) expect(generatedUrl).toBe('https://api.stod2.is/dagskra/api/stod2/2025-01-03') }) @@ -65,13 +65,14 @@ it('can parse response', () => { expect(result).toMatchObject([ { - title: "Heimsókn", - sub_title: "Telma Borgþórsdóttir", - description: "Frábærir þættir með Sindra Sindrasyni sem lítur inn hjá íslenskum fagurkerum. Heimilin eru jafn ólík og þau eru mörg en eiga það þó eitt sameiginlegt að vera sett saman af alúð og smekklegheitum. Sindri hefur líka einstakt lag á að ná fram því besta í viðmælendum sínum.", - actors: "", - directors: "", - start: "2025-01-03T08:00:00.000Z", - stop: "2025-01-03T08:15:00.000Z" + title: 'Heimsókn', + sub_title: 'Telma Borgþórsdóttir', + description: + 'Frábærir þættir með Sindra Sindrasyni sem lítur inn hjá íslenskum fagurkerum. Heimilin eru jafn ólík og þau eru mörg en eiga það þó eitt sameiginlegt að vera sett saman af alúð og smekklegheitum. Sindri hefur líka einstakt lag á að ná fram því besta í viðmælendum sínum.', + actors: '', + directors: '', + start: '2025-01-03T08:00:00.000Z', + stop: '2025-01-03T08:15:00.000Z' } ]) }) From cf52b0c3b0d64b970ac988631086ea0d3889460e Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Sat, 4 Jan 2025 17:01:56 +0300 Subject: [PATCH 8/8] Update stod2.is.config.js --- sites/stod2.is/stod2.is.config.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/sites/stod2.is/stod2.is.config.js b/sites/stod2.is/stod2.is.config.js index 46eb685d..6ae2d1d4 100644 --- a/sites/stod2.is/stod2.is.config.js +++ b/sites/stod2.is/stod2.is.config.js @@ -39,8 +39,8 @@ module.exports = { description: item.lysing, actors: item.adalhlutverk, directors: item.leikstjori, - start: start.toISOString, - stop: stop.toISOString + start, + stop }) }) } @@ -48,21 +48,21 @@ module.exports = { return programs }, async channels() { - try { - const response = await axios.get('https://api.stod2.is/dagskra/api') - if (!response.data || !Array.isArray(response.data)) { - console.error('Error: No channels data found') - return [] + try { + const response = await axios.get('https://api.stod2.is/dagskra/api') + if (!response.data || !Array.isArray(response.data)) { + console.error('Error: No channels data found') + return [] } - return response.data.map(item => { - return { - lang: 'is', - site_id: item + return response.data.map(item => { + return { + lang: 'is', + site_id: item } }) } catch (error) { - console.error('Error fetching channels:', error) - return [] + console.error('Error fetching channels:', error) + return [] } } }