Pass page content to logo function

This commit is contained in:
freearhey 2021-03-20 13:55:09 +03:00
parent 7f570aaffa
commit e7be20be41
2 changed files with 26 additions and 18 deletions

View File

@ -26,7 +26,6 @@ async function main() {
const queue = []
channels.forEach(channel => {
channel.logo = config.logo ? config.logo({ channel }) : null
dates.forEach(date => {
queue.push({ date, channel })
})
@ -39,24 +38,11 @@ async function main() {
const progs = await client
.get(url)
.then(response => {
const parserOptions = Object.assign({}, item, config, {
content: response.data
})
const programs = config
.parser(parserOptions)
.filter(i => i)
.map(p => {
p.channel = item.channel.xmltv_id
return p
})
item.channel.logo = config.logo
? config.logo({ channel: item.channel, content: response.data })
: null
console.log(
` ${config.site} - ${item.channel.xmltv_id} - ${item.date.format('MMM D, YYYY')} (${
programs.length
} programs)`
)
return programs
return utils.parsePrograms({ response, item, config })
})
.then(utils.sleep(config.delay))
.catch(err => {

View File

@ -137,6 +137,28 @@ utils.convertToXMLTV = function ({ config, channels, programs }) {
return output
}
utils.parsePrograms = function ({ response, item, config }) {
const options = Object.assign({}, item, config, {
content: response.data
})
const programs = config
.parser(options)
.filter(i => i)
.map(p => {
p.channel = item.channel.xmltv_id
return p
})
console.log(
` ${config.site} - ${item.channel.xmltv_id} - ${item.date.format('MMM D, YYYY')} (${
programs.length
} programs)`
)
return programs
}
utils.writeToFile = function (filename, data) {
const dir = path.resolve(path.dirname(filename))
if (!fs.existsSync(dir)) {