Replace LF endings with CRLF

This commit is contained in:
freearhey
2025-07-31 22:29:01 +03:00
parent 17e3b4ddda
commit 29aa427923
379 changed files with 29332 additions and 29332 deletions

View File

@@ -1,169 +1,169 @@
const doFetch = require('@ntlab/sfetch')
const cheerio = require('cheerio')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
const tz = 'Europe/Helsinki'
module.exports = {
site: 'tvkaista.org',
days: 2,
url({ channel, date }) {
return `https://www.tvkaista.org/${channel.site_id}/${date.format('YYYY-MM-DD')}`
},
parser({ 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)
let stop = parseStop($item, start)
if (prev) {
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
} else if (stop.isBefore(start)) {
stop = stop.add(1, 'd')
date = date.add(1, 'd')
}
} else {
if (start.hour() > 18) {
start = start.subtract(1, 'd')
date = date.subtract(1, 'd')
}
}
programs.push({
title: parseTitle($item),
description: parseDescription($item),
season: parseSeason($item),
episode: parseEpisode($item),
categories: parseCategories($item),
rating: parseRating($item),
start,
stop
})
})
return programs
},
async channels() {
let channels = []
const queue = ['https://www.tvkaista.org/', 'https://www.tvkaista.org/maksukanavat/']
await doFetch(queue, (url, res) => {
const $ = cheerio.load(res)
$('body > main > div > div.row > div').each((i, el) => {
const link = $(el).find('div > div > div > div.col-auto > a')
const img = link.find('img.channel-logo')
const name = link.text().trim() || img.attr('alt')
const [, site_id] = link.attr('href').split('/')
channels.push({
lang: 'fi',
name,
site_id
})
})
})
return channels
}
}
function parseRating($item) {
let rating = $item(
'div.d-flex.flex-row.bd-highlight > div.bd-highlight.flex-fill > span:nth-child(3) > img'
).attr('alt')
return rating
? {
system: 'VET',
value: rating.replace(/\(|\)/g, '')
}
: null
}
function parseCategories($item) {
return $item('div.collapse > .badge')
.map((i, el) => $item(el).text().trim())
.get()
}
function parseSeason($item) {
const string = $item(
'div.d-flex.flex-row.bd-highlight > div.bd-highlight.flex-fill > span:nth-child(2)'
)
.text()
.trim()
if (!string) return null
let [, season] = string.match(/S(\d{2})/) || [null, null]
return season ? parseInt(season) : null
}
function parseEpisode($item) {
const string = $item(
'div.d-flex.flex-row.bd-highlight > div.bd-highlight.flex-fill > span:nth-child(2)'
)
.text()
.trim()
if (!string) return null
let [, episode] = string.match(/E(\d{2})/) || [null, null]
return episode ? parseInt(episode) : null
}
function parseStart($item, date) {
const [time] = $item('div.d-flex.flex-row.bd-highlight > div.bd-highlight.me-2')
.text()
.trim()
.split('-')
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', tz)
}
function parseStop($item, date) {
const [, time] = $item('div.d-flex.flex-row.bd-highlight > div.bd-highlight.me-2')
.text()
.trim()
.split('-')
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', tz)
}
function parseTitle($item) {
return $item('div.d-flex.flex-row.bd-highlight > div.bd-highlight.flex-fill > span:nth-child(1)')
.text()
.trim()
}
function parseDescription($item) {
return (
$item('div.collapse > p')
.text()
.replace(/\n/g, '')
.replace(/\s\s+/g, ' ')
// eslint-disable-next-line no-irregular-whitespace
.replace(/ /g, ' ')
.trim()
)
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('ul.list-group > li').toArray()
}
const doFetch = require('@ntlab/sfetch')
const cheerio = require('cheerio')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
const tz = 'Europe/Helsinki'
module.exports = {
site: 'tvkaista.org',
days: 2,
url({ channel, date }) {
return `https://www.tvkaista.org/${channel.site_id}/${date.format('YYYY-MM-DD')}`
},
parser({ 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)
let stop = parseStop($item, start)
if (prev) {
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
} else if (stop.isBefore(start)) {
stop = stop.add(1, 'd')
date = date.add(1, 'd')
}
} else {
if (start.hour() > 18) {
start = start.subtract(1, 'd')
date = date.subtract(1, 'd')
}
}
programs.push({
title: parseTitle($item),
description: parseDescription($item),
season: parseSeason($item),
episode: parseEpisode($item),
categories: parseCategories($item),
rating: parseRating($item),
start,
stop
})
})
return programs
},
async channels() {
let channels = []
const queue = ['https://www.tvkaista.org/', 'https://www.tvkaista.org/maksukanavat/']
await doFetch(queue, (url, res) => {
const $ = cheerio.load(res)
$('body > main > div > div.row > div').each((i, el) => {
const link = $(el).find('div > div > div > div.col-auto > a')
const img = link.find('img.channel-logo')
const name = link.text().trim() || img.attr('alt')
const [, site_id] = link.attr('href').split('/')
channels.push({
lang: 'fi',
name,
site_id
})
})
})
return channels
}
}
function parseRating($item) {
let rating = $item(
'div.d-flex.flex-row.bd-highlight > div.bd-highlight.flex-fill > span:nth-child(3) > img'
).attr('alt')
return rating
? {
system: 'VET',
value: rating.replace(/\(|\)/g, '')
}
: null
}
function parseCategories($item) {
return $item('div.collapse > .badge')
.map((i, el) => $item(el).text().trim())
.get()
}
function parseSeason($item) {
const string = $item(
'div.d-flex.flex-row.bd-highlight > div.bd-highlight.flex-fill > span:nth-child(2)'
)
.text()
.trim()
if (!string) return null
let [, season] = string.match(/S(\d{2})/) || [null, null]
return season ? parseInt(season) : null
}
function parseEpisode($item) {
const string = $item(
'div.d-flex.flex-row.bd-highlight > div.bd-highlight.flex-fill > span:nth-child(2)'
)
.text()
.trim()
if (!string) return null
let [, episode] = string.match(/E(\d{2})/) || [null, null]
return episode ? parseInt(episode) : null
}
function parseStart($item, date) {
const [time] = $item('div.d-flex.flex-row.bd-highlight > div.bd-highlight.me-2')
.text()
.trim()
.split('-')
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', tz)
}
function parseStop($item, date) {
const [, time] = $item('div.d-flex.flex-row.bd-highlight > div.bd-highlight.me-2')
.text()
.trim()
.split('-')
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', tz)
}
function parseTitle($item) {
return $item('div.d-flex.flex-row.bd-highlight > div.bd-highlight.flex-fill > span:nth-child(1)')
.text()
.trim()
}
function parseDescription($item) {
return (
$item('div.collapse > p')
.text()
.replace(/\n/g, '')
.replace(/\s\s+/g, ' ')
// eslint-disable-next-line no-irregular-whitespace
.replace(/ /g, ' ')
.trim()
)
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('ul.list-group > li').toArray()
}

