iptv/helpers/format.js

49 lines
912 B
JavaScript
Raw Normal View History

2019-07-20 09:03:31 +02:00
const util = require('./util')
2019-04-30 15:52:38 +02:00
2019-07-20 09:06:29 +02:00
const debug = false
2019-04-30 15:52:38 +02:00
let total = 0
function init() {
2019-07-20 09:03:31 +02:00
let countries = util.parsePlaylist('index.m3u')
2019-07-20 09:06:29 +02:00
if(debug) {
countries = countries.slice(0, 2)
}
2019-04-30 15:52:38 +02:00
let channels = []
for(let country of countries) {
2019-07-20 09:03:31 +02:00
const playlist = util.parsePlaylist(country.file)
2019-04-30 15:52:38 +02:00
for(let item of playlist) {
2019-07-20 09:03:31 +02:00
let channel = util.parseChannelData(item)
2019-04-30 15:52:38 +02:00
channels.push(channel)
}
2019-07-20 09:03:31 +02:00
channels = util.sortByTitle(channels)
2019-04-30 15:52:38 +02:00
2019-07-20 09:32:16 +02:00
util.createFile(country.file, '#EXTM3U\n')
2019-04-30 15:52:38 +02:00
channels.forEach(channel => {
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="${channel.group}",${channel.title}`
2019-04-30 15:52:38 +02:00
2019-07-20 09:32:16 +02:00
const data = '#EXTINF:' + info + '\n' + channel.file + '\n'
util.writeToFile(country.file, data)
2019-07-20 09:03:31 +02:00
})
2019-04-30 15:52:38 +02:00
total += channels.length
channels = []
}
}
init()
console.log(`Total: ${total}.`)