Update scripts

This commit is contained in:
freearhey 2025-03-29 11:39:46 +03:00
parent 74b3cff1d2
commit 02ec7e6f76
42 changed files with 1317 additions and 694 deletions

View file

@ -41,7 +41,7 @@ export class ApiClient {
}
async download(filename: string) {
const stream = await this.storage.createStream(`/temp/data/${filename}`)
const stream = await this.storage.createStream(`temp/data/${filename}`)
const bar = this.progressBar.create(0, 0, { filename })

View file

@ -1,9 +1,10 @@
import { Table } from 'console-table-printer'
import { ComplexOptions } from 'console-table-printer/dist/src/models/external-table'
export class CliTable {
table: Table
constructor(options?) {
constructor(options?: ComplexOptions | string[]) {
this.table = new Table(options)
}

View file

@ -18,7 +18,7 @@ export class IssueData {
return Boolean(this._data.get(key))
}
getString(key: string): string {
getString(key: string): string | undefined {
const deleteSymbol = '~'
return this._data.get(key) === deleteSymbol ? '' : this._data.get(key)

View file

@ -16,7 +16,7 @@ export class IssueLoader {
}
let issues: object[] = []
if (TESTING) {
issues = (await import('../../tests/__data__/input/issues/all.js')).default
issues = (await import('../../tests/__data__/input/playlist_update/issues.js')).default
} else {
issues = await octokit.paginate(octokit.rest.issues.listForRepo, {
owner: OWNER,

View file

@ -3,11 +3,10 @@ import { Issue } from '../models'
import { IssueData } from './issueData'
const FIELDS = new Dictionary({
'Stream ID': 'streamId',
'Channel ID': 'channelId',
'Channel ID (required)': 'channelId',
'Feed ID': 'feedId',
'Stream URL': 'streamUrl',
'Stream URL (optional)': 'streamUrl',
'Stream URL (required)': 'streamUrl',
'Broken Link': 'brokenLinks',
'Broken Links': 'brokenLinks',
Label: 'label',
@ -18,8 +17,7 @@ const FIELDS = new Dictionary({
'HTTP Referrer': 'httpReferrer',
'What happened to the stream?': 'reason',
Reason: 'reason',
Notes: 'notes',
'Notes (optional)': 'notes'
Notes: 'notes'
})
export class IssueParser {
@ -30,7 +28,7 @@ export class IssueParser {
fields.forEach((field: string) => {
const parsed = typeof field === 'string' ? field.split(/\r?\n/).filter(Boolean) : []
let _label = parsed.shift()
_label = _label ? _label.trim() : ''
_label = _label ? _label.replace(/ \(optional\)| \(required\)/, '').trim() : ''
let _value = parsed.join('\r\n')
_value = _value ? _value.trim() : ''

View file

@ -1,4 +1,5 @@
export type LogItem = {
type: string
filepath: string
count: number
}

View file

@ -1,12 +1,22 @@
import { Collection, Storage } from '@freearhey/core'
import { Collection, Storage, Dictionary } from '@freearhey/core'
import parser from 'iptv-playlist-parser'
import { Stream } from '../models'
type PlaylistPareserProps = {
storage: Storage
feedsGroupedByChannelId: Dictionary
channelsGroupedById: Dictionary
}
export class PlaylistParser {
storage: Storage
feedsGroupedByChannelId: Dictionary
channelsGroupedById: Dictionary
constructor({ storage }: { storage: Storage }) {
constructor({ storage, feedsGroupedByChannelId, channelsGroupedById }: PlaylistPareserProps) {
this.storage = storage
this.feedsGroupedByChannelId = feedsGroupedByChannelId
this.channelsGroupedById = channelsGroupedById
}
async parse(files: string[]): Promise<Collection> {
@ -21,41 +31,18 @@ export class PlaylistParser {
}
async parseFile(filepath: string): Promise<Collection> {
const streams = new Collection()
const content = await this.storage.load(filepath)
const parsed: parser.Playlist = parser.parse(content)
parsed.items.forEach((item: parser.PlaylistItem) => {
const { name, label, quality } = parseTitle(item.name)
const stream = new Stream({
channel: item.tvg.id,
name,
label,
quality,
filepath,
line: item.line,
url: item.url,
httpReferrer: item.http.referrer,
httpUserAgent: item.http['user-agent']
})
const streams = new Collection(parsed.items).map((data: parser.PlaylistItem) => {
const stream = new Stream(data)
.withFeed(this.feedsGroupedByChannelId)
.withChannel(this.channelsGroupedById)
.setFilepath(filepath)
streams.add(stream)
return stream
})
return streams
}
}
function parseTitle(title: string): { name: string; label: string; quality: string } {
const [, label] = title.match(/ \[(.*)\]$/) || [null, '']
title = title.replace(new RegExp(` \\[${escapeRegExp(label)}\\]$`), '')
const [, quality] = title.match(/ \(([0-9]+p)\)$/) || [null, '']
title = title.replace(new RegExp(` \\(${quality}\\)$`), '')
return { name: title, label, quality }
}
function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
}

View file

@ -11,15 +11,15 @@ export class StreamTester {
async test(stream: Stream) {
if (TESTING) {
const results = (await import('../../tests/__data__/input/test_results/all.js')).default
const results = (await import('../../tests/__data__/input/playlist_test/results.js')).default
return results[stream.url]
} else {
return this.checker.checkStream({
url: stream.url,
http: {
referrer: stream.httpReferrer,
'user-agent': stream.httpUserAgent
referrer: stream.getHttpReferrer(),
'user-agent': stream.getHttpUserAgent()
}
})
}