View File

@@ -1,93 +1,93 @@
const { parser, url } = require('./tvkaista.org.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)
let date = dayjs.utc('2025-03-01', 'YYYY-MM-DD').startOf('d')
const channel = { site_id: 'yle-tv1' }
it('can generate valid url', () => {
expect(url({ channel, date })).toBe('https://www.tvkaista.org/yle-tv1/2025-03-01')
})
it('can parse response for today', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_1.html'))
let results = parser({ content, date })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(45)
expect(results[0]).toMatchObject({
title: 'Alice & Jack',
description:
'Kausi 1, 2/6. Säröjä. Jack on onnellisesti naimisissa, ja on pienen tyttären isä. Yllättävä puhelu Alicelta suistaa Jackin elämän kuitenkin pois raiteiltaan. Tunteiden myllerryksessä Jack suostuu tapaamaan Alicen salassa vaimoltaa',
season: 1,
episode: 2,
rating: {
system: 'VET',
value: '12'
},
categories: ['Sarja'],
start: '2025-02-28T21:20:00.000Z',
stop: '2025-02-28T22:04:00.000Z'
})
})
it('can parse response for next day', () => {
date = dayjs.utc('2025-03-03', 'YYYY-MM-DD').startOf('d')
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_2.html'))
let results = parser({ content, date })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(39)
expect(results[0]).toMatchObject({
title: 'Sodan silpoma elämä',
description:
'Oleh Stahanov haavoittui vakavasti Itä-Ukrainan rintamalla. Miten elämä rakennetaan uudelleen, kun toipuminen vaatii selviytymistä niin fyysisistä vammoista kuin henkisestä taakastakin? Ohjaus: Viivi Berghem (Suomi 2024)',
start: '2025-03-02T21:05:00.000Z',
stop: '2025-03-02T22:02:00.000Z'
})
expect(results[5]).toMatchObject({
title: 'La Promesa - Salaisuuksien kartano',
description:
'Kausi 1, 3/122. Päätöksen vaikeus. Jimena pääsee lennolle Manuelin kanssa tämän tunnustettua ensin lentokilpailuun osallistumisensa. Johtaako lento näiden kahden lähentymiseen? Onko mysteerikokin henkilöllisy',
season: 1,
episode: 3,
categories: ['Sarja'],
rating: {
system: 'VET',
value: '12'
},
start: '2025-03-03T08:00:00.000Z',
stop: '2025-03-03T08:52:00.000Z'
})
expect(results[38]).toMatchObject({
title: 'Unelma työstä',
description:
'Noin miljoona suomalaista on joko työttömänä tai työskentelee osa- tai määräaikaisessa työsuhteessa. Dokumentissa tarinansa kertoo entinen työministeri, loppuun palanut oikeustieteen tohtori, akateeminen pätkätyöläinen ja nuori teatte',
start: '2025-03-03T21:15:00.000Z',
stop: '2025-03-03T22:11:00.000Z'
})
})
it('can handle empty guide', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
const results = parser({ content, date })
expect(results).toMatchObject([])
})
const { parser, url } = require('./tvkaista.org.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)
let date = dayjs.utc('2025-03-01', 'YYYY-MM-DD').startOf('d')
const channel = { site_id: 'yle-tv1' }
it('can generate valid url', () => {
expect(url({ channel, date })).toBe('https://www.tvkaista.org/yle-tv1/2025-03-01')
})
it('can parse response for today', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_1.html'))
let results = parser({ content, date })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(45)
expect(results[0]).toMatchObject({
title: 'Alice & Jack',
description:
'Kausi 1, 2/6. Säröjä. Jack on onnellisesti naimisissa, ja on pienen tyttären isä. Yllättävä puhelu Alicelta suistaa Jackin elämän kuitenkin pois raiteiltaan. Tunteiden myllerryksessä Jack suostuu tapaamaan Alicen salassa vaimoltaa',
season: 1,
episode: 2,
rating: {
system: 'VET',
value: '12'
},
categories: ['Sarja'],
start: '2025-02-28T21:20:00.000Z',
stop: '2025-02-28T22:04:00.000Z'
})
})
it('can parse response for next day', () => {
date = dayjs.utc('2025-03-03', 'YYYY-MM-DD').startOf('d')
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_2.html'))
let results = parser({ content, date })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(39)
expect(results[0]).toMatchObject({
title: 'Sodan silpoma elämä',
description:
'Oleh Stahanov haavoittui vakavasti Itä-Ukrainan rintamalla. Miten elämä rakennetaan uudelleen, kun toipuminen vaatii selviytymistä niin fyysisistä vammoista kuin henkisestä taakastakin? Ohjaus: Viivi Berghem (Suomi 2024)',
start: '2025-03-02T21:05:00.000Z',
stop: '2025-03-02T22:02:00.000Z'
})
expect(results[5]).toMatchObject({
title: 'La Promesa - Salaisuuksien kartano',
description:
'Kausi 1, 3/122. Päätöksen vaikeus. Jimena pääsee lennolle Manuelin kanssa tämän tunnustettua ensin lentokilpailuun osallistumisensa. Johtaako lento näiden kahden lähentymiseen? Onko mysteerikokin henkilöllisy',
season: 1,
episode: 3,
categories: ['Sarja'],
rating: {
system: 'VET',
value: '12'
},
start: '2025-03-03T08:00:00.000Z',
stop: '2025-03-03T08:52:00.000Z'
})
expect(results[38]).toMatchObject({
title: 'Unelma työstä',
description:
'Noin miljoona suomalaista on joko työttömänä tai työskentelee osa- tai määräaikaisessa työsuhteessa. Dokumentissa tarinansa kertoo entinen työministeri, loppuun palanut oikeustieteen tohtori, akateeminen pätkätyöläinen ja nuori teatte',
start: '2025-03-03T21:15:00.000Z',
stop: '2025-03-03T22:11:00.000Z'
})
})
it('can handle empty guide', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
const results = parser({ content, date })
expect(results).toMatchObject([])
})