Fixes linter errors

This commit is contained in:
freearhey 2023-10-15 14:08:23 +03:00
parent 57e508fc3b
commit 63c86a2b30
393 changed files with 28447 additions and 28443 deletions

View file

@ -1,88 +1,88 @@
const axios = require('axios')
const cheerio = require('cheerio')
const { DateTime } = require('luxon')
module.exports = {
site: 'tv.dir.bg',
days: 2,
url({ channel, date }) {
return `https://tv.dir.bg/tv_channel.php?id=${channel.site_id}&dd=${date.format('DD.MM')}`
},
parser({ content, date }) {
const programs = []
const items = parseItems(content)
items.forEach(item => {
const $item = cheerio.load(item)
const prev = programs[programs.length - 1]
let start = parseStart($item, date)
if (!start) return
if (prev) {
if (start < prev.start) {
start = start.plus({ days: 1 })
date = date.add(1, 'd')
}
prev.stop = start
}
const stop = start.plus({ minutes: 30 })
programs.push({
title: parseTitle($item),
start,
stop
})
})
return programs
},
async channels() {
const requests = [
axios.get('https://tv.dir.bg/programata.php?t=0'),
axios.get('https://tv.dir.bg/programata.php?t=1')
]
const items = await Promise.all(requests)
.then(r => {
return r
.map(i => {
const html = i.data
const $ = cheerio.load(html)
return $('#programa-left > div > div > div > a').toArray()
})
.reduce((acc, curr) => {
acc = acc.concat(curr)
return acc
}, [])
})
.catch(console.log)
const $ = cheerio.load('')
return items.map(item => {
const $item = $(item)
return {
lang: 'bg',
site_id: $item.attr('href').replace('tv_channel.php?id=', ''),
name: $item.find('div.thumbnail > img').attr('alt')
}
})
}
}
function parseStart($item, date) {
const time = $item('i').text()
if (!time) return null
const dateString = `${date.format('MM/DD/YYYY')} ${time}`
return DateTime.fromFormat(dateString, 'MM/dd/yyyy HH.mm', { zone: 'Europe/Sofia' }).toUTC()
}
function parseTitle($item) {
return $item
.text()
.replace(/^\d{2}.\d{2}/, '')
.trim()
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('#events > li').toArray()
}
const axios = require('axios')
const cheerio = require('cheerio')
const { DateTime } = require('luxon')
module.exports = {
site: 'tv.dir.bg',
days: 2,
url({ channel, date }) {
return `https://tv.dir.bg/tv_channel.php?id=${channel.site_id}&dd=${date.format('DD.MM')}`
},
parser({ content, date }) {
const programs = []
const items = parseItems(content)
items.forEach(item => {
const $item = cheerio.load(item)
const prev = programs[programs.length - 1]
let start = parseStart($item, date)
if (!start) return
if (prev) {
if (start < prev.start) {
start = start.plus({ days: 1 })
date = date.add(1, 'd')
}
prev.stop = start
}
const stop = start.plus({ minutes: 30 })
programs.push({
title: parseTitle($item),
start,
stop
})
})
return programs
},
async channels() {
const requests = [
axios.get('https://tv.dir.bg/programata.php?t=0'),
axios.get('https://tv.dir.bg/programata.php?t=1')
]
const items = await Promise.all(requests)
.then(r => {
return r
.map(i => {
const html = i.data
const $ = cheerio.load(html)
return $('#programa-left > div > div > div > a').toArray()
})
.reduce((acc, curr) => {
acc = acc.concat(curr)
return acc
}, [])
})
.catch(console.log)
const $ = cheerio.load('')
return items.map(item => {
const $item = $(item)
return {
lang: 'bg',
site_id: $item.attr('href').replace('tv_channel.php?id=', ''),
name: $item.find('div.thumbnail > img').attr('alt')
}
})
}
}
function parseStart($item, date) {
const time = $item('i').text()
if (!time) return null
const dateString = `${date.format('MM/DD/YYYY')} ${time}`
return DateTime.fromFormat(dateString, 'MM/dd/yyyy HH.mm', { zone: 'Europe/Sofia' }).toUTC()
}
function parseTitle($item) {
return $item
.text()
.replace(/^\d{2}.\d{2}/, '')
.trim()
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('#events > li').toArray()
}

View file

