mirror of https://github.com/iptv-org/iptv
Update scripts
This commit is contained in:
parent
3612372a81
commit
f75d21fa68
|
@ -73,7 +73,7 @@ export default async function main(filepath: string) {
|
|||
logger.info('creating search index...')
|
||||
const items = channels.map((channel: Channel) => channel.getSearchable()).all()
|
||||
const searchIndex = sjs.createIndex(items, {
|
||||
searchable: ['name', 'altNames', 'guideNames', 'streamNames', 'feedFullNames']
|
||||
searchable: ['name', 'altNames', 'guideNames', 'streamTitles', 'feedFullNames']
|
||||
})
|
||||
|
||||
logger.info('starting...\n')
|
||||
|
@ -100,7 +100,7 @@ async function selectChannel(
|
|||
feedsGroupedByChannelId: Dictionary,
|
||||
channelsKeyById: Dictionary
|
||||
): Promise<string> {
|
||||
const query = escapeRegex(stream.getName())
|
||||
const query = escapeRegex(stream.getTitle())
|
||||
const similarChannels = searchIndex
|
||||
.search(query)
|
||||
.map((item: ChannelSearchableData) => channelsKeyById.get(item.id))
|
||||
|
@ -108,7 +108,7 @@ async function selectChannel(
|
|||
const url = stream.url.length > 50 ? stream.url.slice(0, 50) + '...' : stream.url
|
||||
|
||||
const selected: ChoiceValue = await select({
|
||||
message: `Select channel ID for "${stream.name}" (${url}):`,
|
||||
message: `Select channel ID for "${stream.title}" (${url}):`,
|
||||
choices: getChannelChoises(new Collection(similarChannels)),
|
||||
pageSize: 10
|
||||
})
|
||||
|
|
|
@ -53,7 +53,7 @@ async function main() {
|
|||
logger.info('sorting links...')
|
||||
streams = streams.orderBy(
|
||||
[
|
||||
(stream: Stream) => stream.name,
|
||||
(stream: Stream) => stream.title,
|
||||
(stream: Stream) => stream.getVerticalResolution(),
|
||||
(stream: Stream) => stream.getLabel(),
|
||||
(stream: Stream) => stream.url
|
||||
|
|
|
@ -129,7 +129,7 @@ async function editStreams({
|
|||
.withChannel(channelsKeyById)
|
||||
.withFeed(feedsGroupedByChannelId)
|
||||
.updateId()
|
||||
.updateName()
|
||||
.updateTitle()
|
||||
.updateFilepath()
|
||||
}
|
||||
|
||||
|
@ -173,11 +173,11 @@ async function addStreams({
|
|||
const directives = data.getArray('directives') || []
|
||||
|
||||
const stream = new Stream({
|
||||
channel: channelId,
|
||||
feed: feedId,
|
||||
name: data.getString('channelName') || channel.name,
|
||||
channelId,
|
||||
feedId,
|
||||
title: channel.name,
|
||||
url: streamUrl,
|
||||
user_agent: httpUserAgent,
|
||||
userAgent: httpUserAgent,
|
||||
referrer: httpReferrer,
|
||||
directives,
|
||||
quality,
|
||||
|
@ -185,7 +185,7 @@ async function addStreams({
|
|||
})
|
||||
.withChannel(channelsKeyById)
|
||||
.withFeed(feedsGroupedByChannelId)
|
||||
.updateName()
|
||||
.updateTitle()
|
||||
.updateFilepath()
|
||||
|
||||
streams.add(stream)
|
||||
|
|
|
@ -23,6 +23,7 @@ export class IssueLoader {
|
|||
repo: REPO,
|
||||
per_page: 100,
|
||||
labels,
|
||||
status: 'open',
|
||||
headers: {
|
||||
'X-GitHub-Api-Version': '2022-11-28'
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ const FIELDS = new Dictionary({
|
|||
'New Stream URL': 'newStreamUrl',
|
||||
Label: 'label',
|
||||
Quality: 'quality',
|
||||
'Channel Name': 'channelName',
|
||||
'HTTP User-Agent': 'httpUserAgent',
|
||||
'HTTP User Agent': 'httpUserAgent',
|
||||
'HTTP Referrer': 'httpReferrer',
|
||||
|
|
|
@ -133,9 +133,9 @@ export class Channel {
|
|||
return streams
|
||||
}
|
||||
|
||||
getStreamNames(): Collection {
|
||||
getStreamTitles(): Collection {
|
||||
return this.getStreams()
|
||||
.map((stream: Stream) => stream.getName())
|
||||
.map((stream: Stream) => stream.getTitle())
|
||||
.uniq()
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ export class Channel {
|
|||
name: this.name,
|
||||
altNames: this.altNames.all(),
|
||||
guideNames: this.getGuideNames().all(),
|
||||
streamNames: this.getStreamNames().all(),
|
||||
streamTitles: this.getStreamTitles().all(),
|
||||
feedFullNames: this.getFeedFullNames().all()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import { IssueData } from '../core'
|
|||
import path from 'node:path'
|
||||
|
||||
export class Stream {
|
||||
name?: string
|
||||
title: string
|
||||
url: string
|
||||
id?: string
|
||||
channelId?: string
|
||||
|
@ -28,16 +28,17 @@ export class Stream {
|
|||
constructor(data?: StreamData) {
|
||||
if (!data) return
|
||||
|
||||
const id = data.channel && data.feed ? [data.channel, data.feed].join('@') : data.channel
|
||||
const id =
|
||||
data.channelId && data.feedId ? [data.channelId, data.feedId].join('@') : data.channelId
|
||||
const { verticalResolution, isInterlaced } = parseQuality(data.quality)
|
||||
|
||||
this.id = id || undefined
|
||||
this.channelId = data.channel || undefined
|
||||
this.feedId = data.feed || undefined
|
||||
this.name = data.name || undefined
|
||||
this.channelId = data.channelId || undefined
|
||||
this.feedId = data.feedId || undefined
|
||||
this.title = data.title || undefined
|
||||
this.url = data.url
|
||||
this.referrer = data.referrer || undefined
|
||||
this.userAgent = data.user_agent || undefined
|
||||
this.userAgent = data.userAgent || undefined
|
||||
this.verticalResolution = verticalResolution || undefined
|
||||
this.isInterlaced = isInterlaced || undefined
|
||||
this.label = data.label || undefined
|
||||
|
@ -65,17 +66,18 @@ export class Stream {
|
|||
}
|
||||
|
||||
fromPlaylistItem(data: parser.PlaylistItem): this {
|
||||
function parseTitle(title: string): {
|
||||
name: string
|
||||
function parseName(name: string): {
|
||||
title: string
|
||||
label: string
|
||||
quality: string
|
||||
} {
|
||||
let title = name
|
||||
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 }
|
||||
return { title, label, quality }
|
||||
}
|
||||
|
||||
function parseDirectives(string: string) {
|
||||
|
@ -100,7 +102,7 @@ export class Stream {
|
|||
if (!data.url) throw new Error('"url" property is required')
|
||||
|
||||
const [channelId, feedId] = data.tvg.id.split('@')
|
||||
const { name, label, quality } = parseTitle(data.name)
|
||||
const { title, label, quality } = parseName(data.name)
|
||||
const { verticalResolution, isInterlaced } = parseQuality(quality)
|
||||
|
||||
this.id = data.tvg.id || undefined
|
||||
|
@ -108,7 +110,7 @@ export class Stream {
|
|||
this.channelId = channelId || undefined
|
||||
this.line = data.line
|
||||
this.label = label || undefined
|
||||
this.name = name
|
||||
this.title = title
|
||||
this.verticalResolution = verticalResolution || undefined
|
||||
this.isInterlaced = isInterlaced || undefined
|
||||
this.url = data.url
|
||||
|
@ -241,12 +243,12 @@ export class Stream {
|
|||
return parseInt(this.getQuality().replace(/p|i/, ''))
|
||||
}
|
||||
|
||||
updateName(): this {
|
||||
updateTitle(): this {
|
||||
if (!this.channel) return this
|
||||
|
||||
this.name = this.channel.name
|
||||
this.title = this.channel.name
|
||||
if (this.feed && !this.feed.isMain) {
|
||||
this.name += ` ${this.feed.name}`
|
||||
this.title += ` ${this.feed.name}`
|
||||
}
|
||||
|
||||
return this
|
||||
|
@ -375,12 +377,12 @@ export class Stream {
|
|||
return logo ? logo.url : ''
|
||||
}
|
||||
|
||||
getName(): string {
|
||||
return this.name || ''
|
||||
getTitle(): string {
|
||||
return this.title || ''
|
||||
}
|
||||
|
||||
getTitle(): string {
|
||||
let title = `${this.getName()}`
|
||||
getFullTitle(): string {
|
||||
let title = `${this.getTitle()}`
|
||||
|
||||
if (this.getQuality()) {
|
||||
title += ` (${this.getQuality()})`
|
||||
|
@ -405,6 +407,7 @@ export class Stream {
|
|||
return {
|
||||
channel: this.channelId || null,
|
||||
feed: this.feedId || null,
|
||||
title: this.title,
|
||||
url: this.url,
|
||||
referrer: this.referrer || null,
|
||||
user_agent: this.userAgent || null,
|
||||
|
@ -427,7 +430,7 @@ export class Stream {
|
|||
output += ` http-user-agent="${this.userAgent}"`
|
||||
}
|
||||
|
||||
output += `,${this.getTitle()}`
|
||||
output += `,${this.getFullTitle()}`
|
||||
|
||||
this.directives.forEach((prop: string) => {
|
||||
output += `\r\n${prop}`
|
||||
|
|
|
@ -45,6 +45,6 @@ export type ChannelSearchableData = {
|
|||
name: string
|
||||
altNames: string[]
|
||||
guideNames: string[]
|
||||
streamNames: string[]
|
||||
streamTitles: string[]
|
||||
feedFullNames: string[]
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
export type StreamData = {
|
||||
channel: string | null
|
||||
feed: string | null
|
||||
name: string | null
|
||||
channelId: string | null
|
||||
feedId: string | null
|
||||
title: string | null
|
||||
url: string
|
||||
referrer: string | null
|
||||
user_agent: string | null
|
||||
userAgent: string | null
|
||||
quality: string | null
|
||||
label: string | null
|
||||
directives: string[]
|
||||
|
|
Loading…
Reference in New Issue