iptv/scripts/update-readme.js

167 lines
4.4 KiB
JavaScript
Raw Normal View History

2021-01-30 04:26:15 +01:00
const utils = require('./utils')
const parser = require('./parser')
2019-11-01 17:34:05 +01:00
2021-01-30 04:26:15 +01:00
const list = {
2019-11-01 20:11:09 +01:00
countries: [],
languages: [],
2020-05-06 17:02:07 +02:00
categories: []
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()
const countries = {}
const languages = {}
const categories = {}
countries['undefined'] = {
country: 'Undefined',
channels: 0,
playlist: `<code>https://iptv-org.github.io/iptv/countries/undefined.m3u</code>`,
epg: '',
name: 'Undefined'
}
2019-11-01 17:34:05 +01:00
2021-01-30 04:26:15 +01:00
languages['undefined'] = {
language: 'Undefined',
channels: 0,
playlist: `<code>https://iptv-org.github.io/iptv/languages/undefined.m3u</code>`
}
2021-01-27 16:33:14 +01:00
2021-01-30 04:26:15 +01:00
for (const category of utils.supportedCategories) {
categories[category.id] = {
category: category.name,
2021-01-27 16:33:14 +01:00
channels: 0,
2021-01-30 04:26:15 +01:00
playlist: `<code>https://iptv-org.github.io/iptv/categories/${category.id}.m3u</code>`
2021-01-27 16:33:14 +01:00
}
}
2021-01-30 04:26:15 +01:00
categories['other'] = {
category: 'Other',
channels: 0,
playlist: `<code>https://iptv-org.github.io/iptv/categories/other.m3u</code>`
}
2021-01-27 16:33:14 +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) {
// countries
2021-01-30 04:26:15 +01:00
if (!channel.countries.length) {
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) {
if (countries[country.code]) {
countries[country.code].channels++
} else {
let flag = utils.code2flag(country.code)
countries[country.code] = {
country: flag + '&nbsp;' + country.name,
channels: 1,
playlist: `<code>https://iptv-org.github.io/iptv/countries/${country.code}.m3u</code>`,
epg: playlist.header.attrs['x-tvg-url']
? `<code>${playlist.header.attrs['x-tvg-url']}</code>`
: '',
name: country.name
}
}
2019-11-02 11:50:40 +01:00
}
}
// languages
2021-01-30 04:26:15 +01:00
if (!channel.languages.length) {
languages['undefined'].channels++
} else {
for (let language of channel.languages) {
if (languages[language.code]) {
languages[language.code].channels++
} else {
languages[language.code] = {
language: language.name,
channels: 1,
playlist: `<code>https://iptv-org.github.io/iptv/languages/${language.code}.m3u</code>`
}
2020-04-22 16:27:42 +02:00
}
2019-11-01 20:11:09 +01:00
}
}
// categories
2021-01-30 04:26:15 +01:00
const categoryId = channel.category.toLowerCase()
if (!categoryId) {
categories['other'].channels++
} else if (categories[categoryId]) {
categories[categoryId].channels++
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-30 04:26:15 +01:00
list.countries = Object.values(countries)
list.languages = Object.values(languages)
list.categories = Object.values(categories)
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' },
{ name: 'Playlist', align: 'left', nowrap: true },
2020-05-06 17:02:07 +02:00
{ name: 'EPG', align: 'left' }
]
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 generateLanguagesTable() {
2021-01-30 04:26:15 +01:00
console.log(`Generating languages table...`)
list.languages = utils.sortBy(list.languages, ['language'])
const table = utils.generateTable(list.languages, {
2019-11-01 17:34:05 +01:00
columns: [
{ name: 'Language', align: 'left' },
{ name: 'Channels', align: 'right' },
2020-05-06 17:02:07 +02:00
{ name: 'Playlist', align: 'left' }
]
2019-11-01 17:34:05 +01:00
})
2021-01-30 04:26:15 +01:00
utils.createFile('./.readme/_languages.md', table)
2019-11-01 19:13:15 +01:00
}
function generateCategoriesTable() {
2021-01-30 04:26:15 +01:00
console.log(`Generating categories table...`)
list.categories = utils.sortBy(list.categories, ['category'])
const table = utils.generateTable(list.categories, {
2019-11-01 17:34:05 +01:00
columns: [
{ name: 'Category', align: 'left' },
{ name: 'Channels', align: 'right' },
2020-05-06 17:02:07 +02:00
{ name: 'Playlist', align: 'left' }
]
2019-11-01 17:34:05 +01:00
})
2021-01-30 04:26:15 +01:00
utils.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() {
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()