Update update.js

This commit is contained in:
Aleksandr Statciuk 2022-10-27 19:16:17 +03:00
parent 03cd08b786
commit 3c16d29889

View file

@ -63,8 +63,9 @@ async function main() {
let countryPrograms = db_programs.filter(p => countryChannels.includes(p.channel)) let countryPrograms = db_programs.filter(p => countryChannels.includes(p.channel))
let langGroups = _.groupBy(countryPrograms, 'lang') let langGroups = _.groupBy(countryPrograms, 'lang')
let countryLanguages = _.uniq(['eng', ...country.languages]) let countryLanguages = _.uniq([...country.languages, 'eng'])
let programs = {}
for (let langCode of countryLanguages) { for (let langCode of countryLanguages) {
const lang = convertLangCode(langCode, '3', '1') const lang = convertLangCode(langCode, '3', '1')
if (!lang) continue if (!lang) continue
@ -72,54 +73,57 @@ async function main() {
let langPrograms = langGroups[lang] let langPrograms = langGroups[lang]
if (!langPrograms || !langPrograms.length) continue if (!langPrograms || !langPrograms.length) continue
let programs = []
let channelGroups = _.groupBy(langPrograms, 'channel') let channelGroups = _.groupBy(langPrograms, 'channel')
for (let groupedPrograms of Object.values(channelGroups)) { for (let channel in channelGroups) {
if (programs[channel]) continue
let groupedPrograms = channelGroups[channel]
let channelPrograms = getChannelPrograms(groupedPrograms) let channelPrograms = getChannelPrograms(groupedPrograms)
if (!channelPrograms.length) continue if (!channelPrograms.length) continue
programs = programs.concat(channelPrograms) programs[channel] = channelPrograms
} }
programs = _.sortBy(programs, ['channel', 'start']) }
programs = programs.map(p => new Program(p, new Channel(channels_dic[p.channel])))
let channels = programs.map(p => {
let c = channels_dic[p.channel]
c.site = p.site
c.lang = lang
return new Channel(c) programs = _.flatten(Object.values(programs))
}) programs = programs = _.sortBy(programs, ['channel', 'start'])
channels = _.sortBy(channels, 'id') programs = programs.map(p => new Program(p, new Channel(channels_dic[p.channel])))
channels = _.uniqBy(channels, 'id') let channels = programs.map(p => {
let c = channels_dic[p.channel]
c.site = p.site
c.lang = p.lang
const filename = `${country.code.toLowerCase()}_${lang}` return new Channel(c)
const xmlFilepath = `${PUBLIC_DIR}/guides/${filename}.xml` })
const gzFilepath = `${PUBLIC_DIR}/guides/${filename}.xml.gz` channels = _.sortBy(channels, 'id')
const jsonFilepath = `${PUBLIC_DIR}/guides/${filename}.json` channels = _.uniqBy(channels, 'id')
logger.info(`creating ${xmlFilepath}...`)
const xmltv = generateXMLTV({
channels,
programs,
date: CURR_DATE
})
await file.create(xmlFilepath, xmltv)
logger.info(`creating ${gzFilepath}...`)
const compressed = await zip.compress(xmltv)
await file.create(gzFilepath, compressed)
logger.info(`creating ${jsonFilepath}...`)
await file.create(jsonFilepath, JSON.stringify({ channels, programs }))
for (let channel of channels) { const filename = country.code.toLowerCase()
let result = { const xmlFilepath = `${PUBLIC_DIR}/guides/${filename}.xml`
country: country.code, const gzFilepath = `${PUBLIC_DIR}/guides/${filename}.xml.gz`
lang, const jsonFilepath = `${PUBLIC_DIR}/guides/${filename}.json`
site: channel.site, logger.info(`creating ${xmlFilepath}...`)
channel: channel.id, const xmltv = generateXMLTV({
filename channels,
} programs,
date: CURR_DATE
})
await file.create(xmlFilepath, xmltv)
logger.info(`creating ${gzFilepath}...`)
const compressed = await zip.compress(xmltv)
await file.create(gzFilepath, compressed)
logger.info(`creating ${jsonFilepath}...`)
await file.create(jsonFilepath, JSON.stringify({ channels, programs }))
await file.append(logPath, JSON.stringify(result) + '\r\n') for (let channel of channels) {
let result = {
country: country.code,
lang: channel.lang,
site: channel.site,
channel: channel.id,
filename
} }
await file.append(logPath, JSON.stringify(result) + '\r\n')
} }
} }
} }