From 16bec418fef366802dfdce5324592268b3418c49 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 19 Sep 2021 10:43:57 +0300 Subject: [PATCH 1/5] Update Channel.js --- scripts/helpers/Channel.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/helpers/Channel.js b/scripts/helpers/Channel.js index aa10bc8800..8d4a97f57f 100644 --- a/scripts/helpers/Channel.js +++ b/scripts/helpers/Channel.js @@ -109,9 +109,11 @@ module.exports = class Channel { } getInfo() { - let info = `-1 tvg-id="${this.tvg.id}" tvg-country="${this.tvg.country}" tvg-language="${this.tvg.language}" tvg-logo="${this.logo}"` + let info = `-1 tvg-id="${this.tvg.id}" tvg-country="${this.tvg.country || ''}" tvg-language="${ + this.tvg.language || '' + }" tvg-logo="${this.logo || ''}"` - info += ` group-title="${this.group.title}",${this.name}` + info += ` group-title="${this.group.title || ''}",${this.name}` if (this.resolution.height) { info += ` (${this.resolution.height}p)` From 4260ab0a278e14e6ec170c0d2295f7cc0ab730d3 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 19 Sep 2021 10:44:07 +0300 Subject: [PATCH 2/5] Update format.js --- scripts/format.js | 72 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/scripts/format.js b/scripts/format.js index b89329c0d5..11767dd312 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -1,6 +1,7 @@ -const IPTVChecker = require('iptv-checker') -const normalize = require('normalize-url') +const axios = require('axios') const { program } = require('commander') +const normalize = require('normalize-url') +const IPTVChecker = require('iptv-checker') const parser = require('./helpers/parser') const utils = require('./helpers/utils') const file = require('./helpers/file') @@ -38,6 +39,27 @@ async function main() { log.finish() } +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`) @@ -53,11 +75,21 @@ async function updatePlaylist(playlist) { buffer = {} origins = {} + const channels = await loadChannelJson() for (const [i, channel] of playlist.channels.entries()) { const curr = i + 1 - updateDescription(channel, playlist) + updateTvgName(channel) + updateTvgId(channel, playlist) + updateTvgCountry(channel, playlist) normalizeUrl(channel) + const data = channels[channel.tvg.id] + if (data) { + updateLogo(channel, data) + updateGroupTitle(channel, data) + updateTvgLanguage(channel, data) + } + if (config.offline || ignoreStatus.includes(channel.status)) { continue } @@ -186,21 +218,45 @@ function parseRequests(requests) { return requests } -function updateDescription(channel, playlist) { +function updateTvgName(channel) { + if (!channel.tvg.name) { + channel.tvg.name = channel.name.replace(/\"/gi, '') + } +} + +function updateTvgId(channel, playlist) { const code = playlist.country.code - // tvg-id if (!channel.tvg.id && channel.tvg.name) { const id = utils.name2id(channel.tvg.name) channel.tvg.id = id ? `${id}.${code}` : '' } - // country +} + +function updateTvgCountry(channel, playlist) { + const code = playlist.country.code if (!channel.countries.length) { const name = utils.code2name(code) channel.countries = name ? [{ code, name }] : [] channel.tvg.country = channel.countries.map(c => c.code.toUpperCase()).join(';') } - // group-title - channel.group.title = channel.category +} + +function updateLogo(channel, data) { + if (!channel.logo) { + channel.logo = data.logo + } +} + +function updateTvgLanguage(channel, data) { + if (!channel.tvg.language) { + channel.tvg.language = data.languages.map(l => l.name).join(';') + } +} + +function updateGroupTitle(channel, data) { + if (!channel.group.title) { + channel.group.title = channel.category || data.category || '' + } } function normalizeUrl(channel) { From 88fce9c93ebc798a882304e63ff7d2bb68e7546f Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 19 Sep 2021 11:20:50 +0300 Subject: [PATCH 3/5] Update format.js --- scripts/format.js | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/scripts/format.js b/scripts/format.js index 11767dd312..87e896b315 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -6,6 +6,7 @@ const parser = require('./helpers/parser') const utils = require('./helpers/utils') const file = require('./helpers/file') const log = require('./helpers/log') +const epg = require('./helpers/epg') const ignoreStatus = ['Geo-blocked', 'Not 24/7'] @@ -39,6 +40,19 @@ 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') @@ -76,6 +90,7 @@ async function updatePlaylist(playlist) { buffer = {} origins = {} const channels = await loadChannelJson() + const codes = await loadCodes() for (const [i, channel] of playlist.channels.entries()) { const curr = i + 1 updateTvgName(channel) @@ -84,11 +99,10 @@ async function updatePlaylist(playlist) { normalizeUrl(channel) const data = channels[channel.tvg.id] - if (data) { - updateLogo(channel, data) - updateGroupTitle(channel, data) - updateTvgLanguage(channel, data) - } + const epgData = codes[channel.tvg.id] + updateLogo(channel, data, epgData) + updateGroupTitle(channel, data) + updateTvgLanguage(channel, data) if (config.offline || ignoreStatus.includes(channel.status)) { continue @@ -241,20 +255,24 @@ function updateTvgCountry(channel, playlist) { } } -function updateLogo(channel, data) { +function updateLogo(channel, data, epgData) { if (!channel.logo) { - channel.logo = data.logo + if (data) { + channel.logo = data.logo + } else if (epgData) { + channel.logo = epgData.logo + } } } function updateTvgLanguage(channel, data) { - if (!channel.tvg.language) { + if (!channel.tvg.language && data) { channel.tvg.language = data.languages.map(l => l.name).join(';') } } function updateGroupTitle(channel, data) { - if (!channel.group.title) { + if (!channel.group.title && data) { channel.group.title = channel.category || data.category || '' } } From a9265451d156f0f36307f139c7d4874432b24c99 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 19 Sep 2021 11:29:39 +0300 Subject: [PATCH 4/5] 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() From e4b6e5707a54af521bf115162a9292f82fa11a70 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 19 Sep 2021 15:08:10 +0300 Subject: [PATCH 5/5] Update format.js --- scripts/format.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/format.js b/scripts/format.js index ce6c8d1deb..08e12fe387 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -56,7 +56,7 @@ async function updatePlaylist(playlist) { let channels = {} let codes = {} if (!config.offline) { - channels = await loadChannelJson() + channels = await loadChannelsJson() codes = await loadCodes() } @@ -271,7 +271,7 @@ function loadCodes() { .catch(console.log) } -function loadChannelJson() { +function loadChannelsJson() { return axios .get('https://iptv-org.github.io/iptv/channels.json') .then(r => r.data)