diff --git a/sites/stod2.is/readme.md b/sites/stod2.is/readme.md new file mode 100644 index 000000000..843613e04 --- /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 000000000..def4dd241 --- /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 000000000..24632fd9d --- /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 000000000..68642d842 --- /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