Update generate.js

This commit is contained in:
freearhey 2019-11-01 19:58:59 +03:00
parent c6d0ad66bb
commit 816f884d13

View File

@ -19,12 +19,6 @@ categories.forEach(category => {
categoryBuffer[category] = [] categoryBuffer[category] = []
}) })
let repo = {
categories: {},
countries: {},
languages: {}
}
function main() { function main() {
console.log(`Parsing 'index.m3u'...`) console.log(`Parsing 'index.m3u'...`)
const playlist = util.parsePlaylist('index.m3u') const playlist = util.parsePlaylist('index.m3u')
@ -45,7 +39,6 @@ function main() {
console.log(`Creating '${filename}'...`) console.log(`Creating '${filename}'...`)
util.createFile(filename, '#EXTM3U\n') util.createFile(filename, '#EXTM3U\n')
const categoryName = util.supportedCategories.find(c => c.toLowerCase() === category) || 'Other' const categoryName = util.supportedCategories.find(c => c.toLowerCase() === category) || 'Other'
repo.categories[category] = { category: categoryName, channels: 0, playlist: `<code>https://iptv-org.github.io/iptv/${filename}</code>` }
} }
for(let country of countries) { for(let country of countries) {
@ -57,9 +50,6 @@ function main() {
code: util.getBasename(country.url).toUpperCase() code: util.getBasename(country.url).toUpperCase()
} }
const epg = playlist.header.attrs['x-tvg-url'] ? `<code>${playlist.header.attrs['x-tvg-url']}</code>` : ''
repo.countries[c.code] = { country: c.name, channels: playlist.items.length, playlist: `<code>https://iptv-org.github.io/iptv/${country.url}</code>`, epg }
for(let item of playlist.items) { for(let item of playlist.items) {
let channel = util.createChannel(item) let channel = util.createChannel(item)
@ -103,14 +93,6 @@ function main() {
stats.countries++ stats.countries++
} }
for(const languageCode in languageBuffer) {
let languageName = ISO6391.getName(languageCode)
if(languageName) {
repo.languages[languageCode] = { language: languageName, channels: 0, playlist: `<code>https://iptv-org.github.io/iptv/languages/${languageCode}.m3u</code>` }
}
}
repo.languages['undefined'] = { language: 'Undefined', channels: 0, playlist: `<code>https://iptv-org.github.io/iptv/languages/undefined.m3u</code>` }
util.clearCache() util.clearCache()
for(const languageCode in languageBuffer) { for(const languageCode in languageBuffer) {
const filename = `languages/${languageCode}.m3u` const filename = `languages/${languageCode}.m3u`
@ -121,7 +103,6 @@ function main() {
if(!util.checkCache(channel.url)) { if(!util.checkCache(channel.url)) {
util.appendToFile(filename, channel.toString()) util.appendToFile(filename, channel.toString())
util.addToCache(channel.url) util.addToCache(channel.url)
repo.languages[languageCode].channels++
} }
} }
} }
@ -133,47 +114,9 @@ function main() {
if(!util.checkCache(channel.url)) { if(!util.checkCache(channel.url)) {
util.appendToFile(`categories/${category}.m3u`, channel.toString()) util.appendToFile(`categories/${category}.m3u`, channel.toString())
util.addToCache(channel.url) util.addToCache(channel.url)
repo.categories[category].channels++
} }
} }
} }
const languages = Object.values(repo.languages)
const lastRow = languages.splice(languages.length - 1, 1)[0]
languages.sort((a, b) => {
if(a.language < b.language) { return -1 }
if(a.language > b.language) { return 1 }
return 0
})
languages.push(lastRow)
const languagesTable = util.generateTable(languages, {
columns: [
{ name: 'Language', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left' }
]
})
util.createFile('./helpers/languages.md', languagesTable)
const categoriesTable = util.generateTable(Object.values(repo.categories), {
columns: [
{ name: 'Category', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left' }
]
})
util.createFile('./helpers/categories.md', categoriesTable)
const countriesTable = util.generateTable(Object.values(repo.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', countriesTable)
} }
main() main()