Skip to content

Commit c43145c

Browse files
committed
Update programtv.onet.pl.config.js
1 parent 6e79424 commit c43145c

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

sites/programtv.onet.pl/programtv.onet.pl.config.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const axios = require('axios')
12
const cheerio = require('cheerio')
23
const dayjs = require('dayjs')
34
const utc = require('dayjs/plugin/utc')
@@ -15,10 +16,10 @@ module.exports = {
1516

1617
return `https://programtv.onet.pl/program-tv/${channel.site_id}?dzien=${day}`
1718
},
18-
parser: function ({ content, date }) {
19+
async parser({ content, date }) {
1920
const programs = []
2021
const items = parseItems(content)
21-
items.forEach(item => {
22+
for (const item of items) {
2223
const prev = programs[programs.length - 1]
2324
const $item = cheerio.load(item)
2425
let start = parseStart($item, date)
@@ -30,19 +31,27 @@ module.exports = {
3031
prev.stop = start
3132
}
3233
const stop = start.add(1, 'hour')
34+
35+
const programUrl = parseProgramUrl($item)
36+
const details = await loadProgramDetails(programUrl)
37+
let image
38+
if (details) {
39+
image = details.image
40+
}
41+
3342
programs.push({
3443
title: parseTitle($item),
3544
description: parseDescription($item),
45+
image,
3646
category: parseCategory($item),
3747
start,
3848
stop
3949
})
40-
})
50+
}
4151

4252
return programs
4353
},
4454
async channels() {
45-
const axios = require('axios')
4655
const data = await axios
4756
.get('https://programtv.onet.pl/stacje')
4857
.then(r => r.data)
@@ -67,6 +76,27 @@ module.exports = {
6776
}
6877
}
6978

79+
async function loadProgramDetails(url) {
80+
const html = await axios
81+
.get(url)
82+
.then(r => r.data)
83+
.catch(console.error)
84+
if (!html) return
85+
86+
const $ = cheerio.load(html)
87+
88+
return {
89+
image: $('meta[property="og:image"]').attr('content')
90+
}
91+
}
92+
93+
function parseProgramUrl($item) {
94+
const href = $item('.titles > a').attr('href')
95+
const url = new URL(href, 'https://programtv.onet.pl')
96+
97+
return url.href
98+
}
99+
70100
function parseStart($item, date) {
71101
const timeString = $item('.hours > .hour').text()
72102
const dateString = `${date.format('MM/DD/YYYY')} ${timeString}`

0 commit comments

Comments
 (0)