From 3efbee4acd7219607177855bbc60148a45471602 Mon Sep 17 00:00:00 2001 From: TPN Date: Thu, 23 May 2024 16:55:53 +0530 Subject: [PATCH] smov setup --- src/providers/captions.ts | 1 + src/runners/individualRunner.ts | 7 ++++--- src/runners/runner.ts | 6 +++--- src/utils/opensubtitles.ts | 16 ++++++++-------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/providers/captions.ts b/src/providers/captions.ts index 92e5db3..d64dcc2 100644 --- a/src/providers/captions.ts +++ b/src/providers/captions.ts @@ -9,6 +9,7 @@ export type CaptionType = keyof typeof captionTypes; export type Caption = { type: CaptionType; id: string; // only unique per stream + opensubtitles?: boolean; url: string; hasCorsRestrictions: boolean; language: string; diff --git a/src/runners/individualRunner.ts b/src/runners/individualRunner.ts index 7a5d9a2..ee0247c 100644 --- a/src/runners/individualRunner.ts +++ b/src/runners/individualRunner.ts @@ -6,7 +6,7 @@ import { EmbedOutput, SourcererOutput } from '@/providers/base'; import { ProviderList } from '@/providers/get'; import { ScrapeContext } from '@/utils/context'; import { NotFoundError } from '@/utils/errors'; -import { addMissingCaptions } from '@/utils/opensubtitles'; +import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles'; import { isValidStream, validatePlayableStreams } from '@/utils/valid'; export type IndividualSourceRunnerOptions = { @@ -81,7 +81,7 @@ export async function scrapeInvidualSource( // opensubtitles for (const playableStream of playableStreams) { - playableStream.captions = await addMissingCaptions( + playableStream.captions = await addOpenSubtitlesCaptions( playableStream.captions, ops, btoa( @@ -137,7 +137,8 @@ export async function scrapeIndividualEmbed( if (media) for (const playableStream of playableStreams) - playableStream.captions = await addMissingCaptions(playableStream.captions, ops, media); + playableStream.captions = await addOpenSubtitlesCaptions(playableStream.captions, ops, media); + output.stream = playableStreams; return output; diff --git a/src/runners/runner.ts b/src/runners/runner.ts index cb5b52f..86fbf4d 100644 --- a/src/runners/runner.ts +++ b/src/runners/runner.ts @@ -8,7 +8,7 @@ import { Stream } from '@/providers/streams'; import { ScrapeContext } from '@/utils/context'; import { NotFoundError } from '@/utils/errors'; import { reorderOnIdList } from '@/utils/list'; -import { addMissingCaptions } from '@/utils/opensubtitles'; +import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles'; import { isValidStream, validatePlayableStream } from '@/utils/valid'; export type RunOutput = { @@ -109,7 +109,7 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt if (!playableStream) throw new NotFoundError('No streams found'); // opensubtitles - playableStream.captions = await addMissingCaptions( + playableStream.captions = await addOpenSubtitlesCaptions( playableStream.captions, ops, btoa( @@ -166,7 +166,7 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt if (!playableStream) throw new NotFoundError('No streams found'); // opensubtitles - playableStream.captions = await addMissingCaptions( + playableStream.captions = await addOpenSubtitlesCaptions( playableStream.captions, ops, btoa( diff --git a/src/utils/opensubtitles.ts b/src/utils/opensubtitles.ts index 643183d..719ca02 100644 --- a/src/utils/opensubtitles.ts +++ b/src/utils/opensubtitles.ts @@ -2,7 +2,7 @@ import { Caption, labelToLanguageCode, removeDuplicatedLanguages } from '@/provi import { IndividualEmbedRunnerOptions } from '@/runners/individualRunner'; import { ProviderRunnerOptions } from '@/runners/runner'; -export async function addMissingCaptions( +export async function addOpenSubtitlesCaptions( captions: Caption[], ops: ProviderRunnerOptions | IndividualEmbedRunnerOptions, media: string, @@ -21,25 +21,25 @@ export async function addMissingCaptions( }, ); - const Captions: Caption[] = []; + const openSubtilesCaptions: Caption[] = []; for (const caption of Res) { const url = caption.SubDownloadLink.replace('.gz', '').replace('download/', 'download/subencoding-utf8/'); const language = labelToLanguageCode(caption.LanguageName); if (!url || !language) continue; - - // check if the stream already has the language - const existingCaption = captions.find((x) => x.language === language); - if (existingCaption) Captions.push(existingCaption); else - Captions.push({ + openSubtilesCaptions.push({ id: url, + opensubtitles: true, url, type: caption.SubFormat || 'srt', hasCorsRestrictions: false, language, }); } - return removeDuplicatedLanguages(Captions); + return { + ...captions, + ...removeDuplicatedLanguages(openSubtilesCaptions), + }; } catch { return captions; }