Update format.js

This commit is contained in:
Aleksandr Statciuk 2021-09-19 11:20:50 +03:00
parent 4260ab0a27
commit 88fce9c93e
1 changed files with 27 additions and 9 deletions

View File

@ -6,6 +6,7 @@ const parser = require('./helpers/parser')
const utils = require('./helpers/utils') const utils = require('./helpers/utils')
const file = require('./helpers/file') const file = require('./helpers/file')
const log = require('./helpers/log') const log = require('./helpers/log')
const epg = require('./helpers/epg')
const ignoreStatus = ['Geo-blocked', 'Not 24/7'] const ignoreStatus = ['Geo-blocked', 'Not 24/7']
@ -39,6 +40,19 @@ async function main() {
log.finish() log.finish()
} }
function loadCodes() {
return epg.codes
.load()
.then(codes => {
let output = {}
codes.forEach(item => {
output[item['tvg_id']] = item
})
return output
})
.catch(console.log)
}
function loadChannelJson() { function loadChannelJson() {
return axios return axios
.get('https://iptv-org.github.io/iptv/channels.json') .get('https://iptv-org.github.io/iptv/channels.json')
@ -76,6 +90,7 @@ async function updatePlaylist(playlist) {
buffer = {} buffer = {}
origins = {} origins = {}
const channels = await loadChannelJson() const channels = await loadChannelJson()
const codes = await loadCodes()
for (const [i, channel] of playlist.channels.entries()) { for (const [i, channel] of playlist.channels.entries()) {
const curr = i + 1 const curr = i + 1
updateTvgName(channel) updateTvgName(channel)
@ -84,11 +99,10 @@ async function updatePlaylist(playlist) {
normalizeUrl(channel) normalizeUrl(channel)
const data = channels[channel.tvg.id] const data = channels[channel.tvg.id]
if (data) { const epgData = codes[channel.tvg.id]
updateLogo(channel, data) updateLogo(channel, data, epgData)
updateGroupTitle(channel, data) updateGroupTitle(channel, data)
updateTvgLanguage(channel, data) updateTvgLanguage(channel, data)
}
if (config.offline || ignoreStatus.includes(channel.status)) { if (config.offline || ignoreStatus.includes(channel.status)) {
continue continue
@ -241,20 +255,24 @@ function updateTvgCountry(channel, playlist) {
} }
} }
function updateLogo(channel, data) { function updateLogo(channel, data, epgData) {
if (!channel.logo) { if (!channel.logo) {
if (data) {
channel.logo = data.logo channel.logo = data.logo
} else if (epgData) {
channel.logo = epgData.logo
}
} }
} }
function updateTvgLanguage(channel, data) { function updateTvgLanguage(channel, data) {
if (!channel.tvg.language) { if (!channel.tvg.language && data) {
channel.tvg.language = data.languages.map(l => l.name).join(';') channel.tvg.language = data.languages.map(l => l.name).join(';')
} }
} }
function updateGroupTitle(channel, data) { function updateGroupTitle(channel, data) {
if (!channel.group.title) { if (!channel.group.title && data) {
channel.group.title = channel.category || data.category || '' channel.group.title = channel.category || data.category || ''
} }
} }