mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 10:26:41 -05:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,90 +1,90 @@
|
||||
const dayjs = require('dayjs')
|
||||
const cheerio = require('cheerio')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'sjonvarp.is',
|
||||
days: 2,
|
||||
url: function ({ channel, date }) {
|
||||
return `http://www.sjonvarp.is/index.php?Tm=%3F&p=idag&c=${channel.site_id}&y=${date.format(
|
||||
'YYYY'
|
||||
)}&m=${date.format('MM')}&d=${date.format('DD')}`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date)
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.add(30, 'm')
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
const data = await axios
|
||||
.get('https://sjonvarp.is/')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
let channels = []
|
||||
|
||||
const $ = cheerio.load(data)
|
||||
$('.listing-row').each((i, el) => {
|
||||
const site_id = $(el).attr('id')
|
||||
const title = $(el).find('a.channel').first().attr('title')
|
||||
const [, name] = title.match(/^Skoða dagskránna á (.*) í dag$/)
|
||||
|
||||
channels.push({
|
||||
lang: 'is',
|
||||
site_id,
|
||||
name
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.day-listing-title').text()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.day-listing-description').text()
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const time = $item('.day-listing-time')
|
||||
|
||||
return dayjs.utc(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm')
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $(
|
||||
'body > div.container.nano-container > div > ul > div.day-listing > div:not(.day-listing-channel)'
|
||||
).toArray()
|
||||
}
|
||||
const dayjs = require('dayjs')
|
||||
const cheerio = require('cheerio')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'sjonvarp.is',
|
||||
days: 2,
|
||||
url: function ({ channel, date }) {
|
||||
return `http://www.sjonvarp.is/index.php?Tm=%3F&p=idag&c=${channel.site_id}&y=${date.format(
|
||||
'YYYY'
|
||||
)}&m=${date.format('MM')}&d=${date.format('DD')}`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date)
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.add(30, 'm')
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
const data = await axios
|
||||
.get('https://sjonvarp.is/')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
let channels = []
|
||||
|
||||
const $ = cheerio.load(data)
|
||||
$('.listing-row').each((i, el) => {
|
||||
const site_id = $(el).attr('id')
|
||||
const title = $(el).find('a.channel').first().attr('title')
|
||||
const [, name] = title.match(/^Skoða dagskránna á (.*) í dag$/)
|
||||
|
||||
channels.push({
|
||||
lang: 'is',
|
||||
site_id,
|
||||
name
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.day-listing-title').text()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.day-listing-description').text()
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const time = $item('.day-listing-time')
|
||||
|
||||
return dayjs.utc(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm')
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $(
|
||||
'body > div.container.nano-container > div > ul > div.day-listing > div:not(.day-listing-channel)'
|
||||
).toArray()
|
||||
}
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
const { parser, url } = require('./sjonvarp.is.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
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('2022-08-28', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'RUV',
|
||||
xmltv_id: 'RUV.is'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'http://www.sjonvarp.is/index.php?Tm=%3F&p=idag&c=RUV&y=2022&m=08&d=28'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-08-28T07:15:00.000Z',
|
||||
stop: '2022-08-28T07:16:00.000Z',
|
||||
title: 'KrakkaRÚV'
|
||||
})
|
||||
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2022-08-28T07:16:00.000Z',
|
||||
stop: '2022-08-28T07:21:00.000Z',
|
||||
title: 'Tölukubbar',
|
||||
description: 'Lærið um tölustafina með Tölukubbunum! e.'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const result = parser({ content, date })
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./sjonvarp.is.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
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('2022-08-28', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'RUV',
|
||||
xmltv_id: 'RUV.is'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'http://www.sjonvarp.is/index.php?Tm=%3F&p=idag&c=RUV&y=2022&m=08&d=28'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-08-28T07:15:00.000Z',
|
||||
stop: '2022-08-28T07:16:00.000Z',
|
||||
title: 'KrakkaRÚV'
|
||||
})
|
||||
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2022-08-28T07:16:00.000Z',
|
||||
stop: '2022-08-28T07:21:00.000Z',
|
||||
title: 'Tölukubbar',
|
||||
description: 'Lærið um tölustafina með Tölukubbunum! e.'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const result = parser({ content, date })
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user