Update scripts

This commit is contained in:
freearhey
2025-12-04 18:32:25 +03:00
parent a27ba0c7d0
commit 20d3ecc074
9 changed files with 60 additions and 85 deletions

View File

@@ -1,5 +1,5 @@
import { PlaylistParser, StreamTester, CliTable } from '../../core'
import type { TestResult } from '../../core/streamTester'
import type { StreamTesterResult } from '../../core/streamTester'
import { ROOT_DIR, STREAMS_DIR } from '../../constants'
import { Logger, Collection } from '@freearhey/core'
import { program, OptionValues } from 'commander'
@@ -92,10 +92,10 @@ async function runTest(stream: Stream) {
const key = stream.getUniqKey()
results[key] = chalk.white('LOADING...')
const result: TestResult = await tester.test(stream)
const result: StreamTesterResult = await tester.test(stream)
let status = ''
const errorStatusCodes = ['ENOTFOUND', 'HTTP_404_NOT_FOUND']
const errorStatusCodes = ['ENOTFOUND', 'HTTP_404_NOT_FOUND', 'HTTP_404_UNKONWN_ERROR']
if (result.status.ok) status = chalk.green('OK')
else if (errorStatusCodes.includes(result.status.code)) {
status = chalk.red(result.status.code)
@@ -144,7 +144,7 @@ function drawTable() {
}
}
function onFinish(error: Error) {
function onFinish(error: Error | null | undefined) {
clearInterval(interval)
if (error) {

View File

@@ -71,9 +71,9 @@ async function removeStreams({
requests.forEach((issue: Issue) => {
const data = issue.data
if (data.missing('streamUrl')) return
if (data.missing('stream_url')) return
const streamUrls = data.getString('streamUrl') || ''
const streamUrls = data.getString('stream_url') || ''
let changed = false
streamUrls
@@ -104,14 +104,14 @@ async function editStreams({
requests.forEach((issue: Issue) => {
const data = issue.data
if (data.missing('streamUrl')) return
if (data.missing('stream_url')) return
const stream: Stream = streams.first(
(_stream: Stream) => _stream.url === data.getString('streamUrl')
(_stream: Stream) => _stream.url === data.getString('stream_url')
)
if (!stream) return
const streamId = data.getString('streamId') || ''
const streamId = data.getString('stream_id') || ''
const [channelId, feedId] = streamId.split('@')
if (channelId) {
@@ -138,12 +138,12 @@ async function addStreams({
)
requests.forEach((issue: Issue) => {
const data = issue.data
if (data.missing('streamId') || data.missing('streamUrl')) return
if (streams.includes((_stream: Stream) => _stream.url === data.getString('streamUrl'))) return
const streamUrl = data.getString('streamUrl') || ''
if (data.missing('stream_id') || data.missing('stream_url')) return
if (streams.includes((_stream: Stream) => _stream.url === data.getString('stream_url'))) return
const streamUrl = data.getString('stream_url') || ''
if (!isURI(streamUrl)) return
const streamId = data.getString('streamId') || ''
const streamId = data.getString('stream_id') || ''
const [channelId, feedId] = streamId.split('@')
const channel: sdk.Models.Channel | undefined = apiData.channelsKeyById.get(channelId)
@@ -151,9 +151,8 @@ async function addStreams({
const label = data.getString('label') || ''
const quality = data.getString('quality') || null
const httpUserAgent = data.getString('httpUserAgent') || null
const httpReferrer = data.getString('httpReferrer') || null
const directives = data.getArray('directives') || []
const httpUserAgent = data.getString('http_user_agent') || null
const httpReferrer = data.getString('http_referrer') || null
const stream = new Stream({
channel: channelId,
@@ -166,7 +165,7 @@ async function addStreams({
})
stream.label = label
stream.setDirectives(directives).updateTitle().updateFilepath()
stream.updateTitle().updateFilepath()
streams.add(stream)
processedIssues.add(issue.number)

View File

@@ -31,8 +31,8 @@ async function main() {
const streams = await parser.parse(files)
logger.info(`found ${streams.count()} streams`)
let errors = new Collection()
let warnings = new Collection()
const errors = new Collection()
const warnings = new Collection()
const streamsGroupedByFilepath = streams.groupBy((stream: Stream) => stream.getFilepath())
for (const filepath of streamsGroupedByFilepath.keys()) {
const streams = streamsGroupedByFilepath.get(filepath)
@@ -97,8 +97,10 @@ async function main() {
console.log(` ${chalk.gray(position)}${status}${logItem.message}`)
})
errors = errors.concat(log.filter((logItem: LogItem) => logItem.type === 'error'))
warnings = warnings.concat(log.filter((logItem: LogItem) => logItem.type === 'warning'))
log.forEach((logItem: LogItem) => {
if (logItem.type === 'error') errors.add(logItem)
else if (logItem.type === 'warning') warnings.add(logItem)
})
}
}

View File

@@ -47,7 +47,7 @@ async function main() {
issue.labels.find((label: string) => label === 'streams:remove')
)
removeRequests.forEach((issue: Issue) => {
const streamUrls = issue.data.getArray('streamUrl') || []
const streamUrls = issue.data.getArray('stream_url') || []
if (!streamUrls.length) {
const result = {
@@ -82,8 +82,8 @@ async function main() {
const addRequests = issues.filter(issue => issue.labels.includes('streams:add'))
const addRequestsBuffer = new Dictionary()
addRequests.forEach((issue: Issue) => {
const streamId = issue.data.getString('streamId') || ''
const streamUrl = issue.data.getString('streamUrl') || ''
const streamId = issue.data.getString('stream_id') || ''
const streamUrl = issue.data.getString('stream_url') || ''
const [channelId] = streamId.split('@')
const result = {
@@ -114,8 +114,8 @@ async function main() {
issue.labels.find((label: string) => label === 'streams:edit')
)
editRequests.forEach((issue: Issue) => {
const streamId = issue.data.getString('streamId') || ''
const streamUrl = issue.data.getString('streamUrl') || ''
const streamId = issue.data.getString('stream_id') || ''
const streamUrl = issue.data.getString('stream_url') || ''
const [channelId] = streamId.split('@')
const result = {
@@ -140,7 +140,7 @@ async function main() {
)
const channelSearchRequestsBuffer = new Dictionary()
channelSearchRequests.forEach((issue: Issue) => {
const streamId = issue.data.getString('streamId') || issue.data.getString('channelId') || ''
const streamId = issue.data.getString('stream_id') || issue.data.getString('channel_id') || ''
const [channelId, feedId] = streamId.split('@')
const result = {