From 270557388e29cbd50ab09b222ca4a52236a8c5fb Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Tue, 10 Aug 2021 17:06:22 +0300 Subject: [PATCH] Update format.js --- scripts/format.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/format.js b/scripts/format.js index af382fb4fe..acc2fca3c8 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -1,4 +1,5 @@ const IPTVChecker = require('iptv-checker') +const normalize = require('normalize-url') const { program } = require('commander') const ProgressBar = require('progress') const parser = require('./helpers/parser') @@ -61,6 +62,9 @@ async function updatePlaylist(playlist) { for (const channel of playlist.channels) { addMissingData(channel) + updateGroupTitle(channel) + normalizeUrl(channel) + const checkOnline = config.status || config.resolution const skipChannel = channel.status && @@ -119,25 +123,32 @@ function updateStatus(channel, status) { } function addMissingData(channel) { - // add tvg-name + // tvg-name if (!channel.tvg.name && channel.name) { channel.tvg.name = channel.name.replace(/\"/gi, '') } - // add tvg-id + // tvg-id if (!channel.tvg.id && channel.tvg.name) { const id = utils.name2id(channel.tvg.name) channel.tvg.id = id ? `${id}.${code}` : '' } - // add country + // country 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(';') } - // update group-title +} + +function updateGroupTitle(channel) { channel.group.title = channel.category } +function normalizeUrl(channel) { + const normalized = normalize(channel.url, { stripWWW: false }) + channel.updateUrl(normalized) +} + function updateResolution(channel, metadata) { const streams = metadata ? metadata.streams.filter(stream => stream.codec_type === 'video') : [] if (!channel.resolution.height && streams.length) {