mirror of
https://github.com/iptv-org/iptv
synced 2026-09-06 12:01:57 -04:00
Update scripts
This commit is contained in:
+45
-22
@@ -14,6 +14,8 @@ export class Stream extends sdk.Models.Stream {
|
||||
tvgId?: string
|
||||
statusCode?: string
|
||||
guides = new Collection<sdk.Models.Guide>()
|
||||
isNot247?: boolean
|
||||
isGeoBlocked?: boolean
|
||||
|
||||
setGuides(guides?: sdk.Models.Guide[]) {
|
||||
this.guides = new Collection(guides)
|
||||
@@ -48,47 +50,51 @@ export class Stream extends sdk.Models.Stream {
|
||||
}
|
||||
}
|
||||
|
||||
const data = {
|
||||
label: dataSet.isDeleted('label') ? '' : dataSet.getString('label'),
|
||||
quality: dataSet.isDeleted('quality') ? '' : dataSet.getString('quality'),
|
||||
httpUserAgent: dataSet.isDeleted('http_user_agent')
|
||||
? ''
|
||||
: dataSet.getString('http_user_agent'),
|
||||
httpReferrer: dataSet.isDeleted('http_referrer') ? '' : dataSet.getString('http_referrer')
|
||||
}
|
||||
const live247 = dataSet.getBoolean('live_247')
|
||||
const geoBlocked = dataSet.getBoolean('geo_blocked')
|
||||
|
||||
if (data.label !== undefined) this.label = data.label
|
||||
if (data.quality !== undefined) this.quality = data.quality
|
||||
if (data.httpUserAgent !== undefined) this.user_agent = data.httpUserAgent
|
||||
if (data.httpReferrer !== undefined) this.referrer = data.httpReferrer
|
||||
if (live247) this.isNot247 = live247
|
||||
if (geoBlocked) this.isGeoBlocked = geoBlocked
|
||||
|
||||
const quality = dataSet.isDeleted('quality') ? '' : dataSet.getString('quality')
|
||||
const httpUserAgent = dataSet.isDeleted('http_user_agent')
|
||||
? ''
|
||||
: dataSet.getString('http_user_agent')
|
||||
const httpReferrer = dataSet.isDeleted('http_referrer')
|
||||
? ''
|
||||
: dataSet.getString('http_referrer')
|
||||
|
||||
if (quality !== undefined) this.quality = quality
|
||||
if (httpUserAgent !== undefined) this.user_agent = httpUserAgent
|
||||
if (httpReferrer !== undefined) this.referrer = httpReferrer
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
static fromPlaylistItem(data: parser.PlaylistItem): Stream {
|
||||
function escapeRegExp(text) {
|
||||
function escapeRegExp(text: string) {
|
||||
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
|
||||
}
|
||||
|
||||
function parseName(name: string): {
|
||||
title: string
|
||||
label: string
|
||||
labels: string[]
|
||||
quality: string
|
||||
} {
|
||||
let title = name
|
||||
const [, label] = title.match(/ \[(.*)\]$/) || [null, '']
|
||||
title = title.replace(new RegExp(` \\[${escapeRegExp(label)}\\]$`), '')
|
||||
const [, labels] = title.match(/ \[(.*)\]$/) || [null, '']
|
||||
title = title.replace(new RegExp(` \\[${escapeRegExp(labels)}\\]$`), '')
|
||||
const [, quality] = title.match(/ \(([0-9]+[p|i])\)$/) || [null, '']
|
||||
title = title.replace(new RegExp(` \\(${quality}\\)$`), '')
|
||||
|
||||
return { title, label, quality }
|
||||
return { title, labels: labels.split(';'), quality }
|
||||
}
|
||||
|
||||
if (!data.name) throw new Error('"name" property is required')
|
||||
if (!data.url) throw new Error('"url" property is required')
|
||||
|
||||
const [channelId, feedId] = data.tvg.id.split('@')
|
||||
const { title, label, quality } = parseName(data.name)
|
||||
const { title, labels, quality } = parseName(data.name)
|
||||
|
||||
const stream = new Stream({
|
||||
channel: channelId || null,
|
||||
@@ -98,11 +104,13 @@ export class Stream extends sdk.Models.Stream {
|
||||
url: data.url,
|
||||
referrer: data.http.referrer || null,
|
||||
user_agent: data.http['user-agent'] || null,
|
||||
label: label || null
|
||||
label: null
|
||||
})
|
||||
|
||||
stream.tvgId = data.tvg.id
|
||||
stream.line = data.line
|
||||
stream.isNot247 = labels.includes('Not 24/7')
|
||||
stream.isGeoBlocked = labels.includes('Geo-blocked')
|
||||
|
||||
return stream
|
||||
}
|
||||
@@ -416,13 +424,28 @@ export class Stream extends sdk.Models.Stream {
|
||||
title += ` (${this.quality})`
|
||||
}
|
||||
|
||||
if (this.label) {
|
||||
title += ` [${this.label}]`
|
||||
const labels = this.getLabels()
|
||||
|
||||
if (labels.length) {
|
||||
title += ` [${labels.join(';')}]`
|
||||
}
|
||||
|
||||
return title
|
||||
}
|
||||
|
||||
getLabels(): string[] {
|
||||
let labels: string[] = []
|
||||
if (this.isNot247 === true) {
|
||||
labels.push('Not 24/7')
|
||||
}
|
||||
|
||||
if (this.isGeoBlocked === true) {
|
||||
labels.push('Geo-blocked')
|
||||
}
|
||||
|
||||
return labels
|
||||
}
|
||||
|
||||
toString(options: { public?: boolean } = {}) {
|
||||
options = { ...{ public: false }, ...options }
|
||||
|
||||
@@ -470,7 +493,7 @@ export class Stream extends sdk.Models.Stream {
|
||||
title: this.title,
|
||||
url: this.url,
|
||||
quality: this.quality,
|
||||
label: this.label,
|
||||
labels: this.getLabels(),
|
||||
user_agent: this.user_agent,
|
||||
referrer: this.referrer
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user