From 62fac8017217747937a2657ff2b2a121f9090954 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Wed, 1 Nov 2023 05:38:07 +0300 Subject: [PATCH] Update scripts --- scripts/commands/api/generate.ts | 2 +- scripts/commands/playlist/generate.ts | 12 ++++++++++-- scripts/commands/playlist/update.ts | 2 ++ scripts/core/issueParser.ts | 2 ++ scripts/core/playlistParser.ts | 3 ++- scripts/models/stream.ts | 11 ++++++++++- 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/scripts/commands/api/generate.ts b/scripts/commands/api/generate.ts index f1acd6a8c..a3390af8f 100644 --- a/scripts/commands/api/generate.ts +++ b/scripts/commands/api/generate.ts @@ -13,7 +13,7 @@ async function main() { let streams = await parser.parse(files) streams = streams .map(data => new Stream(data)) - .orderBy((stream: Stream) => stream.channel) + .orderBy([(stream: Stream) => stream.channel, (stream: Stream) => stream.timeshift]) .map((stream: Stream) => stream.toJSON()) logger.info(`found ${streams.count()} streams`) diff --git a/scripts/commands/playlist/generate.ts b/scripts/commands/playlist/generate.ts index 7ca6d4a80..49fe0c0cd 100644 --- a/scripts/commands/playlist/generate.ts +++ b/scripts/commands/playlist/generate.ts @@ -37,7 +37,7 @@ async function main() { logger.info('loading streams...') let streams = await loadStreams({ channels, categories, languages }) let totalStreams = streams.count() - streams = streams.uniqBy((stream: Stream) => stream.channel || _.uniqueId()) + streams = streams.uniqBy((stream: Stream) => (stream.channel || _.uniqueId()) + stream.timeshift) logger.info(`found ${totalStreams} streams (including ${streams.count()} unique)`) const generatorsLogger = new Logger({ @@ -104,7 +104,15 @@ async function loadStreams({ let streams = await parser.parse(files) streams = streams - .orderBy([(stream: Stream) => stream.channel, (stream: Stream) => stream.url], ['asc', 'asc']) + .orderBy( + [ + (stream: Stream) => stream.channel, + (stream: Stream) => stream.timeshift, + (stream: Stream) => parseInt(stream.quality.replace('p', '')), + (stream: Stream) => stream.label + ], + ['asc', 'asc', 'desc', 'asc'] + ) .map((stream: Stream) => { const channel: Channel | undefined = groupedChannels.get(stream.channel) diff --git a/scripts/commands/playlist/update.ts b/scripts/commands/playlist/update.ts index b9814f463..e33e0c9c8 100644 --- a/scripts/commands/playlist/update.ts +++ b/scripts/commands/playlist/update.ts @@ -90,6 +90,7 @@ async function editStreams(loader: IssueLoader) { if (data.has('channel_name')) stream.name = data.get('channel_name') if (data.has('label')) stream.label = data.get('label') if (data.has('quality')) stream.quality = data.get('quality') + if (data.has('timeshift')) stream.timeshift = data.get('timeshift') if (data.has('user_agent')) stream.userAgent = data.get('user_agent') if (data.has('http_referrer')) stream.httpReferrer = data.get('http_referrer') if (data.has('channel_name')) stream.name = data.get('channel_name') @@ -114,6 +115,7 @@ async function addStreams(loader: IssueLoader) { url: data.get('stream_url'), label: data.get('label'), quality: data.get('quality'), + timeshift: data.get('timeshift'), userAgent: data.get('user_agent'), httpReferrer: data.get('http_referrer'), filepath: `${channel.country.toLowerCase()}.m3u`, diff --git a/scripts/core/issueParser.ts b/scripts/core/issueParser.ts index 196e03920..def939cd2 100644 --- a/scripts/core/issueParser.ts +++ b/scripts/core/issueParser.ts @@ -10,6 +10,8 @@ const FIELDS = new Dictionary({ 'Broken Link': 'stream_url', Label: 'label', Quality: 'quality', + Timeshift: 'timeshift', + 'Timeshift (optional)': 'timeshift', 'Channel Name': 'channel_name', 'HTTP User-Agent': 'user_agent', 'HTTP Referrer': 'http_referrer', diff --git a/scripts/core/playlistParser.ts b/scripts/core/playlistParser.ts index 296288e13..192fa5a45 100644 --- a/scripts/core/playlistParser.ts +++ b/scripts/core/playlistParser.ts @@ -40,7 +40,8 @@ export class PlaylistParser { line: item.line, url: item.url, httpReferrer: item.http.referrer, - userAgent: item.http['user-agent'] + userAgent: item.http['user-agent'], + timeshift: item.tvg.shift }) streams.add(stream) diff --git a/scripts/models/stream.ts b/scripts/models/stream.ts index 37559f931..11a752e08 100644 --- a/scripts/models/stream.ts +++ b/scripts/models/stream.ts @@ -11,6 +11,7 @@ type StreamProps = { label?: string quality?: string userAgent?: string + timeshift?: string } export class Stream { @@ -30,6 +31,7 @@ export class Stream { isNSFW: boolean groupTitle: string removed: boolean = false + timeshift: string constructor({ channel, @@ -40,7 +42,8 @@ export class Stream { name, quality, url, - userAgent + userAgent, + timeshift }: StreamProps) { this.channel = channel || '' this.filepath = filepath @@ -57,6 +60,7 @@ export class Stream { this.languages = new Collection() this.isNSFW = false this.groupTitle = 'Undefined' + this.timeshift = timeshift || '' } normalizeURL() { @@ -145,6 +149,7 @@ export class Stream { return { channel: this.channel, url: this.url, + timeshift: this.timeshift || null, http_referrer: this.httpReferrer || null, user_agent: this.userAgent || null } @@ -153,6 +158,10 @@ export class Stream { toString(options: { public: boolean }) { let output = `#EXTINF:-1 tvg-id="${this.channel}"` + if (this.timeshift) { + output += ` tvg-shift="${this.timeshift}"` + } + if (options.public) { output += ` tvg-logo="${this.logo}" group-title="${this.groupTitle}"` }