2019-07-20 09:03:31 +02:00
|
|
|
const util = require('./util')
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-07-20 09:03:31 +02:00
|
|
|
const debug = false
|
2019-09-14 02:07:54 +02:00
|
|
|
const types = ['full', 'country', 'content']
|
|
|
|
const categories = util.supportedCategories.map(c => c.toLowerCase())
|
2019-07-20 09:03:31 +02:00
|
|
|
let stats = {
|
2019-08-07 16:28:35 +02:00
|
|
|
countries: 0,
|
2019-08-08 11:52:29 +02:00
|
|
|
channels: 0
|
2019-07-20 09:03:31 +02:00
|
|
|
}
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-09-14 02:07:54 +02:00
|
|
|
let buffer = {}
|
|
|
|
categories.push('other')
|
|
|
|
categories.forEach(category => {
|
|
|
|
buffer[category] = []
|
|
|
|
})
|
|
|
|
|
2019-10-09 04:33:52 +02:00
|
|
|
let repo = {
|
|
|
|
categories: {},
|
|
|
|
countries: {}
|
|
|
|
}
|
|
|
|
|
2019-08-07 16:28:35 +02:00
|
|
|
function main() {
|
|
|
|
console.log(`Parsing 'index.m3u'...`)
|
|
|
|
const playlist = util.parsePlaylist('index.m3u')
|
|
|
|
let countries = playlist.items
|
2019-07-20 09:03:31 +02:00
|
|
|
if(debug) {
|
2019-08-07 16:28:35 +02:00
|
|
|
console.log('Debug mode is turn on')
|
2019-07-20 09:03:31 +02:00
|
|
|
countries = countries.slice(0, 1)
|
|
|
|
}
|
|
|
|
|
2019-08-07 16:28:35 +02:00
|
|
|
for(let type of types) {
|
|
|
|
const filename = `index.${type}.m3u`
|
|
|
|
console.log(`Creating '${filename}'...`)
|
|
|
|
util.createFile(filename, '#EXTM3U\n')
|
2019-07-20 14:27:40 +02:00
|
|
|
}
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-09-14 02:07:54 +02:00
|
|
|
for(let category of categories) {
|
|
|
|
const filename = `categories/${category}.m3u`
|
|
|
|
console.log(`Creating '${filename}'...`)
|
|
|
|
util.createFile(filename, '#EXTM3U\n')
|
2019-10-09 04:33:52 +02:00
|
|
|
const categoryName = util.supportedCategories.find(c => c.toLowerCase() === category) || 'Other'
|
|
|
|
repo.categories[category] = { category: categoryName, channels: 0, playlist: `\`https://iptv-org.github.io/iptv/${filename}\`` }
|
2019-09-14 02:07:54 +02:00
|
|
|
}
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-09-14 02:07:54 +02:00
|
|
|
for(let country of countries) {
|
2019-08-07 16:28:35 +02:00
|
|
|
console.log(`Parsing '${country.url}'...`)
|
|
|
|
const playlist = util.parsePlaylist(country.url)
|
2019-07-20 14:27:40 +02:00
|
|
|
|
2019-08-07 16:28:35 +02:00
|
|
|
const c = {
|
2019-10-07 01:45:06 +02:00
|
|
|
name: country.name,
|
2019-08-07 16:28:35 +02:00
|
|
|
code: util.getBasename(country.url).toUpperCase()
|
|
|
|
}
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-10-09 04:33:52 +02:00
|
|
|
const epg = playlist.header.attrs['x-tvg-url'] ? `\`${playlist.header.attrs['x-tvg-url']}\`` : ''
|
|
|
|
repo.countries[c.code] = { country: c.name, channels: playlist.items.length, playlist: `\`https://iptv-org.github.io/iptv/${country.url}\``, epg }
|
|
|
|
|
2019-08-07 16:28:35 +02:00
|
|
|
for(let item of playlist.items) {
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-10-07 01:45:06 +02:00
|
|
|
let channel = util.createChannel(item)
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-09-14 02:07:54 +02:00
|
|
|
let group = channel.group
|
2019-08-08 11:52:29 +02:00
|
|
|
|
|
|
|
for(const type of types) {
|
|
|
|
if(type === 'full') {
|
|
|
|
channel.group = [ c.name, channel.group ].filter(i => i).join(';')
|
|
|
|
} else if(type === 'country') {
|
|
|
|
channel.group = c.name
|
|
|
|
} else {
|
2019-09-14 02:07:54 +02:00
|
|
|
channel.group = group
|
2019-08-08 11:52:29 +02:00
|
|
|
}
|
2019-07-20 14:27:40 +02:00
|
|
|
|
2019-09-14 02:07:54 +02:00
|
|
|
util.appendToFile(`index.${type}.m3u`, channel.toString())
|
|
|
|
}
|
|
|
|
|
|
|
|
let category = channel.group.toLowerCase()
|
|
|
|
if(buffer[category]) {
|
|
|
|
buffer[category].push(channel)
|
|
|
|
} else {
|
|
|
|
buffer['other'].push(channel)
|
2019-04-23 20:49:09 +02:00
|
|
|
}
|
|
|
|
|
2019-08-07 16:28:35 +02:00
|
|
|
stats.channels++
|
2019-04-23 20:49:09 +02:00
|
|
|
}
|
|
|
|
|
2019-08-07 16:28:35 +02:00
|
|
|
stats.countries++
|
2019-04-23 20:49:09 +02:00
|
|
|
}
|
2019-09-14 02:07:54 +02:00
|
|
|
|
|
|
|
for(const category in buffer) {
|
|
|
|
let channels = util.sortByTitleAndUrl(buffer[category])
|
|
|
|
for(const channel of channels) {
|
|
|
|
if(!util.checkCache(channel.url)) {
|
|
|
|
util.appendToFile(`categories/${category}.m3u`, channel.toString())
|
|
|
|
util.addToCache(channel.url)
|
2019-10-09 04:33:52 +02:00
|
|
|
repo.categories[category].channels++
|
2019-09-14 02:07:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-09 04:33:52 +02:00
|
|
|
|
|
|
|
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' },
|
|
|
|
{ name: 'EPG', align: 'left' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
util.createFile('./helpers/countries.md', countriesTable)
|
2019-04-23 20:49:09 +02:00
|
|
|
}
|
|
|
|
|
2019-08-07 16:28:35 +02:00
|
|
|
main()
|
2019-04-30 14:45:02 +02:00
|
|
|
|
2019-08-08 11:52:29 +02:00
|
|
|
console.log(`Countries: ${stats.countries}. Channels: ${stats.channels}.`)
|