mirror of
https://github.com/sussy-code/providers.git
synced 2026-04-05 01:09:50 +00:00
stupid eslint
This commit is contained in:
parent
ccfd5a2da0
commit
f0c992f7fe
1 changed files with 27 additions and 15 deletions
|
|
@ -1,29 +1,44 @@
|
|||
import { Caption, labelToLanguageCode, removeDuplicatedLanguages } from '@/providers/captions';
|
||||
import { IndividualEmbedRunnerOptions } from '@/runners/individualRunner';
|
||||
import { ProviderRunnerOptions } from '@/runners/runner';
|
||||
import {
|
||||
Caption,
|
||||
labelToLanguageCode,
|
||||
removeDuplicatedLanguages,
|
||||
} from "@/providers/captions";
|
||||
import { IndividualEmbedRunnerOptions } from "@/runners/individualRunner";
|
||||
import { ProviderRunnerOptions } from "@/runners/runner";
|
||||
|
||||
export async function addOpenSubtitlesCaptions(
|
||||
captions: Caption[],
|
||||
ops: ProviderRunnerOptions | IndividualEmbedRunnerOptions,
|
||||
media: string,
|
||||
media: string
|
||||
): Promise<Caption[]> {
|
||||
try {
|
||||
const [imdbId, season, episode] = atob(media)
|
||||
.split('.')
|
||||
.split(".")
|
||||
.map((x, i) => (i === 0 ? x : Number(x) || null));
|
||||
if (!imdbId) return captions;
|
||||
const Res: { LanguageName: string; SubDownloadLink: string; SubFormat: 'srt' | 'vtt' }[] = await ops.proxiedFetcher(
|
||||
`https://rest.opensubtitles.org/search/${season && episode ? `episode-${episode}/` : ''}imdbid-${(imdbId as string).slice(2)}${season && episode ? `/season-${season}` : ''}`,
|
||||
const Res: {
|
||||
LanguageName: string;
|
||||
SubDownloadLink: string;
|
||||
SubFormat: "srt" | "vtt";
|
||||
}[] = await ops.proxiedFetcher(
|
||||
`https://rest.opensubtitles.org/search/${
|
||||
season && episode ? `episode-${episode}/` : ""
|
||||
}imdbid-${(imdbId as string).slice(2)}${
|
||||
season && episode ? `/season-${season}` : ""
|
||||
}`,
|
||||
{
|
||||
headers: {
|
||||
'X-User-Agent': 'VLSub 0.10.2',
|
||||
"X-User-Agent": "VLSub 0.10.2",
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const openSubtilesCaptions: Caption[] = [];
|
||||
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);
|
||||
if (!url || !language) continue;
|
||||
else
|
||||
|
|
@ -31,15 +46,12 @@ export async function addOpenSubtitlesCaptions(
|
|||
id: url,
|
||||
opensubtitles: true,
|
||||
url,
|
||||
type: caption.SubFormat || 'srt',
|
||||
type: caption.SubFormat || "srt",
|
||||
hasCorsRestrictions: false,
|
||||
language,
|
||||
});
|
||||
}
|
||||
return [
|
||||
...captions,
|
||||
...removeDuplicatedLanguages(openSubtilesCaptions),
|
||||
];
|
||||
return [...captions, ...removeDuplicatedLanguages(openSubtilesCaptions)];
|
||||
} catch {
|
||||
return captions;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue