smov setup

This commit is contained in:
TPN 2024-05-23 16:55:53 +05:30
parent 5689e6319e
commit 3efbee4acd
4 changed files with 16 additions and 14 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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(

View File

@ -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;
}