Update scripts

This commit is contained in:
freearhey
2025-07-17 17:43:00 +03:00
parent 35a4b24bce
commit 2787186700
8 changed files with 44 additions and 15 deletions

View File

@@ -19,6 +19,7 @@ const xsd = `<?xml version="1.0" encoding="UTF-8"?>
<xs:attribute use="required" ref="site_id"/> <xs:attribute use="required" ref="site_id"/>
<xs:attribute name="xmltv_id" use="required" type="xs:string"/> <xs:attribute name="xmltv_id" use="required" type="xs:string"/>
<xs:attribute name="logo" type="xs:string"/> <xs:attribute name="logo" type="xs:string"/>
<xs:attribute name="lcn" type="xs:string"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:attribute name="site"> <xs:attribute name="site">

View File

@@ -1,6 +1,6 @@
import { Storage, Collection, Dictionary, File } from '@freearhey/core' import { Storage, Collection, Dictionary, File } from '@freearhey/core'
import { ChannelsParser } from '../../core' import { ChannelsParser } from '../../core'
import { Channel } from '../../models' import { Channel, Feed } from '../../models'
import { program } from 'commander' import { program } from 'commander'
import chalk from 'chalk' import chalk from 'chalk'
import langs from 'langs' import langs from 'langs'
@@ -10,7 +10,7 @@ import epgGrabber from 'epg-grabber'
program.argument('[filepath]', 'Path to *.channels.xml files to validate').parse(process.argv) program.argument('[filepath]', 'Path to *.channels.xml files to validate').parse(process.argv)
type ValidationError = { type ValidationError = {
type: 'duplicate' | 'wrong_xmltv_id' | 'wrong_lang' type: 'duplicate' | 'wrong_channel_id' | 'wrong_feed_id' | 'wrong_lang'
name: string name: string
lang?: string lang?: string
xmltv_id?: string xmltv_id?: string
@@ -24,7 +24,10 @@ async function main() {
const dataStorage = new Storage(DATA_DIR) const dataStorage = new Storage(DATA_DIR)
const channelsData = await dataStorage.json('channels.json') const channelsData = await dataStorage.json('channels.json')
const channels = new Collection(channelsData).map(data => new Channel(data)) const channels = new Collection(channelsData).map(data => new Channel(data))
const channelsGroupedById = channels.groupBy((channel: Channel) => channel.id) const channelsKeyById = channels.keyBy((channel: Channel) => channel.id)
const feedsData = await dataStorage.json('feeds.json')
const feeds = new Collection(feedsData).map(data => new Feed(data))
const feedsKeyByStreamId = feeds.keyBy((feed: Feed) => feed.getStreamId())
let totalFiles = 0 let totalFiles = 0
let totalErrors = 0 let totalErrors = 0
@@ -54,12 +57,21 @@ async function main() {
} }
if (!channel.xmltv_id) return if (!channel.xmltv_id) return
const [channelId] = channel.xmltv_id.split('@') const [channelId, feedId] = channel.xmltv_id.split('@')
const foundChannel = channelsGroupedById.get(channelId)
const foundChannel = channelsKeyById.get(channelId)
if (!foundChannel) { if (!foundChannel) {
errors.push({ type: 'wrong_xmltv_id', ...channel }) errors.push({ type: 'wrong_channel_id', ...channel })
totalErrors++ totalErrors++
} }
if (feedId) {
const foundFeed = feedsKeyByStreamId.get(channel.xmltv_id)
if (!foundFeed) {
errors.push({ type: 'wrong_feed_id', ...channel })
totalErrors++
}
}
}) })
if (errors.length) { if (errors.length) {

View File

@@ -44,6 +44,7 @@ program
.default(false) .default(false)
.env('GZIP') .env('GZIP')
) )
.addOption(new Option('--curl', 'Display each request as CURL').default(false).env('CURL'))
.parse() .parse()
export type GrabOptions = { export type GrabOptions = {
@@ -51,6 +52,7 @@ export type GrabOptions = {
channels?: string channels?: string
output: string output: string
gzip: boolean gzip: boolean
curl: boolean
maxConnections: number maxConnections: number
timeout?: string timeout?: string
delay?: string delay?: string

View File

@@ -70,6 +70,10 @@ export class Grabber {
} }
} }
if (this.options.curl === true) {
config.curl = true
}
const _programs = await this.grabber.grab( const _programs = await this.grabber.grab(
channel, channel,
date, date,

View File

@@ -29,7 +29,7 @@ export class GuideManager {
const pathTemplate = new StringTemplate(this.options.output) const pathTemplate = new StringTemplate(this.options.output)
const groupedChannels = this.channels const groupedChannels = this.channels
.orderBy([(channel: Channel) => channel.xmltv_id]) .orderBy([(channel: Channel) => channel.index, (channel: Channel) => channel.xmltv_id])
.uniqBy((channel: Channel) => `${channel.xmltv_id}:${channel.site}:${channel.lang}`) .uniqBy((channel: Channel) => `${channel.xmltv_id}:${channel.site}:${channel.lang}`)
.groupBy((channel: Channel) => { .groupBy((channel: Channel) => {
return pathTemplate.format({ lang: channel.lang || 'en', site: channel.site || '' }) return pathTemplate.format({ lang: channel.lang || 'en', site: channel.site || '' })

View File

@@ -2,9 +2,9 @@ import { URL } from 'node:url'
type ProxyParserResult = { type ProxyParserResult = {
protocol: string | null protocol: string | null
auth: { auth?: {
username: string | null username?: string
password: string | null password?: string
} }
host: string host: string
port: number | null port: number | null
@@ -14,14 +14,18 @@ export class ProxyParser {
parse(_url: string): ProxyParserResult { parse(_url: string): ProxyParserResult {
const parsed = new URL(_url) const parsed = new URL(_url)
return { const result: ProxyParserResult = {
protocol: parsed.protocol.replace(':', '') || null, protocol: parsed.protocol.replace(':', '') || null,
auth: {
username: parsed.username || null,
password: parsed.password || null
},
host: parsed.hostname, host: parsed.hostname,
port: parsed.port ? parseInt(parsed.port) : null port: parsed.port ? parseInt(parsed.port) : null
} }
if (parsed.username || parsed.password) {
result.auth = {}
if (parsed.username) result.auth.username = parsed.username
if (parsed.password) result.auth.password = parsed.password
}
return result
} }
} }

View File

@@ -35,8 +35,10 @@ export class QueueCreator {
const channelsContent = await this.dataStorage.json('channels.json') const channelsContent = await this.dataStorage.json('channels.json')
const channels = new Collection(channelsContent).map(data => new Channel(data)) const channels = new Collection(channelsContent).map(data => new Channel(data))
let index = 0
const queue = new Queue() const queue = new Queue()
for (const channel of this.parsedChannels.all()) { for (const channel of this.parsedChannels.all()) {
channel.index = index++
if (!channel.site || !channel.site_id || !channel.name) continue if (!channel.site || !channel.site_id || !channel.name) continue
const configPath = path.resolve(SITES_DIR, `${channel.site}/${channel.site}.config.js`) const configPath = path.resolve(SITES_DIR, `${channel.site}/${channel.site}.config.js`)

View File

@@ -69,4 +69,8 @@ export class Feed {
return `${this.channel.name} ${this.name}` return `${this.channel.name} ${this.name}`
} }
getStreamId(): string {
return `${this.channelId}@${this.id}`
}
} }