smov setup
This commit is contained in:
parent
5689e6319e
commit
3efbee4acd
|
@ -9,6 +9,7 @@ export type CaptionType = keyof typeof captionTypes;
|
||||||
export type Caption = {
|
export type Caption = {
|
||||||
type: CaptionType;
|
type: CaptionType;
|
||||||
id: string; // only unique per stream
|
id: string; // only unique per stream
|
||||||
|
opensubtitles?: boolean;
|
||||||
url: string;
|
url: string;
|
||||||
hasCorsRestrictions: boolean;
|
hasCorsRestrictions: boolean;
|
||||||
language: string;
|
language: string;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { EmbedOutput, SourcererOutput } from '@/providers/base';
|
||||||
import { ProviderList } from '@/providers/get';
|
import { ProviderList } from '@/providers/get';
|
||||||
import { ScrapeContext } from '@/utils/context';
|
import { ScrapeContext } from '@/utils/context';
|
||||||
import { NotFoundError } from '@/utils/errors';
|
import { NotFoundError } from '@/utils/errors';
|
||||||
import { addMissingCaptions } from '@/utils/opensubtitles';
|
import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles';
|
||||||
import { isValidStream, validatePlayableStreams } from '@/utils/valid';
|
import { isValidStream, validatePlayableStreams } from '@/utils/valid';
|
||||||
|
|
||||||
export type IndividualSourceRunnerOptions = {
|
export type IndividualSourceRunnerOptions = {
|
||||||
|
@ -81,7 +81,7 @@ export async function scrapeInvidualSource(
|
||||||
|
|
||||||
// opensubtitles
|
// opensubtitles
|
||||||
for (const playableStream of playableStreams) {
|
for (const playableStream of playableStreams) {
|
||||||
playableStream.captions = await addMissingCaptions(
|
playableStream.captions = await addOpenSubtitlesCaptions(
|
||||||
playableStream.captions,
|
playableStream.captions,
|
||||||
ops,
|
ops,
|
||||||
btoa(
|
btoa(
|
||||||
|
@ -137,7 +137,8 @@ export async function scrapeIndividualEmbed(
|
||||||
|
|
||||||
if (media)
|
if (media)
|
||||||
for (const playableStream of playableStreams)
|
for (const playableStream of playableStreams)
|
||||||
playableStream.captions = await addMissingCaptions(playableStream.captions, ops, media);
|
playableStream.captions = await addOpenSubtitlesCaptions(playableStream.captions, ops, media);
|
||||||
|
|
||||||
output.stream = playableStreams;
|
output.stream = playableStreams;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { Stream } from '@/providers/streams';
|
||||||
import { ScrapeContext } from '@/utils/context';
|
import { ScrapeContext } from '@/utils/context';
|
||||||
import { NotFoundError } from '@/utils/errors';
|
import { NotFoundError } from '@/utils/errors';
|
||||||
import { reorderOnIdList } from '@/utils/list';
|
import { reorderOnIdList } from '@/utils/list';
|
||||||
import { addMissingCaptions } from '@/utils/opensubtitles';
|
import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles';
|
||||||
import { isValidStream, validatePlayableStream } from '@/utils/valid';
|
import { isValidStream, validatePlayableStream } from '@/utils/valid';
|
||||||
|
|
||||||
export type RunOutput = {
|
export type RunOutput = {
|
||||||
|
@ -109,7 +109,7 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
||||||
if (!playableStream) throw new NotFoundError('No streams found');
|
if (!playableStream) throw new NotFoundError('No streams found');
|
||||||
|
|
||||||
// opensubtitles
|
// opensubtitles
|
||||||
playableStream.captions = await addMissingCaptions(
|
playableStream.captions = await addOpenSubtitlesCaptions(
|
||||||
playableStream.captions,
|
playableStream.captions,
|
||||||
ops,
|
ops,
|
||||||
btoa(
|
btoa(
|
||||||
|
@ -166,7 +166,7 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
||||||
if (!playableStream) throw new NotFoundError('No streams found');
|
if (!playableStream) throw new NotFoundError('No streams found');
|
||||||
|
|
||||||
// opensubtitles
|
// opensubtitles
|
||||||
playableStream.captions = await addMissingCaptions(
|
playableStream.captions = await addOpenSubtitlesCaptions(
|
||||||
playableStream.captions,
|
playableStream.captions,
|
||||||
ops,
|
ops,
|
||||||
btoa(
|
btoa(
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Caption, labelToLanguageCode, removeDuplicatedLanguages } from '@/provi
|
||||||
import { IndividualEmbedRunnerOptions } from '@/runners/individualRunner';
|
import { IndividualEmbedRunnerOptions } from '@/runners/individualRunner';
|
||||||
import { ProviderRunnerOptions } from '@/runners/runner';
|
import { ProviderRunnerOptions } from '@/runners/runner';
|
||||||
|
|
||||||
export async function addMissingCaptions(
|
export async function addOpenSubtitlesCaptions(
|
||||||
captions: Caption[],
|
captions: Caption[],
|
||||||
ops: ProviderRunnerOptions | IndividualEmbedRunnerOptions,
|
ops: ProviderRunnerOptions | IndividualEmbedRunnerOptions,
|
||||||
media: string,
|
media: string,
|
||||||
|
@ -21,25 +21,25 @@ export async function addMissingCaptions(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const Captions: Caption[] = [];
|
const openSubtilesCaptions: Caption[] = [];
|
||||||
for (const caption of Res) {
|
for (const caption of Res) {
|
||||||
const url = caption.SubDownloadLink.replace('.gz', '').replace('download/', 'download/subencoding-utf8/');
|
const url = caption.SubDownloadLink.replace('.gz', '').replace('download/', 'download/subencoding-utf8/');
|
||||||
const language = labelToLanguageCode(caption.LanguageName);
|
const language = labelToLanguageCode(caption.LanguageName);
|
||||||
if (!url || !language) continue;
|
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
|
else
|
||||||
Captions.push({
|
openSubtilesCaptions.push({
|
||||||
id: url,
|
id: url,
|
||||||
|
opensubtitles: true,
|
||||||
url,
|
url,
|
||||||
type: caption.SubFormat || 'srt',
|
type: caption.SubFormat || 'srt',
|
||||||
hasCorsRestrictions: false,
|
hasCorsRestrictions: false,
|
||||||
language,
|
language,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return removeDuplicatedLanguages(Captions);
|
return {
|
||||||
|
...captions,
|
||||||
|
...removeDuplicatedLanguages(openSubtilesCaptions),
|
||||||
|
};
|
||||||
} catch {
|
} catch {
|
||||||
return captions;
|
return captions;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue