2019-11-01 17:34:05 +01:00
|
|
|
const util = require('./util')
|
|
|
|
const ISO6391 = require('iso-639-1')
|
2019-11-01 17:58:56 +01:00
|
|
|
const markdownInclude = require('markdown-include')
|
|
|
|
const path = require('path')
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
function main() {
|
|
|
|
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 19:13:15 +01:00
|
|
|
function generateCountriesTable() {
|
|
|
|
const root = util.parsePlaylist('index.m3u')
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
let countries = []
|
|
|
|
for(let item of root.items) {
|
|
|
|
const playlist = util.parsePlaylist(item.url)
|
|
|
|
const countryCode = util.getBasename(item.url).toUpperCase()
|
|
|
|
const epg = playlist.header.attrs['x-tvg-url'] ? `<code>${playlist.header.attrs['x-tvg-url']}</code>` : ''
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
countries.push({
|
|
|
|
country: item.name,
|
2019-11-01 17:58:56 +01:00
|
|
|
channels: playlist.items.length,
|
2019-11-01 19:13:15 +01:00
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/${item.url}</code>`,
|
|
|
|
epg
|
|
|
|
})
|
|
|
|
}
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
const table = util.generateTable(countries, {
|
|
|
|
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-01 19:13:15 +01:00
|
|
|
util.createFile('./helpers/countries.md', table)
|
|
|
|
}
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
function generateLanguagesTable() {
|
|
|
|
const playlist = util.parsePlaylist('index.language.m3u')
|
|
|
|
|
|
|
|
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] = {
|
2019-11-01 17:58:56 +01:00
|
|
|
language: languageName,
|
2019-11-01 19:13:15 +01:00
|
|
|
channels: 1,
|
2019-11-01 17:58:56 +01:00
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/languages/${languageCode}.m3u</code>`
|
|
|
|
}
|
2019-11-01 17:34:05 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-01 17:58:56 +01:00
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
languages = Object.values(languages)
|
2019-11-01 17:34:05 +01:00
|
|
|
languages.sort((a, b) => {
|
2019-11-01 19:13:15 +01:00
|
|
|
if(a.language === 'Undefined') { return 1 }
|
|
|
|
if(b.language === 'Undefined') { return -1 }
|
2019-11-01 17:34:05 +01:00
|
|
|
if(a.language < b.language) { return -1 }
|
|
|
|
if(a.language > b.language) { return 1 }
|
|
|
|
return 0
|
|
|
|
})
|
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
const table = util.generateTable(languages, {
|
2019-11-01 17:34:05 +01:00
|
|
|
columns: [
|
|
|
|
{ name: 'Language', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
|
|
|
{ name: 'Playlist', align: 'left' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
util.createFile('./helpers/languages.md', table)
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateCategoriesTable() {
|
|
|
|
const playlist = util.parsePlaylist('index.content.m3u')
|
|
|
|
|
|
|
|
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(b.category === 'Other') { return -1 }
|
|
|
|
if(a.category < b.category) { return -1 }
|
|
|
|
if(a.category > b.category) { return 1 }
|
|
|
|
return 0
|
|
|
|
})
|
|
|
|
|
|
|
|
const table = util.generateTable(categories, {
|
2019-11-01 17:34:05 +01:00
|
|
|
columns: [
|
|
|
|
{ name: 'Category', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
|
|
|
{ name: 'Playlist', align: 'left' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
util.createFile('./helpers/categories.md', table)
|
|
|
|
}
|
2019-11-01 17:58:56 +01:00
|
|
|
|
2019-11-01 19:13:15 +01:00
|
|
|
function generateReadme() {
|
2019-11-01 17:58:56 +01:00
|
|
|
markdownInclude.compileFiles(path.resolve(__dirname, './markdown.json'))
|
2019-11-01 17:34:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|