iptv/helpers/generate.js

92 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-07-20 09:03:31 +02:00
const util = require('./util')
2019-07-20 09:03:31 +02:00
const debug = false
2019-08-07 16:28:35 +02:00
const types = ['full', 'country', 'content', 'sport']
2019-07-20 09:03:31 +02:00
let stats = {
2019-08-07 16:28:35 +02:00
countries: 0,
channels: 0,
2019-07-20 09:03:31 +02:00
duplicates: 0
}
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
}
for(let country of countries) {
2019-08-08 01:50:53 +02:00
if(debug) {
console.log(`Clear cache...`)
}
util.clearCache()
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 = {
name: country.inf.title,
code: util.getBasename(country.url).toUpperCase()
}
2019-08-07 16:28:35 +02:00
for(let item of playlist.items) {
2019-08-07 16:28:35 +02:00
let channel = util.createChannel({
id: item.inf['tvg-id'],
name: item.inf['tvg-name'],
logo: item.inf['tvg-logo'],
group: item.inf['group-title'],
url: item.url,
title: item.inf.title
})
2019-08-07 16:28:35 +02:00
if(util.checkCache(channel.url)) {
2019-07-20 09:03:31 +02:00
stats.duplicates++
2019-08-07 16:28:35 +02:00
} else {
2019-08-07 16:28:35 +02:00
let category = channel.group
2019-07-20 14:27:40 +02:00
for(const type of types) {
if(type === 'full') {
2019-08-07 16:28:35 +02:00
channel.group = [ c.name, channel.group ].filter(i => i).join(';')
2019-07-20 14:27:40 +02:00
} else if(type === 'country') {
2019-08-07 16:28:35 +02:00
channel.group = c.name
2019-07-24 11:12:15 +02:00
} else {
2019-08-07 16:28:35 +02:00
channel.group = category
2019-07-20 14:27:40 +02:00
}
2019-08-07 16:28:35 +02:00
const filename = `index.${type}.m3u`
2019-07-24 11:12:15 +02:00
if(type === 'sport') {
2019-08-07 16:28:35 +02:00
if(channel.group === 'Sport') {
util.appendToFile(filename, channel.toString())
2019-07-24 11:12:15 +02:00
}
} else {
2019-08-07 16:28:35 +02:00
util.appendToFile(filename, channel.toString())
2019-07-24 11:12:15 +02:00
}
2019-07-20 14:27:40 +02:00
}
2019-07-20 09:03:31 +02:00
2019-08-07 16:28:35 +02:00
util.addToCache(channel.url)
}
2019-08-07 16:28:35 +02:00
stats.channels++
}
2019-08-07 16:28:35 +02:00
stats.countries++
}
}
2019-08-07 16:28:35 +02:00
main()
2019-04-30 14:45:02 +02:00
2019-08-07 16:28:35 +02:00
console.log(`Countries: ${stats.countries}. Channels: ${stats.channels}. Unique: ${stats.channels - stats.duplicates}. Duplicates: ${stats.duplicates}.`)