2019-11-02 10:45:09 +01:00
|
|
|
const helper = require('./helper')
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-11-02 11:26:21 +01:00
|
|
|
const ROOT_DIR = './.gh-pages'
|
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
let list = {
|
|
|
|
all: [],
|
|
|
|
countries: {},
|
|
|
|
languages: {},
|
|
|
|
categories: {}
|
2019-07-20 09:03:31 +02:00
|
|
|
}
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-11-01 22:27:05 +01:00
|
|
|
function main() {
|
|
|
|
console.log(`Parsing index...`)
|
|
|
|
parseIndex()
|
2019-11-03 18:25:33 +01:00
|
|
|
console.log('Creating root directory...')
|
|
|
|
createRootDirectory()
|
2019-11-13 15:27:59 +01:00
|
|
|
console.log('Creating .nojekyll...')
|
|
|
|
createNoJekyllFile()
|
2019-11-02 11:50:56 +01:00
|
|
|
console.log('Generating index.m3u...')
|
|
|
|
generateIndex()
|
2019-11-01 22:27:05 +01:00
|
|
|
console.log('Generating index.country.m3u...')
|
|
|
|
generateCountryIndex()
|
|
|
|
console.log('Generating index.language.m3u...')
|
|
|
|
generateLanguageIndex()
|
2019-11-02 13:11:33 +01:00
|
|
|
console.log('Generating index.category.m3u...')
|
|
|
|
generateCategoryIndex()
|
2019-11-02 11:50:56 +01:00
|
|
|
console.log('Generating /countries...')
|
|
|
|
generateCountries()
|
2019-11-01 22:27:05 +01:00
|
|
|
console.log('Generating /categories...')
|
|
|
|
generateCategories()
|
|
|
|
console.log('Generating /languages...')
|
|
|
|
generateLanguages()
|
|
|
|
console.log('Done.\n')
|
|
|
|
|
2020-04-11 03:34:50 +02:00
|
|
|
console.log(
|
|
|
|
`Countries: ${Object.values(list.countries).length}. Languages: ${
|
|
|
|
Object.values(list.languages).length
|
|
|
|
}. Categories: ${Object.values(list.categories).length}. Channels: ${list.all.length}.`
|
|
|
|
)
|
2019-11-01 22:27:05 +01:00
|
|
|
}
|
|
|
|
|
2019-11-03 18:25:33 +01:00
|
|
|
function createRootDirectory() {
|
2019-11-02 11:26:21 +01:00
|
|
|
helper.createDir(ROOT_DIR)
|
|
|
|
}
|
|
|
|
|
2019-11-13 15:27:59 +01:00
|
|
|
function createNoJekyllFile() {
|
|
|
|
helper.createFile(`${ROOT_DIR}/.nojekyll`)
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
function parseIndex() {
|
2019-11-02 10:45:09 +01:00
|
|
|
const root = helper.parsePlaylist('index.m3u')
|
2019-10-31 12:58:34 +01:00
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
let countries = {}
|
|
|
|
let languages = {}
|
|
|
|
let categories = {}
|
2019-09-14 02:07:54 +02:00
|
|
|
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let rootItem of root.items) {
|
2019-11-02 10:45:09 +01:00
|
|
|
const playlist = helper.parsePlaylist(rootItem.url)
|
|
|
|
const countryCode = helper.getBasename(rootItem.url).toLowerCase()
|
2019-11-01 22:08:27 +01:00
|
|
|
const countryName = rootItem.name
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let item of playlist.items) {
|
2019-11-02 10:45:09 +01:00
|
|
|
const channel = helper.createChannel(item)
|
2019-11-01 22:08:27 +01:00
|
|
|
channel.countryCode = countryCode
|
|
|
|
channel.countryName = countryName
|
2019-11-02 15:30:12 +01:00
|
|
|
channel.epg = playlist.header.attrs['x-tvg-url'] || ''
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
// all
|
|
|
|
list.all.push(channel)
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
// country
|
2020-04-11 03:34:50 +02:00
|
|
|
if (!countries[countryCode]) {
|
2019-11-01 22:08:27 +01:00
|
|
|
countries[countryCode] = []
|
2019-10-31 12:58:34 +01:00
|
|
|
}
|
2019-11-01 22:08:27 +01:00
|
|
|
countries[countryCode].push(channel)
|
2019-10-31 12:58:34 +01:00
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
// language
|
2020-04-12 17:33:06 +02:00
|
|
|
for (let language of channel.language.split(';')) {
|
|
|
|
const languageCode = helper.getISO6391Code(language) || 'undefined'
|
|
|
|
if (!languages[languageCode]) {
|
|
|
|
languages[languageCode] = []
|
|
|
|
}
|
|
|
|
languages[languageCode].push(channel)
|
2019-04-23 20:49:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
// category
|
|
|
|
const categoryCode = channel.group.toLowerCase() || 'other'
|
2020-04-11 03:34:50 +02:00
|
|
|
if (!categories[categoryCode]) {
|
2019-11-01 22:08:27 +01:00
|
|
|
categories[categoryCode] = []
|
2019-10-31 13:21:08 +01:00
|
|
|
}
|
2019-11-01 22:08:27 +01:00
|
|
|
categories[categoryCode].push(channel)
|
2019-04-23 20:49:09 +02:00
|
|
|
}
|
2019-11-01 22:08:27 +01:00
|
|
|
}
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
list.countries = countries
|
|
|
|
list.languages = languages
|
|
|
|
list.categories = categories
|
|
|
|
}
|
|
|
|
|
2019-11-02 11:50:56 +01:00
|
|
|
function generateIndex() {
|
|
|
|
const filename = `${ROOT_DIR}/index.m3u`
|
|
|
|
helper.createFile(filename, '#EXTM3U\n')
|
|
|
|
|
2019-11-02 13:43:41 +01:00
|
|
|
const channels = helper.sortBy(list.all, ['title', 'url'])
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let channel of channels) {
|
2019-11-02 11:50:56 +01:00
|
|
|
helper.appendToFile(filename, channel.toString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
function generateCountryIndex() {
|
2019-11-02 11:26:21 +01:00
|
|
|
const filename = `${ROOT_DIR}/index.country.m3u`
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.createFile(filename, '#EXTM3U\n')
|
2019-11-01 22:08:27 +01:00
|
|
|
|
2019-11-02 13:43:41 +01:00
|
|
|
const channels = helper.sortBy(list.all, ['countryName', 'title', 'url'])
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let channel of channels) {
|
2019-11-01 22:08:27 +01:00
|
|
|
const group = channel.group
|
|
|
|
channel.group = channel.countryName
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.appendToFile(filename, channel.toString())
|
2019-11-01 22:08:27 +01:00
|
|
|
channel.group = group
|
2019-04-23 20:49:09 +02:00
|
|
|
}
|
2019-11-01 22:08:27 +01:00
|
|
|
}
|
2019-09-14 02:07:54 +02:00
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
function generateLanguageIndex() {
|
2019-11-02 11:26:21 +01:00
|
|
|
const filename = `${ROOT_DIR}/index.language.m3u`
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.createFile(filename, '#EXTM3U\n')
|
2019-11-01 22:08:27 +01:00
|
|
|
|
2019-11-02 13:43:41 +01:00
|
|
|
const channels = helper.sortBy(list.all, ['language', 'title', 'url'])
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let channel of channels) {
|
2019-11-01 22:08:27 +01:00
|
|
|
const group = channel.group
|
|
|
|
channel.group = channel.language
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.appendToFile(filename, channel.toString())
|
2019-11-01 22:08:27 +01:00
|
|
|
channel.group = group
|
2019-10-31 12:58:34 +01:00
|
|
|
}
|
2019-11-01 22:08:27 +01:00
|
|
|
}
|
2019-10-31 12:58:34 +01:00
|
|
|
|
2019-11-02 13:11:33 +01:00
|
|
|
function generateCategoryIndex() {
|
|
|
|
const filename = `${ROOT_DIR}/index.category.m3u`
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.createFile(filename, '#EXTM3U\n')
|
2019-11-01 22:08:27 +01:00
|
|
|
|
2019-11-02 13:43:41 +01:00
|
|
|
const channels = helper.sortBy(list.all, ['group', 'title', 'url'])
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let channel of channels) {
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.appendToFile(filename, channel.toString())
|
2019-09-14 02:07:54 +02:00
|
|
|
}
|
2019-04-23 20:49:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-02 11:50:56 +01:00
|
|
|
function generateCountries() {
|
|
|
|
const outputDir = `${ROOT_DIR}/countries`
|
|
|
|
helper.createDir(outputDir)
|
|
|
|
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let cid in list.countries) {
|
2019-11-02 11:50:56 +01:00
|
|
|
let country = list.countries[cid]
|
|
|
|
const filename = `${outputDir}/${cid}.m3u`
|
|
|
|
helper.createFile(filename, '#EXTM3U\n')
|
2019-11-02 13:43:41 +01:00
|
|
|
|
|
|
|
const channels = helper.sortBy(Object.values(country), ['title', 'url'])
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let channel of channels) {
|
2019-11-02 11:50:56 +01:00
|
|
|
helper.appendToFile(filename, channel.toString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:21:08 +01:00
|
|
|
function generateCategories() {
|
2019-11-02 11:26:21 +01:00
|
|
|
const outputDir = `${ROOT_DIR}/categories`
|
|
|
|
helper.createDir(outputDir)
|
|
|
|
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let cid in list.categories) {
|
2019-11-01 22:21:08 +01:00
|
|
|
let category = list.categories[cid]
|
2019-11-02 11:26:21 +01:00
|
|
|
const filename = `${outputDir}/${cid}.m3u`
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.createFile(filename, '#EXTM3U\n')
|
2019-11-02 13:43:41 +01:00
|
|
|
|
|
|
|
const channels = helper.sortBy(Object.values(category), ['title', 'url'])
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let channel of channels) {
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.appendToFile(filename, channel.toString())
|
2019-11-01 22:21:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateLanguages() {
|
2019-11-02 11:26:21 +01:00
|
|
|
const outputDir = `${ROOT_DIR}/languages`
|
|
|
|
helper.createDir(outputDir)
|
2019-11-02 11:50:56 +01:00
|
|
|
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let lid in list.languages) {
|
2019-11-01 22:21:08 +01:00
|
|
|
let language = list.languages[lid]
|
2019-11-02 11:26:21 +01:00
|
|
|
const filename = `${outputDir}/${lid}.m3u`
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.createFile(filename, '#EXTM3U\n')
|
2019-11-02 13:43:41 +01:00
|
|
|
|
|
|
|
const channels = helper.sortBy(Object.values(language), ['title', 'url'])
|
2020-04-11 03:34:50 +02:00
|
|
|
for (let channel of channels) {
|
2019-11-02 10:45:09 +01:00
|
|
|
helper.appendToFile(filename, channel.toString())
|
2019-11-01 22:21:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
main()
|