@ -1,57 +1,57 @@
// node ./scripts/commands/parse-channels.js --config=./sites/tv.dir.bg/tv.dir.bg.config.js --output=./sites/tv.dir.bg/tv.dir.bg.channels.xml
// npm run grab -- --site=tv.dir.bg
const { parser, url } = require('./tv.dir.bg.config.js')
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-01-20', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '12',
xmltv_id: 'BTV.bg'
}
it('can generate valid url', () => {
expect(url({ channel, date })).toBe('https://tv.dir.bg/tv_channel.php?id=12&dd=20.01')
})
it('can parse response', () => {
const content =
'<!DOCTYPE html><html><head></head><body><div class="container" id="news"><div class="row"><div class="col-sm-12 col-md-5"><ul id="events"><li><i></i> <div class="progress"> <div class="progress-bar progress-bar-striped active" role="progressbar" style="width:99%"> </div></div></li><li><a href="tv_show_info.php?id"="10"><i>06.00</i>„<b>Тази сутрин</b>” - информационно предаване с водещи Златимир Йочеви Биляна Гавазова</a></li><li><i>15.00</i>„Доктор Чудо” - сериал, еп.71</li><li><a href="tv_show_info.php?id"="1601"><i>05.30</i>„<b>Лице в лице</b>” /п./ </a></li></ul></div></div></div></body></html>'
const result = parser({ content, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2022-01-20T04:00:00.000Z',
stop: '2022-01-20T13:00:00.000Z',
title: '„Тази сутрин” - информационно предаване с водещи Златимир Йочеви Биляна Гавазова'
},
{
start: '2022-01-20T13:00:00.000Z',
stop: '2022-01-21T03:30:00.000Z',
title: '„Доктор Чудо” - сериал, еп.71'
},
{
start: '2022-01-21T03:30:00.000Z',
stop: '2022-01-21T04:00:00.000Z',
title: '„Лице в лице” /п./'
}
])
})
it('can handle empty guide', () => {
const result = parser({
date,
channel,
content:
'<!DOCTYPE html><html><head></head><body><div class="container" id="news"><div class="row"><div class="col-sm-12 col-md-5"><ul id="events"></ul></div></div></div></body></html>'
})
expect(result).toMatchObject([])
})
// node ./scripts/commands/parse-channels.js --config=./sites/tv.dir.bg/tv.dir.bg.config.js --output=./sites/tv.dir.bg/tv.dir.bg.channels.xml
// npm run grab -- --site=tv.dir.bg
const { parser, url } = require('./tv.dir.bg.config.js')
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-01-20', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '12',
xmltv_id: 'BTV.bg'
}
it('can generate valid url', () => {
expect(url({ channel, date })).toBe('https://tv.dir.bg/tv_channel.php?id=12&dd=20.01')
})
it('can parse response', () => {
const content =
'<!DOCTYPE html><html><head></head><body><div class="container" id="news"><div class="row"><div class="col-sm-12 col-md-5"><ul id="events"><li><i></i> <div class="progress"> <div class="progress-bar progress-bar-striped active" role="progressbar" style="width:99%"> </div></div></li><li><a href="tv_show_info.php?id"="10"><i>06.00</i>„<b>Тази сутрин</b>” - информационно предаване с водещи Златимир Йочеви Биляна Гавазова</a></li><li><i>15.00</i>„Доктор Чудо” - сериал, еп.71</li><li><a href="tv_show_info.php?id"="1601"><i>05.30</i>„<b>Лице в лице</b>” /п./ </a></li></ul></div></div></div></body></html>'
const result = parser({ content, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2022-01-20T04:00:00.000Z',
stop: '2022-01-20T13:00:00.000Z',
title: '„Тази сутрин” - информационно предаване с водещи Златимир Йочеви Биляна Гавазова'
},
{
start: '2022-01-20T13:00:00.000Z',
stop: '2022-01-21T03:30:00.000Z',
title: '„Доктор Чудо” - сериал, еп.71'
},
{
start: '2022-01-21T03:30:00.000Z',
stop: '2022-01-21T04:00:00.000Z',
title: '„Лице в лице” /п./'
}
])
})
it('can handle empty guide', () => {
const result = parser({
date,
channel,
content:
'<!DOCTYPE html><html><head></head><body><div class="container" id="news"><div class="row"><div class="col-sm-12 col-md-5"><ul id="events"></ul></div></div></div></body></html>'
})
expect(result).toMatchObject([])
})