Update format.js
This commit is contained in:
parent
f27fe3e122
commit
c1ee2b2f19
@ -27,8 +27,8 @@ async function main() {
|
|||||||
log.start()
|
log.start()
|
||||||
|
|
||||||
if (config.debug) log.print(`Debug mode enabled\n`)
|
if (config.debug) log.print(`Debug mode enabled\n`)
|
||||||
if (config.status) log.print(`Updating channel status...\n`)
|
if (config.status) log.print(`Status check enabled\n`)
|
||||||
if (config.resolution) log.print(`Detecting channel resolution...\n`)
|
if (config.resolution) log.print(`Resolution detection enabled\n`)
|
||||||
|
|
||||||
let playlists = parser.parseIndex().filter(i => i.url !== 'channels/unsorted.m3u')
|
let playlists = parser.parseIndex().filter(i => i.url !== 'channels/unsorted.m3u')
|
||||||
playlists = utils.filterPlaylists(playlists, config.country, config.exclude)
|
playlists = utils.filterPlaylists(playlists, config.country, config.exclude)
|
||||||
@ -69,9 +69,19 @@ async function updatePlaylist(playlist) {
|
|||||||
await checker
|
await checker
|
||||||
.checkStream(channel.data)
|
.checkStream(channel.data)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (config.status) updateStatus(channel, result.status)
|
const status = parseStatus(result.status)
|
||||||
if (config.resolution && result.status.ok)
|
|
||||||
|
if (config.status) {
|
||||||
|
updateStatus(channel, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.resolution && status === 'online') {
|
||||||
updateResolution(channel, result.status.metadata)
|
updateResolution(channel, result.status.metadata)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.debug && status === 'offline') {
|
||||||
|
log.print(` ERR: ${channel.url} (${result.status.reason})\n`)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (config.debug) log.print(` ERR: ${channel.url} (${err.message})\n`)
|
if (config.debug) log.print(` ERR: ${channel.url} (${err.message})\n`)
|
||||||
@ -83,6 +93,31 @@ async function updatePlaylist(playlist) {
|
|||||||
return playlist
|
return playlist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseStatus(status) {
|
||||||
|
if (status.ok) {
|
||||||
|
return 'online'
|
||||||
|
} else if (status.reason.includes('timed out')) {
|
||||||
|
return 'timeout'
|
||||||
|
} else if (status.reason.includes('403')) {
|
||||||
|
return 'error_403'
|
||||||
|
} else if (status.reason.includes('not one of 40{0,1,3,4}')) {
|
||||||
|
return 'error_40x' // 402, 451
|
||||||
|
} else {
|
||||||
|
return 'offline'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateStatus(channel, status) {
|
||||||
|
switch (status) {
|
||||||
|
case 'online':
|
||||||
|
channel.status = null
|
||||||
|
break
|
||||||
|
case 'offline':
|
||||||
|
channel.status = 'Offline'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function addMissingData(channel) {
|
function addMissingData(channel) {
|
||||||
// add tvg-name
|
// add tvg-name
|
||||||
if (!channel.tvg.name && channel.name) {
|
if (!channel.tvg.name && channel.name) {
|
||||||
@ -103,21 +138,6 @@ function addMissingData(channel) {
|
|||||||
channel.group.title = channel.category
|
channel.group.title = channel.category
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStatus(channel, status) {
|
|
||||||
if (status.ok) {
|
|
||||||
channel.status = null
|
|
||||||
} else if (
|
|
||||||
status.reason.includes('timed out') ||
|
|
||||||
status.reason.includes('not one of 40{0,1,3,4}') ||
|
|
||||||
status.reason.includes('403')
|
|
||||||
) {
|
|
||||||
// nothing
|
|
||||||
} else {
|
|
||||||
channel.status = 'Offline'
|
|
||||||
if (config.debug) log.print(` ERR: ${channel.url} (${status.reason})\n`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateResolution(channel, metadata) {
|
function updateResolution(channel, metadata) {
|
||||||
const streams = metadata ? metadata.streams.filter(stream => stream.codec_type === 'video') : []
|
const streams = metadata ? metadata.streams.filter(stream => stream.codec_type === 'video') : []
|
||||||
if (!channel.resolution.height && streams.length) {
|
if (!channel.resolution.height && streams.length) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user