2021-08-01 18:52:47 +02:00
|
|
|
const parser = require('./helpers/parser')
|
|
|
|
const utils = require('./helpers/utils')
|
2021-08-02 20:12:27 +02:00
|
|
|
const file = require('./helpers/file')
|
2021-08-01 18:52:47 +02:00
|
|
|
const log = require('./helpers/log')
|
2019-07-20 09:06:29 +02:00
|
|
|
|
2019-11-03 14:03:35 +01:00
|
|
|
async function main() {
|
2021-08-01 07:25:39 +02:00
|
|
|
log.start()
|
2021-05-07 11:51:57 +02:00
|
|
|
|
2021-08-10 22:45:32 +02:00
|
|
|
log.print(`Parsing 'index.m3u'...`)
|
2021-08-01 07:25:39 +02:00
|
|
|
let playlists = parser.parseIndex().filter(i => i.url !== 'channels/unsorted.m3u')
|
2021-01-30 00:26:20 +01:00
|
|
|
for (const playlist of playlists) {
|
2021-08-10 22:45:32 +02:00
|
|
|
log.print(`\nProcessing '${playlist.url}'...`)
|
2021-08-01 18:52:47 +02:00
|
|
|
await parser
|
|
|
|
.parsePlaylist(playlist.url)
|
2021-08-10 22:45:32 +02:00
|
|
|
.then(formatPlaylist)
|
2021-08-02 20:12:27 +02:00
|
|
|
.then(playlist => {
|
|
|
|
if (file.read(playlist.url) !== playlist.toString()) {
|
2021-08-10 22:45:32 +02:00
|
|
|
log.print('updated')
|
2021-08-02 20:12:27 +02:00
|
|
|
playlist.updated = true
|
|
|
|
}
|
|
|
|
|
|
|
|
playlist.save()
|
|
|
|
})
|
2019-11-03 14:03:35 +01:00
|
|
|
}
|
|
|
|
|
2021-08-10 22:45:32 +02:00
|
|
|
log.print('\n')
|
2021-08-01 07:25:39 +02:00
|
|
|
log.finish()
|
2021-01-11 11:55:57 +01:00
|
|
|
}
|
|
|
|
|
2021-08-10 22:45:32 +02:00
|
|
|
async function formatPlaylist(playlist) {
|
2021-08-02 20:12:27 +02:00
|
|
|
for (const channel of playlist.channels) {
|
2021-08-10 22:45:32 +02:00
|
|
|
const code = file.getBasename(playlist.url)
|
|
|
|
// add missing tvg-name
|
|
|
|
if (!channel.tvg.name && code !== 'unsorted' && channel.name) {
|
|
|
|
channel.tvg.name = channel.name.replace(/\"/gi, '')
|
|
|
|
}
|
|
|
|
// add missing tvg-id
|
|
|
|
if (!channel.tvg.id && code !== 'unsorted' && channel.tvg.name) {
|
|
|
|
const id = utils.name2id(channel.tvg.name)
|
|
|
|
channel.tvg.id = id ? `${id}.${code}` : ''
|
2021-08-02 20:12:27 +02:00
|
|
|
}
|
2021-08-10 22:45:32 +02:00
|
|
|
// add missing country
|
|
|
|
if (!channel.countries.length) {
|
|
|
|
const name = utils.code2name(code)
|
|
|
|
channel.countries = name ? [{ code, name }] : []
|
|
|
|
channel.tvg.country = channel.countries.map(c => c.code.toUpperCase()).join(';')
|
|
|
|
}
|
|
|
|
// update group-title
|
|
|
|
channel.group.title = channel.category
|
2021-08-02 20:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return playlist
|
|
|
|
}
|
|
|
|
|
2019-11-03 08:56:54 +01:00
|
|
|
main()
|