Update update-readme.js

This commit is contained in:
freearhey 2019-11-01 22:11:09 +03:00
parent bc7a80fbc1
commit e07540757d
1 changed files with 55 additions and 49 deletions

View File

@ -3,7 +3,15 @@ const ISO6391 = require('iso-639-1')
const markdownInclude = require('markdown-include')
const path = require('path')
let data = {
countries: [],
languages: [],
categories: []
}
function main() {
console.log(`Parsing index...`)
parseIndex()
console.log(`Generating countries table...`)
generateCountriesTable()
console.log(`Generating languages table...`)
@ -15,40 +23,25 @@ function main() {
console.log(`Done.`)
}
function generateCountriesTable() {
function parseIndex() {
const root = util.parsePlaylist('index.m3u')
let countries = []
for(let item of root.items) {
const playlist = util.parsePlaylist(item.url)
const countryCode = util.getBasename(item.url).toUpperCase()
let languages = {}
let categories = {}
for(let rootItem of root.items) {
const playlist = util.parsePlaylist(rootItem.url)
const countryCode = util.getBasename(rootItem.url).toUpperCase()
const epg = playlist.header.attrs['x-tvg-url'] ? `<code>${playlist.header.attrs['x-tvg-url']}</code>` : ''
countries.push({
country: item.name,
data.countries.push({
country: rootItem.name,
channels: playlist.items.length,
playlist: `<code>https://iptv-org.github.io/iptv/${item.url}</code>`,
playlist: `<code>https://iptv-org.github.io/iptv/${rootItem.url}</code>`,
epg
})
}
const table = util.generateTable(countries, {
columns: [
{ name: 'Country', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left', nowrap: true },
{ name: 'EPG', align: 'left' }
]
})
util.createFile('./helpers/countries.md', table)
}
function generateLanguagesTable() {
const playlist = util.parsePlaylist('index.language.m3u')
let languages = {}
for(let item of playlist.items) {
// language
const languageName = item.group.title || 'Undefined'
const languageCode = ISO6391.getCode(languageName) || 'undefined'
if(languages[languageCode]) {
@ -60,33 +53,8 @@ function generateLanguagesTable() {
playlist: `<code>https://iptv-org.github.io/iptv/languages/${languageCode}.m3u</code>`
}
}
}
languages = Object.values(languages)
languages.sort((a, b) => {
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 }
return 0
})
const table = util.generateTable(languages, {
columns: [
{ name: 'Language', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left' }
]
})
util.createFile('./helpers/languages.md', table)
}
function generateCategoriesTable() {
const playlist = util.parsePlaylist('index.content.m3u')
let categories = {}
for(let item of playlist.items) {
// category
const categoryName = util.supportedCategories.find(c => c === item.group.title) || 'Other'
const categoryCode = categoryName.toLowerCase()
if(categories[categoryCode]) {
@ -99,9 +67,47 @@ function generateCategoriesTable() {
}
}
}
}
categories = Object.values(categories)
categories.sort((a, b) => {
data.languages = Object.values(languages)
data.categories = Object.values(categories)
}
function generateCountriesTable() {
const table = util.generateTable(data.countries, {
columns: [
{ name: 'Country', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left', nowrap: true },
{ name: 'EPG', align: 'left' }
]
})
util.createFile('./helpers/countries.md', table)
}
function generateLanguagesTable() {
data.languages.sort((a, b) => {
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 }
return 0
})
const table = util.generateTable(data.languages, {
columns: [
{ name: 'Language', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left' }
]
})
util.createFile('./helpers/languages.md', table)
}
function generateCategoriesTable() {
data.categories.sort((a, b) => {
if(a.category === 'Other') { return 1 }
if(b.category === 'Other') { return -1 }
if(a.category < b.category) { return -1 }
@ -109,7 +115,7 @@ function generateCategoriesTable() {
return 0
})
const table = util.generateTable(categories, {
const table = util.generateTable(data.categories, {
columns: [
{ name: 'Category', align: 'left' },
{ name: 'Channels', align: 'right' },