diff --git a/channels/us.m3u b/channels/us.m3u index fd0f0c5071..db42d1f2ba 100644 --- a/channels/us.m3u +++ b/channels/us.m3u @@ -1683,8 +1683,10 @@ https://a.jsrdn.com/broadcast/e6bdcb5ae9/+0000/c.m3u8 https://d155hi8td9k2ns.cloudfront.net/out/wapo-medialive3-rtmp/live.m3u8 #EXTINF:-1 tvg-id="TheWallStreetJournalLive.us" tvg-country="US" tvg-language="English" tvg-logo="https://i.imgur.com/ZzyXAKm.jpg" group-title="News",The Wall Street Journal Live (1080p) https://wsjlivehls-lh.akamaihd.net/i/events1_1@174990/master.m3u8 -#EXTINF:-1 tvg-id="TheWeatherChannel.us" tvg-country="US" tvg-language="English" tvg-logo="http://i.imgur.com/D4vJyy9.png" group-title="Weather",The Weather Channel (720p) [Geo-blocked] -https://weather-lh.akamaihd.net/i/twc_1@92006/master.m3u8 +#EXTINF:-1 tvg-id="TheWeatherChannel.us" tvg-country="US" tvg-language="English" tvg-logo="http://i.imgur.com/D4vJyy9.png" group-title="Weather",The Weather Channel +https://cdn88.theus6tv.tk/united-states/cable/the-weather-channel.m3u8 +#EXTINF:-1 tvg-id="TheWeatherChannel.us" tvg-country="US" tvg-language="English" tvg-logo="http://i.imgur.com/D4vJyy9.png" group-title="Weather",The Weather Channel (Alternative) +https://cdn88.theus6tv.tk/united-states/cable/the-weather-channel-alt.m3u8 #EXTINF:-1 tvg-id="ThisTVNetwork.us" tvg-country="US" tvg-language="English" tvg-logo="https://i.imgur.com/FQCVaSR.png" group-title="",This TV Network (480p) https://cdn.igocast.com/channel11_hls/channel11_master.m3u8 #EXTINF:-1 tvg-id="TNTEast.us" tvg-country="US" tvg-language="English" tvg-logo="https://i.imgur.com/xvL9KPI.png" group-title="General",TNT East [Geo-blocked] diff --git a/scripts/format.js b/scripts/format.js index b89329c0d5..08e12fe387 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -1,10 +1,12 @@ -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') const log = require('./helpers/log') +const epg = require('./helpers/epg') const ignoreStatus = ['Geo-blocked', 'Not 24/7'] @@ -51,13 +53,28 @@ async function updatePlaylist(playlist) { const total = playlist.channels.length log.print(`Processing '${playlist.url}'...\n`) + let channels = {} + let codes = {} + if (!config.offline) { + channels = await loadChannelsJson() + codes = await loadCodes() + } + buffer = {} origins = {} 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] + const epgData = codes[channel.tvg.id] + updateLogo(channel, data, epgData) + updateGroupTitle(channel, data) + updateTvgLanguage(channel, data) + if (config.offline || ignoreStatus.includes(channel.status)) { continue } @@ -186,21 +203,49 @@ 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, epgData) { + if (!channel.logo) { + if (data) { + channel.logo = data.logo + } else if (epgData) { + channel.logo = epgData.logo + } + } +} + +function updateTvgLanguage(channel, data) { + if (!channel.tvg.language && data) { + channel.tvg.language = data.languages.map(l => l.name).join(';') + } +} + +function updateGroupTitle(channel, data) { + if (!channel.group.title && data) { + channel.group.title = channel.category || data.category || '' + } } function normalizeUrl(channel) { @@ -213,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 loadChannelsJson() { + 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() 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)`