2019-07-20 09:03:31 +02:00
|
|
|
const util = require('./util')
|
2019-04-30 14:45:02 +02:00
|
|
|
const urlParser = require('url')
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-07-20 09:03:31 +02:00
|
|
|
const outputFile = 'index.full.m3u'
|
|
|
|
const debug = false
|
2019-04-23 20:49:09 +02:00
|
|
|
let cache = {}
|
2019-07-20 09:03:31 +02:00
|
|
|
let stats = {
|
|
|
|
total: 0,
|
|
|
|
duplicates: 0
|
|
|
|
}
|
2019-04-23 20:49:09 +02:00
|
|
|
|
|
|
|
function init() {
|
|
|
|
|
2019-07-20 09:03:31 +02:00
|
|
|
let countries = util.parsePlaylist('index.m3u')
|
|
|
|
|
|
|
|
if(debug) {
|
|
|
|
countries = countries.slice(0, 1)
|
|
|
|
}
|
|
|
|
|
2019-07-20 09:32:57 +02:00
|
|
|
util.createFile(outputFile, '#EXTM3U\n')
|
2019-04-23 20:49:09 +02:00
|
|
|
|
|
|
|
for(let country of countries) {
|
|
|
|
|
2019-07-20 09:03:31 +02:00
|
|
|
const countryName = util.getTitle(country.title)
|
|
|
|
const countryCode = util.getBasename(country.file).toUpperCase()
|
|
|
|
const playlist = util.parsePlaylist(country.file)
|
2019-04-23 20:49:09 +02:00
|
|
|
|
|
|
|
for(let item of playlist) {
|
|
|
|
|
2019-07-20 09:03:31 +02:00
|
|
|
const channel = util.parseChannelData(item)
|
|
|
|
const groupTitle = [ countryName, channel.group ].filter(i => i).join(';')
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-07-20 09:03:31 +02:00
|
|
|
const info = `-1 tvg-id="${channel.id}" tvg-name="${channel.name}" tvg-logo="${channel.logo}" group-title="${groupTitle}",${channel.title}`
|
|
|
|
const file = channel.file
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-07-20 09:03:31 +02:00
|
|
|
if(checkCache(file)) {
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-07-20 09:03:31 +02:00
|
|
|
stats.duplicates++
|
2019-04-23 20:49:09 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2019-07-20 09:32:57 +02:00
|
|
|
const data = '#EXTINF:' + info + '\n' + file + '\n'
|
|
|
|
|
|
|
|
util.writeToFile(outputFile, data)
|
2019-07-20 09:03:31 +02:00
|
|
|
|
|
|
|
addToCache(file)
|
2019-04-23 20:49:09 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-20 09:03:31 +02:00
|
|
|
stats.total++
|
2019-04-23 20:49:09 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
init()
|
|
|
|
|
2019-07-20 09:03:31 +02:00
|
|
|
console.log(`Total: ${stats.total}. Duplicates: ${stats.duplicates}. Unique: ${stats.total - stats.duplicates}`)
|
2019-04-23 20:49:09 +02:00
|
|
|
|
|
|
|
function addToCache(url) {
|
2019-04-30 14:45:02 +02:00
|
|
|
let id = getUrlPath(url)
|
2019-04-23 20:49:09 +02:00
|
|
|
|
|
|
|
cache[id] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkCache(url) {
|
2019-04-30 14:45:02 +02:00
|
|
|
let id = getUrlPath(url)
|
2019-04-23 20:49:09 +02:00
|
|
|
|
|
|
|
return cache.hasOwnProperty(id)
|
2019-04-30 14:45:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getUrlPath(u) {
|
|
|
|
let parsed = urlParser.parse(u)
|
|
|
|
let searchQuery = parsed.search || ''
|
|
|
|
|
|
|
|
return parsed.host + parsed.pathname + searchQuery
|
2019-04-23 20:49:09 +02:00
|
|
|
}
|