mirror of
https://github.com/iptv-org/iptv
synced 2026-07-06 07:17:18 -04:00
Update scripts
This commit is contained in:
@@ -1,26 +1,65 @@
|
||||
import { Collection } from '@freearhey/core'
|
||||
import * as sdk from '@iptv-org/sdk'
|
||||
import { Stream } from '../models'
|
||||
|
||||
type PlaylistOptions = {
|
||||
public: boolean
|
||||
public?: boolean
|
||||
}
|
||||
|
||||
export class Playlist {
|
||||
streams: Collection<Stream>
|
||||
options: {
|
||||
public: boolean
|
||||
}
|
||||
public: boolean
|
||||
|
||||
constructor(streams: Collection<Stream>, options?: PlaylistOptions) {
|
||||
this.streams = streams
|
||||
this.options = options || { public: false }
|
||||
this.public = options?.public === true
|
||||
}
|
||||
|
||||
getGuides(): Collection<sdk.Models.Guide> {
|
||||
const guides = new Collection<sdk.Models.Guide>()
|
||||
|
||||
this.streams.forEach(stream => {
|
||||
guides.concat(stream.getGuides())
|
||||
})
|
||||
|
||||
return guides
|
||||
}
|
||||
|
||||
getGuideUrls(): Collection<string> {
|
||||
function byFormat(source: sdk.Types.GuideSource) {
|
||||
if (source.format === 'GZIP') return 2
|
||||
if (source.format === 'XML') return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
const urls = new Collection<string>()
|
||||
|
||||
this.getGuides().forEach((guide: sdk.Models.Guide) => {
|
||||
const sources = new Collection(guide.sources)
|
||||
|
||||
const source = sources
|
||||
.filter((source: sdk.Types.GuideSource) => ['GZIP', 'XML'].includes(source.format))
|
||||
.sortBy([byFormat], ['desc'])
|
||||
.first()
|
||||
|
||||
if (source) urls.add(source.url)
|
||||
})
|
||||
|
||||
return urls.uniq()
|
||||
}
|
||||
|
||||
toString() {
|
||||
let output = '#EXTM3U\r\n'
|
||||
let output = '#EXTM3U'
|
||||
|
||||
const guideUrls = this.getGuideUrls()
|
||||
if (guideUrls.count()) {
|
||||
output += ` x-tvg-url="${guideUrls.join(',')}"`
|
||||
}
|
||||
|
||||
output += '\r\n'
|
||||
|
||||
this.streams.forEach((stream: Stream) => {
|
||||
output += stream.toString(this.options) + '\r\n'
|
||||
output += stream.toString({ public: this.public }) + '\r\n'
|
||||
})
|
||||
|
||||
return output
|
||||
|
||||
@@ -13,6 +13,15 @@ export class Stream extends sdk.Models.Stream {
|
||||
removed: boolean = false
|
||||
tvgId?: string
|
||||
statusCode?: string
|
||||
guides = new Collection<sdk.Models.Guide>()
|
||||
|
||||
setGuides(guides?: sdk.Models.Guide[]) {
|
||||
this.guides = new Collection(guides)
|
||||
}
|
||||
|
||||
getGuides(): Collection<sdk.Models.Guide> {
|
||||
return this.guides
|
||||
}
|
||||
|
||||
validate(): Collection<Error> {
|
||||
const errors = new Collection<Error>()
|
||||
@@ -80,12 +89,12 @@ export class Stream extends sdk.Models.Stream {
|
||||
quality: quality || null,
|
||||
url: data.url,
|
||||
referrer: data.http.referrer || null,
|
||||
user_agent: data.http['user-agent'] || null
|
||||
user_agent: data.http['user-agent'] || null,
|
||||
label: label || null
|
||||
})
|
||||
|
||||
stream.tvgId = data.tvg.id
|
||||
stream.line = data.line
|
||||
stream.label = label || null
|
||||
|
||||
return stream
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user