Update format.js
This commit is contained in:
parent
78cecd8594
commit
0643d5eb1c
|
@ -4,7 +4,7 @@ const config = {
|
||||||
debug: process.env.npm_config_debug || false,
|
debug: process.env.npm_config_debug || false,
|
||||||
country: process.env.npm_config_country,
|
country: process.env.npm_config_country,
|
||||||
exclude: process.env.npm_config_exclude,
|
exclude: process.env.npm_config_exclude,
|
||||||
epg: process.env.npm_config_epg || false,
|
epg: process.env.npm_config_epg || false
|
||||||
}
|
}
|
||||||
|
|
||||||
let updated = 0
|
let updated = 0
|
||||||
|
@ -75,7 +75,7 @@ function parseIndex() {
|
||||||
function parsePlaylist(url) {
|
function parsePlaylist(url) {
|
||||||
const playlist = helper.parsePlaylist(url)
|
const playlist = helper.parsePlaylist(url)
|
||||||
|
|
||||||
playlist.items = playlist.items.map((item) => {
|
playlist.items = playlist.items.map(item => {
|
||||||
return helper.createChannel(item)
|
return helper.createChannel(item)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ function parsePlaylist(url) {
|
||||||
|
|
||||||
function sortChannels(playlist) {
|
function sortChannels(playlist) {
|
||||||
const channels = JSON.stringify(playlist.items)
|
const channels = JSON.stringify(playlist.items)
|
||||||
playlist.items = helper.sortBy(playlist.items, ['title', 'url'])
|
playlist.items = helper.sortBy(playlist.items, ['name', 'url'])
|
||||||
if (channels !== JSON.stringify(playlist.items)) {
|
if (channels !== JSON.stringify(playlist.items)) {
|
||||||
playlist.changed = true
|
playlist.changed = true
|
||||||
}
|
}
|
||||||
|
@ -95,14 +95,14 @@ function sortChannels(playlist) {
|
||||||
function removeDuplicates(playlist) {
|
function removeDuplicates(playlist) {
|
||||||
let buffer = {}
|
let buffer = {}
|
||||||
const channels = JSON.stringify(playlist.items)
|
const channels = JSON.stringify(playlist.items)
|
||||||
playlist.items = playlist.items.filter((i) => {
|
playlist.items = playlist.items.filter(i => {
|
||||||
let result = typeof buffer[i.url] === 'undefined'
|
let result = typeof buffer[i.url] === 'undefined'
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
buffer[i.url] = true
|
buffer[i.url] = true
|
||||||
} else {
|
} else {
|
||||||
if (config.debug) {
|
if (config.debug) {
|
||||||
console.log(`Duplicate of '${i.title}' has been removed`)
|
console.log(`Duplicate of '${i.name}' has been removed`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,34 +128,34 @@ async function loadEPG(url) {
|
||||||
function addDataFromEPG(playlist, epg) {
|
function addDataFromEPG(playlist, epg) {
|
||||||
if (!epg) return playlist
|
if (!epg) return playlist
|
||||||
|
|
||||||
for (let item of playlist.items) {
|
for (let channel of playlist.items) {
|
||||||
if (!item.id) continue
|
if (!channel.tvg.id) continue
|
||||||
|
|
||||||
const channel = epg.channels[item.id]
|
const epgItem = epg.channels[channel.tvg.id]
|
||||||
|
|
||||||
if (!channel) continue
|
if (!epgItem) continue
|
||||||
|
|
||||||
if (!item.name && channel.name.length) {
|
if (!channel.tvg.name && epgItem.name.length) {
|
||||||
item.name = channel.name[0].value
|
channel.tvg.name = epgItem.name[0].value
|
||||||
playlist.changed = true
|
playlist.changed = true
|
||||||
if (config.debug) {
|
if (config.debug) {
|
||||||
console.log(`Added tvg-name '${item.name}' to '${item.title}'`)
|
console.log(`Added tvg-name '${channel.tvg.name}' to '${channel.name}'`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.language && channel.name.length && channel.name[0].lang) {
|
if (!channel.language.length && epgItem.name.length && epgItem.name[0].lang) {
|
||||||
item.language = channel.name[0].lang
|
channel.setLanguage(epgItem.name[0].lang)
|
||||||
playlist.changed = true
|
playlist.changed = true
|
||||||
if (config.debug) {
|
if (config.debug) {
|
||||||
console.log(`Added tvg-language '${item.language}' to '${item.title}'`)
|
console.log(`Added tvg-language '${epgItem.name[0].lang}' to '${channel.name}'`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.logo && channel.icon.length) {
|
if (!channel.logo && epgItem.icon.length) {
|
||||||
item.logo = channel.icon[0]
|
channel.logo = epgItem.icon[0]
|
||||||
playlist.changed = true
|
playlist.changed = true
|
||||||
if (config.debug) {
|
if (config.debug) {
|
||||||
console.log(`Added tvg-logo '${item.logo}' to '${item.title}'`)
|
console.log(`Added tvg-logo '${channel.logo}' to '${channel.name}'`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,10 +173,10 @@ function updatePlaylist(filepath, playlist) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterUnsorted() {
|
function filterUnsorted() {
|
||||||
const urls = items.map((i) => i.url)
|
const urls = items.map(i => i.url)
|
||||||
const unsortedPlaylist = parsePlaylist('channels/unsorted.m3u')
|
const unsortedPlaylist = parsePlaylist('channels/unsorted.m3u')
|
||||||
const before = unsortedPlaylist.items.length
|
const before = unsortedPlaylist.items.length
|
||||||
unsortedPlaylist.items = unsortedPlaylist.items.filter((i) => !urls.includes(i.url))
|
unsortedPlaylist.items = unsortedPlaylist.items.filter(i => !urls.includes(i.url))
|
||||||
|
|
||||||
if (before !== unsortedPlaylist.items.length) {
|
if (before !== unsortedPlaylist.items.length) {
|
||||||
updatePlaylist('channels/unsorted.m3u', unsortedPlaylist)
|
updatePlaylist('channels/unsorted.m3u', unsortedPlaylist)
|
||||||
|
|
Loading…
Reference in New Issue