From a9265451d156f0f36307f139c7d4874432b24c99 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 19 Sep 2021 11:29:39 +0300 Subject: [PATCH] Update format.js --- scripts/format.js | 77 +++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/scripts/format.js b/scripts/format.js index 87e896b315..ce6c8d1deb 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -40,40 +40,6 @@ async function main() { 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() { - return axios - .get('https://iptv-org.github.io/iptv/channels.json') - .then(r => r.data) - .then(channels => { - let output = {} - channels.forEach(channel => { - const item = output[channel.tvg.id] - if (!item) { - output[channel.tvg.id] = channel - } else { - item.logo = item.logo || channel.logo - item.languages = item.languages.length ? item.languages : channel.languages - item.category = item.category || channel.category - } - }) - return output - }) - .catch(console.log) -} - function savePlaylist(playlist) { if (file.read(playlist.url) !== playlist.toString()) { log.print(`File '${playlist.url}' has been updated\n`) @@ -87,10 +53,15 @@ async function updatePlaylist(playlist) { const total = playlist.channels.length log.print(`Processing '${playlist.url}'...\n`) + let channels = {} + let codes = {} + if (!config.offline) { + channels = await loadChannelJson() + codes = await loadCodes() + } + buffer = {} origins = {} - const channels = await loadChannelJson() - const codes = await loadCodes() for (const [i, channel] of playlist.channels.entries()) { const curr = i + 1 updateTvgName(channel) @@ -287,4 +258,38 @@ function parseNumber(str) { return parseInt(str) } +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() { + return axios + .get('https://iptv-org.github.io/iptv/channels.json') + .then(r => r.data) + .then(channels => { + let output = {} + channels.forEach(channel => { + const item = output[channel.tvg.id] + if (!item) { + output[channel.tvg.id] = channel + } else { + item.logo = item.logo || channel.logo + item.languages = item.languages.length ? item.languages : channel.languages + item.category = item.category || channel.category + } + }) + return output + }) + .catch(console.log) +} + main()