Make code prettier
This commit is contained in:
parent
d9bef97c88
commit
97f0454d20
@ -16,20 +16,30 @@ async function main() {
|
|||||||
for (let item of index.items) {
|
for (let item of index.items) {
|
||||||
console.log(`Processing '${item.url}'...`)
|
console.log(`Processing '${item.url}'...`)
|
||||||
let playlist = parsePlaylist(item.url)
|
let playlist = parsePlaylist(item.url)
|
||||||
if(config.debug) { console.log(`Sorting channels...`) }
|
if (config.debug) {
|
||||||
|
console.log(`Sorting channels...`)
|
||||||
|
}
|
||||||
playlist = sortChannels(playlist)
|
playlist = sortChannels(playlist)
|
||||||
if(config.debug) { console.log(`Removing duplicates...`) }
|
if (config.debug) {
|
||||||
|
console.log(`Removing duplicates...`)
|
||||||
|
}
|
||||||
playlist = removeDuplicates(playlist)
|
playlist = removeDuplicates(playlist)
|
||||||
|
|
||||||
if (config.epg) {
|
if (config.epg) {
|
||||||
const tvgUrl = playlist.header.attrs['x-tvg-url']
|
const tvgUrl = playlist.header.attrs['x-tvg-url']
|
||||||
if (tvgUrl) {
|
if (tvgUrl) {
|
||||||
if(config.debug) { console.log(`Loading EPG from '${tvgUrl}'...`) }
|
if (config.debug) {
|
||||||
|
console.log(`Loading EPG from '${tvgUrl}'...`)
|
||||||
|
}
|
||||||
const epg = await loadEPG(tvgUrl)
|
const epg = await loadEPG(tvgUrl)
|
||||||
if(config.debug) { console.log(`Adding the missing data from EPG...`) }
|
if (config.debug) {
|
||||||
|
console.log(`Adding the missing data from EPG...`)
|
||||||
|
}
|
||||||
playlist = addDataFromEPG(playlist, epg)
|
playlist = addDataFromEPG(playlist, epg)
|
||||||
} else {
|
} else {
|
||||||
if(config.debug) { console.log(`EPG source is not found`) }
|
if (config.debug) {
|
||||||
|
console.log(`EPG source is not found`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +78,9 @@ function parsePlaylist(url) {
|
|||||||
function sortChannels(playlist) {
|
function sortChannels(playlist) {
|
||||||
const channels = JSON.stringify(playlist.items)
|
const channels = JSON.stringify(playlist.items)
|
||||||
playlist.items = helper.sortBy(playlist.items, ['title', 'url'])
|
playlist.items = helper.sortBy(playlist.items, ['title', 'url'])
|
||||||
if(channels !== JSON.stringify(playlist.items)) { playlist.changed = true }
|
if (channels !== JSON.stringify(playlist.items)) {
|
||||||
|
playlist.changed = true
|
||||||
|
}
|
||||||
|
|
||||||
return playlist
|
return playlist
|
||||||
}
|
}
|
||||||
@ -82,13 +94,17 @@ function removeDuplicates(playlist) {
|
|||||||
if (result) {
|
if (result) {
|
||||||
buffer[i.url] = true
|
buffer[i.url] = true
|
||||||
} else {
|
} else {
|
||||||
if(config.debug) { console.log(`Duplicate of '${i.title}' has been removed`) }
|
if (config.debug) {
|
||||||
|
console.log(`Duplicate of '${i.title}' has been removed`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
|
|
||||||
if(channels !== JSON.stringify(playlist.items)) { playlist.changed = true }
|
if (channels !== JSON.stringify(playlist.items)) {
|
||||||
|
playlist.changed = true
|
||||||
|
}
|
||||||
|
|
||||||
return playlist
|
return playlist
|
||||||
}
|
}
|
||||||
@ -115,19 +131,25 @@ function addDataFromEPG(playlist, epg) {
|
|||||||
if (!item.name && channel.name.length) {
|
if (!item.name && channel.name.length) {
|
||||||
item.name = channel.name[0].value
|
item.name = channel.name[0].value
|
||||||
playlist.changed = true
|
playlist.changed = true
|
||||||
if(config.debug) { console.log(`Added tvg-name '${item.name}' to '${item.title}'`) }
|
if (config.debug) {
|
||||||
|
console.log(`Added tvg-name '${item.name}' to '${item.title}'`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.language && channel.name.length && channel.name[0].lang) {
|
if (!item.language && channel.name.length && channel.name[0].lang) {
|
||||||
item.language = channel.name[0].lang
|
item.language = channel.name[0].lang
|
||||||
playlist.changed = true
|
playlist.changed = true
|
||||||
if(config.debug) { console.log(`Added tvg-language '${item.language}' to '${item.title}'`) }
|
if (config.debug) {
|
||||||
|
console.log(`Added tvg-language '${item.language}' to '${item.title}'`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.logo && channel.icon.length) {
|
if (!item.logo && channel.icon.length) {
|
||||||
item.logo = channel.icon[0]
|
item.logo = channel.icon[0]
|
||||||
playlist.changed = true
|
playlist.changed = true
|
||||||
if(config.debug) { console.log(`Added tvg-logo '${item.logo}' to '${item.title}'`) }
|
if (config.debug) {
|
||||||
|
console.log(`Added tvg-logo '${item.logo}' to '${item.title}'`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,11 @@ function main() {
|
|||||||
generateLanguages()
|
generateLanguages()
|
||||||
console.log('Done.\n')
|
console.log('Done.\n')
|
||||||
|
|
||||||
console.log(`Countries: ${Object.values(list.countries).length}. Languages: ${Object.values(list.languages).length}. Categories: ${Object.values(list.categories).length}. Channels: ${list.all.length}.`)
|
console.log(
|
||||||
|
`Countries: ${Object.values(list.countries).length}. Languages: ${
|
||||||
|
Object.values(list.languages).length
|
||||||
|
}. Categories: ${Object.values(list.categories).length}. Channels: ${list.all.length}.`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRootDirectory() {
|
function createRootDirectory() {
|
||||||
|
@ -30,10 +30,11 @@ function parseIndex() {
|
|||||||
const playlist = helper.parsePlaylist(rootItem.url)
|
const playlist = helper.parsePlaylist(rootItem.url)
|
||||||
const countryName = rootItem.name
|
const countryName = rootItem.name
|
||||||
const countryCode = helper.getBasename(rootItem.url).toLowerCase()
|
const countryCode = helper.getBasename(rootItem.url).toLowerCase()
|
||||||
const countryEpg = playlist.header.attrs['x-tvg-url'] ? `<code>${playlist.header.attrs['x-tvg-url']}</code>` : ''
|
const countryEpg = playlist.header.attrs['x-tvg-url']
|
||||||
|
? `<code>${playlist.header.attrs['x-tvg-url']}</code>`
|
||||||
|
: ''
|
||||||
|
|
||||||
for (let item of playlist.items) {
|
for (let item of playlist.items) {
|
||||||
|
|
||||||
// countries
|
// countries
|
||||||
if (countries[countryCode]) {
|
if (countries[countryCode]) {
|
||||||
countries[countryCode].channels++
|
countries[countryCode].channels++
|
||||||
@ -94,10 +95,18 @@ function generateCountriesTable() {
|
|||||||
|
|
||||||
function generateLanguagesTable() {
|
function generateLanguagesTable() {
|
||||||
output.languages.sort((a, b) => {
|
output.languages.sort((a, b) => {
|
||||||
if(a.language === 'Undefined') { return 1 }
|
if (a.language === 'Undefined') {
|
||||||
if(b.language === 'Undefined') { return -1 }
|
return 1
|
||||||
if(a.language < b.language) { return -1 }
|
}
|
||||||
if(a.language > b.language) { return 1 }
|
if (b.language === 'Undefined') {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if (a.language < b.language) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if (a.language > b.language) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
return 0
|
return 0
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -114,10 +123,18 @@ function generateLanguagesTable() {
|
|||||||
|
|
||||||
function generateCategoriesTable() {
|
function generateCategoriesTable() {
|
||||||
output.categories.sort((a, b) => {
|
output.categories.sort((a, b) => {
|
||||||
if(a.category === 'Other') { return 1 }
|
if (a.category === 'Other') {
|
||||||
if(b.category === 'Other') { return -1 }
|
return 1
|
||||||
if(a.category < b.category) { return -1 }
|
}
|
||||||
if(a.category > b.category) { return 1 }
|
if (b.category === 'Other') {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if (a.category < b.category) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if (a.category > b.category) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
return 0
|
return 0
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user