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