Added playlist generation for different languages

This commit is contained in:
freearhey 2019-10-31 14:58:34 +03:00
parent c78cf7f453
commit 399c5abc93
1 changed files with 62 additions and 10 deletions

View File

@ -1,22 +1,28 @@
const util = require('./util') const util = require('./util')
const ISO6391 = require('iso-639-1')
const debug = false const debug = false
const types = ['full', 'country', 'content'] const types = ['full', 'country', 'content', 'language']
const categories = util.supportedCategories.map(c => c.toLowerCase()) const categories = util.supportedCategories.map(c => c.toLowerCase())
let stats = { let stats = {
countries: 0, countries: 0,
channels: 0 channels: 0
} }
let buffer = {} let languageBuffer = {
undefined: []
}
let categoryBuffer = {}
categories.push('other') categories.push('other')
categories.forEach(category => { categories.forEach(category => {
buffer[category] = [] categoryBuffer[category] = []
}) })
let repo = { let repo = {
categories: {}, categories: {},
countries: {} countries: {},
languages: {}
} }
function main() { function main() {
@ -59,12 +65,13 @@ function main() {
let channel = util.createChannel(item) let channel = util.createChannel(item)
let group = channel.group let group = channel.group
for(const type of types) { for(const type of types) {
if(type === 'full') { if(type === 'full') {
channel.group = [ c.name, channel.group ].filter(i => i).join(';') channel.group = [ c.name, channel.group ].filter(i => i).join(';')
} else if(type === 'country') { } else if(type === 'country') {
channel.group = c.name channel.group = c.name
} else if(type === 'language') {
channel.group = channel.language
} else { } else {
channel.group = group channel.group = group
} }
@ -73,10 +80,21 @@ function main() {
} }
let category = channel.group.toLowerCase() let category = channel.group.toLowerCase()
if(buffer[category]) { if(categoryBuffer[category]) {
buffer[category].push(channel) categoryBuffer[category].push(channel)
} else { } else {
buffer['other'].push(channel) categoryBuffer['other'].push(channel)
}
let languageCode = ISO6391.getCode(channel.language)
if(languageCode) {
if(!languageBuffer[languageCode]) {
languageBuffer[languageCode] = []
}
languageBuffer[languageCode].push(channel)
} else {
languageBuffer['undefined'].push(channel)
} }
stats.channels++ stats.channels++
@ -85,8 +103,32 @@ function main() {
stats.countries++ stats.countries++
} }
for(const category in buffer) { for(const languageCode in languageBuffer) {
let channels = util.sortByTitleAndUrl(buffer[category]) 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()
for(const languageCode in languageBuffer) {
const filename = `languages/${languageCode}.m3u`
util.createFile(filename, '#EXTM3U\n')
let channels = util.sortByTitleAndUrl(languageBuffer[languageCode])
for(const channel of channels) {
if(!util.checkCache(channel.url)) {
util.appendToFile(filename, channel.toString())
util.addToCache(channel.url)
repo.languages[languageCode].channels++
}
}
}
util.clearCache()
for(const category in categoryBuffer) {
let channels = util.sortByTitleAndUrl(categoryBuffer[category])
for(const channel of channels) { for(const channel of channels) {
if(!util.checkCache(channel.url)) { if(!util.checkCache(channel.url)) {
util.appendToFile(`categories/${category}.m3u`, channel.toString()) util.appendToFile(`categories/${category}.m3u`, channel.toString())
@ -96,6 +138,15 @@ function main() {
} }
} }
const languagesTable = util.generateTable(Object.values(repo.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), { const categoriesTable = util.generateTable(Object.values(repo.categories), {
columns: [ columns: [
{ name: 'Category', align: 'left' }, { name: 'Category', align: 'left' },
@ -104,6 +155,7 @@ function main() {
] ]
}) })
util.createFile('./helpers/categories.md', categoriesTable) util.createFile('./helpers/categories.md', categoriesTable)
const countriesTable = util.generateTable(Object.values(repo.countries), { const countriesTable = util.generateTable(Object.values(repo.countries), {
columns: [ columns: [
{ name: 'Country', align: 'left' }, { name: 'Country', align: 'left' },