mirror of
https://github.com/iptv-org/iptv
synced 2026-04-25 12:17:19 -04:00
Update scripts
This commit is contained in:
31
scripts/commands/playlist/export.ts
Normal file
31
scripts/commands/playlist/export.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { API_DIR, STREAMS_DIR } from '../../constants'
|
||||
import { Storage } from '@freearhey/storage-js'
|
||||
import { PlaylistParser } from '../../core'
|
||||
import { Logger } from '@freearhey/core'
|
||||
import { Stream } from '../../models'
|
||||
import { loadData } from '../../api'
|
||||
|
||||
async function main() {
|
||||
const logger = new Logger()
|
||||
|
||||
logger.info('loading data from api...')
|
||||
await loadData()
|
||||
|
||||
logger.info('loading streams...')
|
||||
const streamsStorage = new Storage(STREAMS_DIR)
|
||||
const parser = new PlaylistParser({
|
||||
storage: streamsStorage
|
||||
})
|
||||
const files = await streamsStorage.list('**/*.m3u')
|
||||
const parsed = await parser.parse(files)
|
||||
const _streams = parsed
|
||||
.sortBy((stream: Stream) => stream.getId())
|
||||
.map((stream: Stream) => stream.toObject())
|
||||
logger.info(`found ${_streams.count()} streams`)
|
||||
|
||||
logger.info('saving to .api/streams.json...')
|
||||
const apiStorage = new Storage(API_DIR)
|
||||
await apiStorage.save('streams.json', _streams.toJSON())
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user