2019-11-02 10:45:09 +01:00
|
|
|
const helper = require('./helper')
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2019-11-01 20:15:22 +01:00
|
|
|
let output = {
|
2019-11-01 20:11:09 +01:00
|
|
|
countries: [],
|
|
|
|
languages: [],
|
|
|
|
categories: []
|
|
|
|
}
|
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
function main() {
|
2019-11-01 20:11:09 +01:00
|
|
|
console.log(`Parsing index...`)
|
|
|
|
parseIndex()
|
2019-11-01 19:13:15 +01:00
|
|
|
console.log(`Generating countries table...`)
|
|
|
|
generateCountriesTable()
|
|
|
|
console.log(`Generating languages table...`)
|
|
|
|
generateLanguagesTable()
|
|
|
|
console.log(`Generating categories table...`)
|
|
|
|
generateCategoriesTable()
|
|
|
|
console.log(`Generating README.md...`)
|
|
|
|
generateReadme()
|
|
|
|
console.log(`Done.`)
|
2019-11-01 17:34:05 +01:00
|
|
|
}
|
|
|
|
|
2019-11-01 20:11:09 +01:00
|
|
|
function parseIndex() {
|
2019-11-02 10:45:09 +01:00
|
|
|
const root = helper.parsePlaylist('index.m3u')
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2019-11-02 11:50:40 +01:00
|
|
|
let countries = {}
|
2019-11-01 20:11:09 +01:00
|
|
|
let languages = {}
|
|
|
|
let categories = {}
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let rootItem of root.items) {
|
2019-11-02 10:45:09 +01:00
|
|
|
const playlist = helper.parsePlaylist(rootItem.url)
|
2019-11-02 11:50:40 +01:00
|
|
|
const countryName = rootItem.name
|
|
|
|
const countryCode = helper.getBasename(rootItem.url).toLowerCase()
|
2020-04-11 03:34:50 +02:00
|
|
|
const countryEpg = playlist.header.attrs['x-tvg-url']
|
|
|
|
? `<code>${playlist.header.attrs['x-tvg-url']}</code>`
|
|
|
|
: ''
|
2019-11-01 20:11:09 +01:00
|
|
|
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let item of playlist.items) {
|
2019-11-04 10:46:57 +01:00
|
|
|
// countries
|
2020-04-11 03:34:50 +02:00
|
|
|
if (countries[countryCode]) {
|
2019-11-02 11:50:40 +01:00
|
|
|
countries[countryCode].channels++
|
|
|
|
} else {
|
2020-04-11 03:34:50 +02:00
|
|
|
countries[countryCode] = {
|
|
|
|
country: countryName,
|
|
|
|
channels: 1,
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/countries/${countryCode}.m3u</code>`,
|
2019-11-02 11:50:40 +01:00
|
|
|
epg: countryEpg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-04 10:46:57 +01:00
|
|
|
// languages
|
2019-11-01 20:15:22 +01:00
|
|
|
const languageName = item.tvg.language || 'Undefined'
|
2019-11-02 10:45:09 +01:00
|
|
|
const languageCode = helper.getISO6391Code(languageName) || 'undefined'
|
2020-04-11 03:34:50 +02:00
|
|
|
if (languages[languageCode]) {
|
2019-11-01 20:11:09 +01:00
|
|
|
languages[languageCode].channels++
|
|
|
|
} else {
|
2020-04-11 03:34:50 +02:00
|
|
|
languages[languageCode] = {
|
|
|
|
language: languageName,
|
|
|
|
channels: 1,
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/languages/${languageCode}.m3u</code>`
|
2019-11-01 20:11:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-04 10:46:57 +01:00
|
|
|
// categories
|
2019-11-02 10:45:09 +01:00
|
|
|
const categoryName = item.group.title || 'Other'
|
2019-11-01 20:11:09 +01:00
|
|
|
const categoryCode = categoryName.toLowerCase()
|
2020-04-11 03:34:50 +02:00
|
|
|
if (categories[categoryCode]) {
|
2019-11-01 20:11:09 +01:00
|
|
|
categories[categoryCode].channels++
|
|
|
|
} else {
|
2020-04-11 03:34:50 +02:00
|
|
|
categories[categoryCode] = {
|
|
|
|
category: categoryName,
|
|
|
|
channels: 1,
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/categories/${categoryCode}.m3u</code>`
|
2019-11-01 20:11:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-01 19:13:15 +01:00
|
|
|
}
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2019-11-02 11:50:40 +01:00
|
|
|
output.countries = Object.values(countries)
|
2019-11-01 20:15:22 +01:00
|
|
|
output.languages = Object.values(languages)
|
|
|
|
output.categories = Object.values(categories)
|
2019-11-01 20:11:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function generateCountriesTable() {
|
2019-11-02 10:45:09 +01:00
|
|
|
const table = helper.generateTable(output.countries, {
|
2019-11-01 19:13:15 +01:00
|
|
|
columns: [
|
|
|
|
{ name: 'Country', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
|
|
|
{ name: 'Playlist', align: 'left', nowrap: true },
|
|
|
|
{ name: 'EPG', align: 'left' }
|
|
|
|
]
|
|
|
|
})
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.createFile('./.readme/_countries.md', table)
|
2019-11-01 19:13:15 +01:00
|
|
|
}
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
function generateLanguagesTable() {
|
2019-11-01 20:15:22 +01:00
|
|
|
output.languages.sort((a, b) => {
|
2020-04-11 03:34:50 +02:00
|
|
|
if (a.language === 'Undefined') {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
if (b.language === 'Undefined') {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
if (a.language < b.language) {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
if (a.language > b.language) {
|
|
|
|
return 1
|
|
|
|
}
|
2019-11-01 17:34:05 +01:00
|
|
|
return 0
|
|
|
|
})
|
|
|
|
|
2019-11-02 10:45:09 +01:00
|
|
|
const table = helper.generateTable(output.languages, {
|
2019-11-01 17:34:05 +01:00
|
|
|
columns: [
|
|
|
|
{ name: 'Language', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
|
|
|
{ name: 'Playlist', align: 'left' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.createFile('./.readme/_languages.md', table)
|
2019-11-01 19:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function generateCategoriesTable() {
|
2019-11-01 20:15:22 +01:00
|
|
|
output.categories.sort((a, b) => {
|
2020-04-11 03:34:50 +02:00
|
|
|
if (a.category === 'Other') {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
if (b.category === 'Other') {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
if (a.category < b.category) {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
if (a.category > b.category) {
|
|
|
|
return 1
|
|
|
|
}
|
2019-11-01 19:13:15 +01:00
|
|
|
return 0
|
|
|
|
})
|
|
|
|
|
2019-11-02 10:45:09 +01:00
|
|
|
const table = helper.generateTable(output.categories, {
|
2019-11-01 17:34:05 +01:00
|
|
|
columns: [
|
|
|
|
{ name: 'Category', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
|
|
|
{ name: 'Playlist', align: 'left' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.createFile('./.readme/_categories.md', table)
|
2019-11-01 19:13:15 +01:00
|
|
|
}
|
2019-11-01 17:58:56 +01:00
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
function generateReadme() {
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.compileMarkdown('../.readme/config.json')
|
2019-11-01 17:34:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|