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",
"license": "MIT",
"dependencies": {
"@freearhey/iso-639-3": "^1.0.0",
"axios": "^0.21.4",
"commander": "^7.0.0",
"iptv-checker": "^0.21.0",
@ -560,11 +559,6 @@
"resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz",
"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": {
"version": "1.1.0",
"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",
"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": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",

View File

@ -10,7 +10,6 @@
"private": true,
"license": "MIT",
"dependencies": {
"@freearhey/iso-639-3": "^1.0.0",
"axios": "^0.21.4",
"commander": "^7.0.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
updateTvgName(channel)
updateTvgId(channel, playlist)
updateTvgCountry(channel, playlist)
updateTvgCountry(channel)
normalizeUrl(channel)
const data = channels[channel.tvg.id]
@ -217,9 +217,9 @@ function updateTvgId(channel, playlist) {
}
}
function updateTvgCountry(channel, playlist) {
const code = playlist.country.code
if (!channel.countries.length) {
function updateTvgCountry(channel) {
if (!channel.countries.length && channel.tvg.id) {
const code = channel.tvg.id.split('.')[1] || null
const name = utils.code2name(code)
channel.countries = name ? [{ code, name }] : []
channel.tvg.country = channel.countries.map(c => c.code.toUpperCase()).join(';')
@ -237,8 +237,13 @@ function updateLogo(channel, data, epgData) {
}
function updateTvgLanguage(channel, data) {
if (!channel.tvg.language && data) {
channel.tvg.language = data.languages.map(l => l.name).join(';')
if (!channel.tvg.language) {
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 iso6393 = require('@freearhey/iso-639-3')
const transliteration = require('transliteration')
const countries = require('../data/countries')
const categories = require('../data/categories')
const languages = require('../data/languages')
const regions = require('../data/regions')
const utils = {}
@ -50,11 +51,19 @@ utils.code2name = function (code) {
}
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
}
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) {
fields = fields.map(field => {
if (field === 'resolution.height') return channel => channel.resolution.height || 0