2021-01-30 04:26:15 +01:00
|
|
|
const utils = require('./utils')
|
|
|
|
const parser = require('./parser')
|
2021-01-31 18:19:01 +01:00
|
|
|
const categories = require('./categories')
|
2021-02-11 05:16:44 +01:00
|
|
|
const db = require('./db')
|
|
|
|
|
|
|
|
db.load()
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2021-01-30 04:26:15 +01:00
|
|
|
const list = {
|
2021-02-11 05:28:35 +01:00
|
|
|
countries: {}
|
2019-11-01 20:11:09 +01:00
|
|
|
}
|
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
function main() {
|
2019-11-01 20:11:09 +01:00
|
|
|
parseIndex()
|
2019-11-01 19:13:15 +01:00
|
|
|
generateCountriesTable()
|
|
|
|
generateLanguagesTable()
|
|
|
|
generateCategoriesTable()
|
|
|
|
generateReadme()
|
2021-01-30 04:26:15 +01:00
|
|
|
finish()
|
2019-11-01 17:34:05 +01:00
|
|
|
}
|
|
|
|
|
2019-11-01 20:11:09 +01:00
|
|
|
function parseIndex() {
|
2021-01-30 04:26:15 +01:00
|
|
|
console.log(`Parsing index...`)
|
|
|
|
const items = parser.parseIndex()
|
|
|
|
|
2021-01-31 18:19:01 +01:00
|
|
|
list.countries['undefined'] = {
|
2021-01-30 04:26:15 +01:00
|
|
|
country: 'Undefined',
|
|
|
|
channels: 0,
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/countries/undefined.m3u</code>`,
|
|
|
|
name: 'Undefined'
|
|
|
|
}
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2021-01-30 04:26:15 +01:00
|
|
|
for (const item of items) {
|
|
|
|
const playlist = parser.parsePlaylist(item.url)
|
|
|
|
for (let channel of playlist.channels) {
|
2019-11-04 10:46:57 +01:00
|
|
|
// countries
|
2021-01-30 04:26:15 +01:00
|
|
|
if (!channel.countries.length) {
|
2021-01-31 18:19:01 +01:00
|
|
|
list.countries['undefined'].channels++
|
2019-11-02 11:50:40 +01:00
|
|
|
} else {
|
2021-01-30 04:26:15 +01:00
|
|
|
for (let country of channel.countries) {
|
2021-01-31 18:19:01 +01:00
|
|
|
if (list.countries[country.code]) {
|
|
|
|
list.countries[country.code].channels++
|
2021-01-30 04:26:15 +01:00
|
|
|
} else {
|
|
|
|
let flag = utils.code2flag(country.code)
|
2021-01-31 18:19:01 +01:00
|
|
|
list.countries[country.code] = {
|
2021-01-30 04:26:15 +01:00
|
|
|
country: flag + ' ' + country.name,
|
|
|
|
channels: 1,
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/countries/${country.code}.m3u</code>`,
|
|
|
|
name: country.name
|
|
|
|
}
|
|
|
|
}
|
2019-11-02 11:50:40 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-01 20:11:09 +01:00
|
|
|
}
|
2019-11-01 19:13:15 +01:00
|
|
|
}
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2021-01-31 18:19:01 +01:00
|
|
|
list.countries = Object.values(list.countries)
|
2021-02-11 05:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function generateCategoriesTable() {
|
|
|
|
console.log(`Generating categories table...`)
|
|
|
|
const categories = []
|
|
|
|
|
|
|
|
for (const category of db.categories.all()) {
|
|
|
|
categories.push({
|
|
|
|
category: category.name,
|
|
|
|
channels: db.channels.forCategory(category).count(),
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/categories/${category.id}.m3u</code>`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
categories.push({
|
|
|
|
category: 'Other',
|
|
|
|
channels: db.channels.forCategory({ id: null }).count(),
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/categories/other.m3u</code>`
|
|
|
|
})
|
|
|
|
|
|
|
|
const table = utils.generateTable(categories, {
|
|
|
|
columns: [
|
|
|
|
{ name: 'Category', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
|
|
|
{ name: 'Playlist', align: 'left' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
utils.createFile('./.readme/_categories.md', table)
|
2019-11-01 20:11:09 +01:00
|
|
|
}
|
|
|
|
|
2021-02-11 05:28:35 +01:00
|
|
|
function generateLanguagesTable() {
|
|
|
|
console.log(`Generating languages table...`)
|
|
|
|
const languages = []
|
|
|
|
|
|
|
|
for (const language of db.languages.sortBy(['name']).all()) {
|
|
|
|
languages.push({
|
|
|
|
language: language.name,
|
|
|
|
channels: db.channels.forLanguage(language).count(),
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/languages/${language.code}.m3u</code>`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
languages.push({
|
|
|
|
language: 'Undefined',
|
|
|
|
channels: db.channels.forLanguage({ code: null }).count(),
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/languages/undefined.m3u</code>`
|
|
|
|
})
|
|
|
|
|
|
|
|
const table = utils.generateTable(languages, {
|
|
|
|
columns: [
|
|
|
|
{ name: 'Language', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
|
|
|
{ name: 'Playlist', align: 'left' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
utils.createFile('./.readme/_languages.md', table)
|
|
|
|
}
|
|
|
|
|
2019-11-01 20:11:09 +01:00
|
|
|
function generateCountriesTable() {
|
2021-01-30 04:26:15 +01:00
|
|
|
console.log(`Generating countries table...`)
|
|
|
|
list.countries = utils.sortBy(list.countries, ['name'])
|
|
|
|
list.countries.forEach(function (i) {
|
|
|
|
delete i.name
|
|
|
|
})
|
|
|
|
const table = utils.generateTable(list.countries, {
|
2019-11-01 19:13:15 +01:00
|
|
|
columns: [
|
|
|
|
{ name: 'Country', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
2021-02-08 10:08:16 +01:00
|
|
|
{ name: 'Playlist', align: 'left', nowrap: true }
|
2020-05-06 17:02:07 +02:00
|
|
|
]
|
2019-11-01 19:13:15 +01:00
|
|
|
})
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2021-01-30 04:26:15 +01:00
|
|
|
utils.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 generateReadme() {
|
2021-01-30 04:26:15 +01:00
|
|
|
console.log(`Generating README.md...`)
|
|
|
|
utils.compileMarkdown('../.readme/config.json')
|
|
|
|
}
|
|
|
|
|
|
|
|
function finish() {
|
|
|
|
console.log(`Done.`)
|
2019-11-01 17:34:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|