Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stod2.is #2535

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions sites/stod2.is/readme.md
Original file line number Diff line number Diff line change
@@ -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
```
14 changes: 14 additions & 0 deletions sites/stod2.is/stod2.is.channels.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<channels>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="stod2">Stöð 2</channel>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="stod3">Stöð 2 Fjölskylda</channel>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="sport">Stöð 2 Sport</channel>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="sport2">Stöð 2 Sport 2</channel>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="sport3">Stöð 2 Sport 3</channel>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="sport4">Stöð 2 Sport 4</channel>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="golfstodin">Stöð 2 Sport 5</channel>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="sport6">Stöð 2 Sport 6</channel>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="besta01">Besta01</channel>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="besta02">Besta02</channel>
<channel site="stod2.is" lang="is" xmltv_id="" site_id="besta03">Besta03</channel>
</channels>
62 changes: 62 additions & 0 deletions sites/stod2.is/stod2.is.config.js
Original file line number Diff line number Diff line change
@@ -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
}
30 changes: 30 additions & 0 deletions sites/stod2.is/stod2.is.test.js
Original file line number Diff line number Diff line change
@@ -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([])
})