mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-13 10:30:03 -04:00
Update format.js
This commit is contained in:
parent
8dd15f08f5
commit
573174c79d
1 changed files with 50 additions and 9 deletions
|
@ -1,5 +1,7 @@
|
||||||
|
const categories = require('./helpers/categories')
|
||||||
const parser = require('./helpers/parser')
|
const parser = require('./helpers/parser')
|
||||||
const utils = require('./helpers/utils')
|
const utils = require('./helpers/utils')
|
||||||
|
const file = require('./helpers/file')
|
||||||
const log = require('./helpers/log')
|
const log = require('./helpers/log')
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
@ -11,25 +13,64 @@ async function main() {
|
||||||
log.print(`\nProcessing '${playlist.url}'...`)
|
log.print(`\nProcessing '${playlist.url}'...`)
|
||||||
await parser
|
await parser
|
||||||
.parsePlaylist(playlist.url)
|
.parsePlaylist(playlist.url)
|
||||||
|
.then(removeWrongCategories)
|
||||||
|
.then(addMissingData)
|
||||||
.then(sortChannels)
|
.then(sortChannels)
|
||||||
.then(p => p.save())
|
.then(playlist => {
|
||||||
|
if (file.read(playlist.url) !== playlist.toString()) {
|
||||||
|
log.print('updated')
|
||||||
|
playlist.updated = true
|
||||||
|
}
|
||||||
|
|
||||||
|
playlist.save()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
log.print('\n')
|
log.print('\n')
|
||||||
log.finish()
|
log.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sortChannels(playlist) {
|
async function removeWrongCategories(playlist) {
|
||||||
const channels = [...playlist.channels]
|
for (const channel of playlist.channels) {
|
||||||
utils.sortBy(channels, ['name', 'url'])
|
if (!channel.category) continue
|
||||||
|
const valid = categories.find(c => c.name === channel.category)
|
||||||
if (JSON.stringify(playlist.channels) !== JSON.stringify(channels)) {
|
if (!valid) {
|
||||||
log.print('updated')
|
channel.category = ''
|
||||||
playlist.channels = channels
|
}
|
||||||
playlist.updated = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return playlist
|
return playlist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function addMissingData(playlist) {
|
||||||
|
for (const channel of playlist.channels) {
|
||||||
|
const code = file.getBasename(playlist.url)
|
||||||
|
// tvg-name
|
||||||
|
if (!channel.tvg.name && code !== 'unsorted' && channel.name) {
|
||||||
|
channel.tvg.name = channel.name.replace(/\"/gi, '')
|
||||||
|
}
|
||||||
|
// tvg-id
|
||||||
|
if (!channel.tvg.id && code !== 'unsorted' && channel.tvg.name) {
|
||||||
|
const id = utils.name2id(channel.tvg.name)
|
||||||
|
channel.tvg.id = id ? `${id}.${code}` : ''
|
||||||
|
}
|
||||||
|
// 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(';')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return playlist
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sortChannels(playlist) {
|
||||||
|
const channels = [...playlist.channels]
|
||||||
|
utils.sortBy(channels, ['name', 'url'])
|
||||||
|
playlist.channels = channels
|
||||||
|
|
||||||
|
return playlist
|
||||||
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue