mirror of
https://github.com/iptv-org/iptv
synced 2026-05-09 02:57:34 -04:00
Update test.ts
This commit is contained in:
@@ -21,7 +21,15 @@ const results: { [key: string]: string } = {}
|
|||||||
let interval: string | number | NodeJS.Timeout | undefined
|
let interval: string | number | NodeJS.Timeout | undefined
|
||||||
let streams = new Collection<Stream>()
|
let streams = new Collection<Stream>()
|
||||||
let isLiveUpdateEnabled = true
|
let isLiveUpdateEnabled = true
|
||||||
const errorStatusCodes = ['ENOTFOUND', 'HTTP_404_NOT_FOUND', 'HTTP_404_UNKONWN_ERROR']
|
const errorStatusCodes = [
|
||||||
|
'ENOTFOUND',
|
||||||
|
'ENETUNREACH',
|
||||||
|
'ECONNREFUSED',
|
||||||
|
'HTTP_404_NOT_FOUND',
|
||||||
|
'HTTP_404_UNKONWN_ERROR',
|
||||||
|
'HTTP_403_FORBIDDEN',
|
||||||
|
'HTTP_401_UNAUTHORIZED'
|
||||||
|
]
|
||||||
|
|
||||||
program
|
program
|
||||||
.argument('[filepath...]', 'Path to file to test')
|
.argument('[filepath...]', 'Path to file to test')
|
||||||
@@ -98,17 +106,12 @@ async function runTest(stream: Stream) {
|
|||||||
|
|
||||||
stream.statusCode = result.status.code
|
stream.statusCode = result.status.code
|
||||||
|
|
||||||
let status = ''
|
if (stream.statusCode === 'OK') return
|
||||||
if (result.status.ok) status = chalk.green('OK')
|
if (errorStatusCodes.includes(stream.statusCode) && !stream.label) {
|
||||||
else if (errorStatusCodes.includes(result.status.code)) {
|
|
||||||
status = chalk.red(result.status.code)
|
|
||||||
errors++
|
errors++
|
||||||
} else {
|
} else {
|
||||||
status = chalk.yellow(result.status.code)
|
|
||||||
warnings++
|
warnings++
|
||||||
}
|
}
|
||||||
|
|
||||||
results[key] = status
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawTable() {
|
function drawTable() {
|
||||||
@@ -130,7 +133,6 @@ function drawTable() {
|
|||||||
})
|
})
|
||||||
streams.forEach((stream: Stream, index: number) => {
|
streams.forEach((stream: Stream, index: number) => {
|
||||||
const key = stream.getUniqKey()
|
const key = stream.getUniqKey()
|
||||||
const status = results[key] || chalk.gray('PENDING')
|
|
||||||
const tvgId = stream.getTvgId()
|
const tvgId = stream.getTvgId()
|
||||||
|
|
||||||
const row = {
|
const row = {
|
||||||
@@ -138,7 +140,7 @@ function drawTable() {
|
|||||||
'tvg-id': truncate(tvgId, 25),
|
'tvg-id': truncate(tvgId, 25),
|
||||||
url: truncate(stream.url, 100),
|
url: truncate(stream.url, 100),
|
||||||
label: stream.label,
|
label: stream.label,
|
||||||
status
|
status: getStatus(stream)
|
||||||
}
|
}
|
||||||
table.append(row)
|
table.append(row)
|
||||||
})
|
})
|
||||||
@@ -154,9 +156,7 @@ async function removeBrokenLinks() {
|
|||||||
for (const filepath of streamsGrouped.keys()) {
|
for (const filepath of streamsGrouped.keys()) {
|
||||||
let streams: Collection<Stream> = new Collection(streamsGrouped.get(filepath))
|
let streams: Collection<Stream> = new Collection(streamsGrouped.get(filepath))
|
||||||
|
|
||||||
streams = streams.filter((stream: Stream) =>
|
streams = streams.filter((stream: Stream) => !isBroken(stream))
|
||||||
!stream.statusCode || stream.label ? true : !errorStatusCodes.includes(stream.statusCode)
|
|
||||||
)
|
|
||||||
|
|
||||||
const playlist = new Playlist(streams, { public: false })
|
const playlist = new Playlist(streams, { public: false })
|
||||||
await rootStorage.save(filepath, playlist.toString())
|
await rootStorage.save(filepath, playlist.toString())
|
||||||
@@ -198,3 +198,20 @@ async function isOffline() {
|
|||||||
})
|
})
|
||||||
}).catch(() => {})
|
}).catch(() => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getStatus(stream: Stream): string {
|
||||||
|
if (!stream.statusCode) return chalk.gray('PENDING')
|
||||||
|
if (stream.statusCode === 'OK') return chalk.green(stream.statusCode)
|
||||||
|
if (errorStatusCodes.includes(stream.statusCode) && !stream.label)
|
||||||
|
return chalk.red(stream.statusCode)
|
||||||
|
|
||||||
|
return chalk.yellow(stream.statusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
function isBroken(stream: Stream): boolean {
|
||||||
|
if (!stream.statusCode) return false
|
||||||
|
if (stream.label) return false
|
||||||
|
if (!errorStatusCodes.includes(stream.statusCode)) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user