Update scripts

This commit is contained in:
freearhey 2025-05-01 00:51:41 +03:00
parent 5e5b87404c
commit bfb0d5872d
7 changed files with 39 additions and 47 deletions

View file

@ -32,7 +32,7 @@ async function main() {
const files = await streamsStorage.list('**/*.m3u') const files = await streamsStorage.list('**/*.m3u')
const streams = await parser.parse(files) const streams = await parser.parse(files)
logger.info('removing broken streams...') logger.info('removing streams...')
await removeStreams({ streams, issues }) await removeStreams({ streams, issues })
logger.info('edit stream description...') logger.info('edit stream description...')
@ -73,12 +73,12 @@ async function removeStreams({ streams, issues }: { streams: Collection; issues:
) )
requests.forEach((issue: Issue) => { requests.forEach((issue: Issue) => {
const data = issue.data const data = issue.data
if (data.missing('brokenLinks')) return if (data.missing('streamUrl')) return
const brokenLinks = data.getString('brokenLinks') || '' const streamUrls = data.getString('streamUrl') || ''
let changed = false let changed = false
brokenLinks streamUrls
.split(/\r?\n/) .split(/\r?\n/)
.filter(Boolean) .filter(Boolean)
.forEach(link => { .forEach(link => {
@ -131,15 +131,7 @@ async function editStreams({
.updateFilepath() .updateFilepath()
} }
const label = data.getString('label') || '' stream.update(data)
const quality = data.getString('quality') || ''
const httpUserAgent = data.getString('httpUserAgent') || ''
const httpReferrer = data.getString('httpReferrer') || ''
if (data.has('label')) stream.setLabel(label)
if (data.has('quality')) stream.setQuality(quality)
if (data.has('httpUserAgent')) stream.setUserAgent(httpUserAgent)
if (data.has('httpReferrer')) stream.setReferrer(httpReferrer)
processedIssues.add(issue.number) processedIssues.add(issue.number)
}) })

View file

@ -37,17 +37,17 @@ async function main() {
const streamsGroupedByChannelId = streams.groupBy((stream: Stream) => stream.channelId) const streamsGroupedByChannelId = streams.groupBy((stream: Stream) => stream.channelId)
const streamsGroupedById = streams.groupBy((stream: Stream) => stream.getId()) const streamsGroupedById = streams.groupBy((stream: Stream) => stream.getId())
logger.info('checking broken streams reports...') logger.info('checking streams:remove requests...')
const brokenStreamReports = issues.filter(issue => const removeRequests = issues.filter(issue =>
issue.labels.find((label: string) => label === 'broken stream') issue.labels.find((label: string) => label === 'streams:remove')
) )
brokenStreamReports.forEach((issue: Issue) => { removeRequests.forEach((issue: Issue) => {
const brokenLinks = issue.data.getArray('brokenLinks') || [] const streamUrls = issue.data.getArray('streamUrl') || []
if (!brokenLinks.length) { if (!streamUrls.length) {
const result = { const result = {
issueNumber: issue.number, issueNumber: issue.number,
type: 'broken stream', type: 'streams:remove',
streamId: undefined, streamId: undefined,
streamUrl: undefined, streamUrl: undefined,
status: 'missing_link' status: 'missing_link'
@ -55,10 +55,10 @@ async function main() {
report.add(result) report.add(result)
} else { } else {
for (const streamUrl of brokenLinks) { for (const streamUrl of streamUrls) {
const result = { const result = {
issueNumber: issue.number, issueNumber: issue.number,
type: 'broken stream', type: 'streams:remove',
streamId: undefined, streamId: undefined,
streamUrl: truncate(streamUrl), streamUrl: truncate(streamUrl),
status: 'pending' status: 'pending'

View file

@ -68,7 +68,7 @@ export class DataProcessor {
) )
const channelsKeyById = channels.keyBy((channel: Channel) => channel.id) const channelsKeyById = channels.keyBy((channel: Channel) => channel.id)
let feeds = new Collection(data.feeds).map(data => const feeds = new Collection(data.feeds).map(data =>
new Feed(data) new Feed(data)
.withChannel(channelsKeyById) .withChannel(channelsKeyById)
.withLanguages(languagesKeyByCode) .withLanguages(languagesKeyByCode)

View file

@ -7,8 +7,7 @@ const FIELDS = new Dictionary({
'Channel ID': 'channelId', 'Channel ID': 'channelId',
'Feed ID': 'feedId', 'Feed ID': 'feedId',
'Stream URL': 'streamUrl', 'Stream URL': 'streamUrl',
'Broken Link': 'brokenLinks', 'New Stream URL': 'newStreamUrl',
'Broken Links': 'brokenLinks',
Label: 'label', Label: 'label',
Quality: 'quality', Quality: 'quality',
'Channel Name': 'channelName', 'Channel Name': 'channelName',

View file

@ -1,4 +1,4 @@
import { Collection, Storage, Logger, File } from '@freearhey/core' import { Collection, Storage, File } from '@freearhey/core'
import { Stream, Category, Playlist } from '../models' import { Stream, Category, Playlist } from '../models'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator' import { Generator } from './generator'

View file

@ -1,5 +1,5 @@
import { Collection, Dictionary } from '@freearhey/core'
import { Country, Language, Region, Channel, Subdivision } from './index' import { Country, Language, Region, Channel, Subdivision } from './index'
import { Collection, Dictionary } from '@freearhey/core'
import type { FeedData } from '../types/feed' import type { FeedData } from '../types/feed'
export class Feed { export class Feed {
@ -106,7 +106,7 @@ export class Feed {
regionsKeyByCode: Dictionary, regionsKeyByCode: Dictionary,
subdivisionsKeyByCode: Dictionary subdivisionsKeyByCode: Dictionary
): this { ): this {
let broadcastCountries = new Collection() const broadcastCountries = new Collection()
if (this.isInternational()) { if (this.isInternational()) {
this.broadcastCountries = broadcastCountries this.broadcastCountries = broadcastCountries

View file

@ -2,6 +2,7 @@ import { Feed, Channel, Category, Region, Subdivision, Country, Language } from
import { URL, Collection, Dictionary } from '@freearhey/core' import { URL, Collection, Dictionary } from '@freearhey/core'
import type { StreamData } from '../types/stream' import type { StreamData } from '../types/stream'
import parser from 'iptv-playlist-parser' import parser from 'iptv-playlist-parser'
import { IssueData } from '../core'
export class Stream { export class Stream {
name?: string name?: string
@ -39,6 +40,24 @@ export class Stream {
this.label = data.label || undefined this.label = data.label || undefined
} }
update(issueData: IssueData): this {
const data = {
label: issueData.getString('label'),
quality: issueData.getString('quality'),
httpUserAgent: issueData.getString('httpUserAgent'),
httpReferrer: issueData.getString('httpReferrer'),
newStreamUrl: issueData.getString('newStreamUrl')
}
if (data.label !== undefined) this.label = data.label
if (data.quality !== undefined) this.setQuality(data.quality)
if (data.httpUserAgent !== undefined) this.userAgent = data.httpUserAgent
if (data.httpReferrer !== undefined) this.referrer = data.httpReferrer
if (data.newStreamUrl !== undefined) this.url = data.newStreamUrl
return this
}
fromPlaylistItem(data: parser.PlaylistItem): this { fromPlaylistItem(data: parser.PlaylistItem): this {
if (!data.name) throw new Error('"name" property is required') if (!data.name) throw new Error('"name" property is required')
if (!data.url) throw new Error('"url" property is required') if (!data.url) throw new Error('"url" property is required')
@ -98,12 +117,6 @@ export class Stream {
return this return this
} }
setLabel(label: string): this {
this.label = label
return this
}
setQuality(quality: string): this { setQuality(quality: string): this {
const { verticalResolution, isInterlaced } = parseQuality(quality) const { verticalResolution, isInterlaced } = parseQuality(quality)
@ -113,18 +126,6 @@ export class Stream {
return this return this
} }
setUserAgent(userAgent: string): this {
this.userAgent = userAgent
return this
}
setReferrer(referrer: string): this {
this.referrer = referrer
return this
}
getLine(): number { getLine(): number {
return this.line || -1 return this.line || -1
} }
@ -387,7 +388,7 @@ function parseQuality(quality: string | null): {
isInterlaced: boolean | null isInterlaced: boolean | null
} { } {
if (!quality) return { verticalResolution: null, isInterlaced: null } if (!quality) return { verticalResolution: null, isInterlaced: null }
let [, verticalResolutionString] = quality.match(/^(\d+)/) || [null, undefined] const [, verticalResolutionString] = quality.match(/^(\d+)/) || [null, undefined]
const isInterlaced = /i$/i.test(quality) const isInterlaced = /i$/i.test(quality)
let verticalResolution = 0 let verticalResolution = 0
if (verticalResolutionString) verticalResolution = parseInt(verticalResolutionString) if (verticalResolutionString) verticalResolution = parseInt(verticalResolutionString)