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] 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 [] + } + } +}