Update format.js

This commit is contained in:
Aleksandr Statciuk 2021-08-02 21:55:58 +03:00
parent 6e189ad5bc
commit a02e3db46a

View file

@ -12,7 +12,7 @@ async function main() {
log.print(`\nProcessing '${playlist.url}'...`) log.print(`\nProcessing '${playlist.url}'...`)
await parser await parser
.parsePlaylist(playlist.url) .parsePlaylist(playlist.url)
.then(addMissingData) .then(formatPlaylist)
.then(playlist => { .then(playlist => {
if (file.read(playlist.url) !== playlist.toString()) { if (file.read(playlist.url) !== playlist.toString()) {
log.print('updated') log.print('updated')
@ -27,24 +27,26 @@ async function main() {
log.finish() log.finish()
} }
async function addMissingData(playlist) { async function formatPlaylist(playlist) {
for (const channel of playlist.channels) { for (const channel of playlist.channels) {
const code = file.getBasename(playlist.url) const code = file.getBasename(playlist.url)
// tvg-name // add missing tvg-name
if (!channel.tvg.name && code !== 'unsorted' && channel.name) { if (!channel.tvg.name && code !== 'unsorted' && channel.name) {
channel.tvg.name = channel.name.replace(/\"/gi, '') channel.tvg.name = channel.name.replace(/\"/gi, '')
} }
// tvg-id // add missing tvg-id
if (!channel.tvg.id && code !== 'unsorted' && channel.tvg.name) { if (!channel.tvg.id && code !== 'unsorted' && channel.tvg.name) {
const id = utils.name2id(channel.tvg.name) const id = utils.name2id(channel.tvg.name)
channel.tvg.id = id ? `${id}.${code}` : '' channel.tvg.id = id ? `${id}.${code}` : ''
} }
// country // add missing country
if (!channel.countries.length) { if (!channel.countries.length) {
const name = utils.code2name(code) const name = utils.code2name(code)
channel.countries = name ? [{ code, name }] : [] channel.countries = name ? [{ code, name }] : []
channel.tvg.country = channel.countries.map(c => c.code.toUpperCase()).join(';') channel.tvg.country = channel.countries.map(c => c.code.toUpperCase()).join(';')
} }
// update group-title
channel.group.title = channel.category
} }
return playlist return playlist