Merge pull request #5149 from iptv-org/update-format-js

Update format.js
This commit is contained in:
James E. Kemp 2021-10-23 16:46:50 -07:00 committed by GitHub
commit 9ca381c848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34042 additions and 20 deletions

11
package-lock.json generated
View File

@ -7,7 +7,6 @@
"name": "iptv", "name": "iptv",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@freearhey/iso-639-3": "^1.0.0",
"axios": "^0.21.4", "axios": "^0.21.4",
"commander": "^7.0.0", "commander": "^7.0.0",
"iptv-checker": "^0.21.0", "iptv-checker": "^0.21.0",
@ -560,11 +559,6 @@
"resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz",
"integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==" "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw=="
}, },
"node_modules/@freearhey/iso-639-3": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@freearhey/iso-639-3/-/iso-639-3-1.0.0.tgz",
"integrity": "sha512-K4xgPkCktQakQcYv8WuV8gFWAWrAaTrQEVgr/KVdE8k10KL9QmYVw+8Qb9WbtpMr2VXDz5pDwIAEINU5KlnlAg=="
},
"node_modules/@istanbuljs/load-nyc-config": { "node_modules/@istanbuljs/load-nyc-config": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",
@ -4242,11 +4236,6 @@
"resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz",
"integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==" "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw=="
}, },
"@freearhey/iso-639-3": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@freearhey/iso-639-3/-/iso-639-3-1.0.0.tgz",
"integrity": "sha512-K4xgPkCktQakQcYv8WuV8gFWAWrAaTrQEVgr/KVdE8k10KL9QmYVw+8Qb9WbtpMr2VXDz5pDwIAEINU5KlnlAg=="
},
"@istanbuljs/load-nyc-config": { "@istanbuljs/load-nyc-config": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",

View File

@ -10,7 +10,6 @@
"private": true, "private": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@freearhey/iso-639-3": "^1.0.0",
"axios": "^0.21.4", "axios": "^0.21.4",
"commander": "^7.0.0", "commander": "^7.0.0",
"iptv-checker": "^0.21.0", "iptv-checker": "^0.21.0",

1002
scripts/data/countries.json Normal file

File diff suppressed because it is too large Load Diff

33018
scripts/data/languages.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -66,7 +66,7 @@ async function updatePlaylist(playlist) {
const curr = i + 1 const curr = i + 1
updateTvgName(channel) updateTvgName(channel)
updateTvgId(channel, playlist) updateTvgId(channel, playlist)
updateTvgCountry(channel, playlist) updateTvgCountry(channel)
normalizeUrl(channel) normalizeUrl(channel)
const data = channels[channel.tvg.id] const data = channels[channel.tvg.id]
@ -217,9 +217,9 @@ function updateTvgId(channel, playlist) {
} }
} }
function updateTvgCountry(channel, playlist) { function updateTvgCountry(channel) {
const code = playlist.country.code if (!channel.countries.length && channel.tvg.id) {
if (!channel.countries.length) { const code = channel.tvg.id.split('.')[1] || null
const name = utils.code2name(code) const name = utils.code2name(code)
channel.countries = name ? [{ code, name }] : [] channel.countries = name ? [{ code, name }] : []
channel.tvg.country = channel.countries.map(c => c.code.toUpperCase()).join(';') channel.tvg.country = channel.countries.map(c => c.code.toUpperCase()).join(';')
@ -237,8 +237,13 @@ function updateLogo(channel, data, epgData) {
} }
function updateTvgLanguage(channel, data) { function updateTvgLanguage(channel, data) {
if (!channel.tvg.language && data) { if (!channel.tvg.language) {
channel.tvg.language = data.languages.map(l => l.name).join(';') if (data) {
channel.tvg.language = data.languages.map(l => l.name).join(';')
} else if (channel.countries.length) {
const countryCode = channel.countries[0].code
channel.tvg.language = utils.country2language(countryCode)
}
} }
} }

View File

@ -1,7 +1,8 @@
const { orderBy } = require('natural-orderby') const { orderBy } = require('natural-orderby')
const iso6393 = require('@freearhey/iso-639-3')
const transliteration = require('transliteration') const transliteration = require('transliteration')
const countries = require('../data/countries')
const categories = require('../data/categories') const categories = require('../data/categories')
const languages = require('../data/languages')
const regions = require('../data/regions') const regions = require('../data/regions')
const utils = {} const utils = {}
@ -50,11 +51,19 @@ utils.code2name = function (code) {
} }
utils.language2code = function (name) { utils.language2code = function (name) {
const lang = iso6393.find(l => l.name === name) const lang = languages.find(l => l.name === name)
return lang && lang.code ? lang.code : null return lang && lang.code ? lang.code : null
} }
utils.country2language = function (code) {
const country = countries[code.toUpperCase()]
if (!country.languages.length) return ''
const language = languages.find(l => l.code === country.languages[0])
return language ? language.name : ''
}
utils.sortBy = function (arr, fields, order = null) { utils.sortBy = function (arr, fields, order = null) {
fields = fields.map(field => { fields = fields.map(field => {
if (field === 'resolution.height') return channel => channel.resolution.height || 0 if (field === 'resolution.height') return channel => channel.resolution.height || 0