mirror of
https://github.com/p-stream/providers.git
synced 2026-01-11 20:10:33 +00:00
fix wyzie subs
This commit is contained in:
parent
ab26a61eea
commit
064c9ee8d6
4 changed files with 74 additions and 52 deletions
|
|
@ -107,14 +107,21 @@ export async function scrapeInvidualSource(
|
|||
|
||||
// Fall back to OpenSubtitles if no Wyzie subs found
|
||||
if (!playableStream.captions.some((caption) => caption.wyziesubs)) {
|
||||
const [imdbId, season, episode] = atob(ops.media.imdbId)
|
||||
.split('.')
|
||||
.map((x, i) => (i === 0 ? x : Number(x) || null));
|
||||
const mediaInfo = {
|
||||
...ops,
|
||||
media: {
|
||||
type: season && episode ? 'show' : 'movie',
|
||||
imdbId: imdbId?.toString() || '',
|
||||
...(season && episode ? { season: { number: season }, episode: { number: episode } } : {}),
|
||||
} as ScrapeMedia,
|
||||
};
|
||||
playableStream.captions = await addOpenSubtitlesCaptions(
|
||||
playableStream.captions,
|
||||
ops,
|
||||
btoa(
|
||||
`${ops.media.imdbId}${
|
||||
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
|
||||
}`,
|
||||
),
|
||||
mediaInfo,
|
||||
ops.media.imdbId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -172,9 +179,21 @@ export async function scrapeIndividualEmbed(
|
|||
const playableStreams = await validatePlayableStreams(output.stream, ops, embedScraper.id);
|
||||
if (playableStreams.length === 0) throw new NotFoundError('No playable streams found');
|
||||
|
||||
if (media && !ops.disableOpensubtitles)
|
||||
if (media && !ops.disableOpensubtitles) {
|
||||
const [imdbId, season, episode] = atob(media)
|
||||
.split('.')
|
||||
.map((x, i) => (i === 0 ? x : Number(x) || null));
|
||||
const mediaInfo = {
|
||||
...ops,
|
||||
media: {
|
||||
type: season && episode ? 'show' : 'movie',
|
||||
imdbId: imdbId?.toString() || '',
|
||||
...(season && episode ? { season: { number: season }, episode: { number: episode } } : {}),
|
||||
} as ScrapeMedia,
|
||||
};
|
||||
for (const playableStream of playableStreams)
|
||||
playableStream.captions = await addOpenSubtitlesCaptions(playableStream.captions, ops, media);
|
||||
playableStream.captions = await addOpenSubtitlesCaptions(playableStream.captions, mediaInfo, media);
|
||||
}
|
||||
|
||||
output.stream = playableStreams;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import { reorderOnIdList } from '@/utils/list';
|
|||
import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles';
|
||||
import { requiresProxy, setupProxy } from '@/utils/proxy';
|
||||
import { isValidStream, validatePlayableStream } from '@/utils/valid';
|
||||
import { addWyzieCaptions } from '@/utils/wyziesubs';
|
||||
|
||||
export type RunOutput = {
|
||||
sourceId: string;
|
||||
|
|
@ -119,27 +118,15 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
|||
// opensubtitles
|
||||
if (!ops.disableOpensubtitles) {
|
||||
if (ops.media.imdbId) {
|
||||
// Try Wyzie subs first
|
||||
playableStream.captions = await addWyzieCaptions(
|
||||
playableStream.captions = await addOpenSubtitlesCaptions(
|
||||
playableStream.captions,
|
||||
ops.media.tmdbId,
|
||||
ops.media.imdbId,
|
||||
ops.media.type === 'show' ? ops.media.season.number : undefined,
|
||||
ops.media.type === 'show' ? ops.media.episode.number : undefined,
|
||||
ops,
|
||||
btoa(
|
||||
`${ops.media.imdbId}${
|
||||
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
|
||||
}`,
|
||||
),
|
||||
);
|
||||
|
||||
// Fall back to OpenSubtitles if no Wyzie subs found
|
||||
if (!playableStream.captions.some((caption) => caption.wyziesubs)) {
|
||||
playableStream.captions = await addOpenSubtitlesCaptions(
|
||||
playableStream.captions,
|
||||
ops,
|
||||
btoa(
|
||||
`${ops.media.imdbId}${
|
||||
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
|
||||
}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -197,27 +184,15 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
|||
// opensubtitles
|
||||
if (!ops.disableOpensubtitles) {
|
||||
if (ops.media.imdbId) {
|
||||
// Try Wyzie subs first
|
||||
playableStream.captions = await addWyzieCaptions(
|
||||
playableStream.captions = await addOpenSubtitlesCaptions(
|
||||
playableStream.captions,
|
||||
ops.media.tmdbId,
|
||||
ops.media.imdbId,
|
||||
ops.media.type === 'show' ? ops.media.season.number : undefined,
|
||||
ops.media.type === 'show' ? ops.media.episode.number : undefined,
|
||||
ops,
|
||||
btoa(
|
||||
`${ops.media.imdbId}${
|
||||
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
|
||||
}`,
|
||||
),
|
||||
);
|
||||
|
||||
// Fall back to OpenSubtitles if no Wyzie subs found
|
||||
if (!playableStream.captions.some((caption) => caption.wyziesubs)) {
|
||||
playableStream.captions = await addOpenSubtitlesCaptions(
|
||||
playableStream.captions,
|
||||
ops,
|
||||
btoa(
|
||||
`${ops.media.imdbId}${
|
||||
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
|
||||
}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
embedOutput.stream = [playableStream];
|
||||
|
|
|
|||
|
|
@ -1,10 +1,17 @@
|
|||
import { ScrapeMedia } from '@/entrypoint/utils/media';
|
||||
import { Caption, labelToLanguageCode, removeDuplicatedLanguages } from '@/providers/captions';
|
||||
import { IndividualEmbedRunnerOptions } from '@/runners/individualRunner';
|
||||
import { ProviderRunnerOptions } from '@/runners/runner';
|
||||
|
||||
import { addWyzieCaptions } from './wyziesubs';
|
||||
|
||||
type CaptionOptions = (ProviderRunnerOptions | IndividualEmbedRunnerOptions) & {
|
||||
media?: ScrapeMedia;
|
||||
};
|
||||
|
||||
export async function addOpenSubtitlesCaptions(
|
||||
captions: Caption[],
|
||||
ops: ProviderRunnerOptions | IndividualEmbedRunnerOptions,
|
||||
ops: CaptionOptions,
|
||||
media: string,
|
||||
): Promise<Caption[]> {
|
||||
try {
|
||||
|
|
@ -12,6 +19,28 @@ export async function addOpenSubtitlesCaptions(
|
|||
.split('.')
|
||||
.map((x, i) => (i === 0 ? x : Number(x) || null));
|
||||
if (!imdbId) return captions;
|
||||
|
||||
// First try Wyzie subs
|
||||
const wyzieCaptions = await addWyzieCaptions(
|
||||
[],
|
||||
ops.media?.tmdbId?.toString() || '',
|
||||
imdbId.toString(),
|
||||
typeof season === 'number' ? season : undefined,
|
||||
typeof episode === 'number' ? episode : undefined,
|
||||
);
|
||||
|
||||
// If we found Wyzie subs, return them as OpenSubtitles captions
|
||||
if (wyzieCaptions.length > 0) {
|
||||
return [
|
||||
...captions,
|
||||
...wyzieCaptions.map((caption) => ({
|
||||
...caption,
|
||||
opensubtitles: true,
|
||||
})),
|
||||
];
|
||||
}
|
||||
|
||||
// Fall back to OpenSubtitles if no Wyzie subs found
|
||||
const Res: {
|
||||
LanguageName: string;
|
||||
SubDownloadLink: string;
|
||||
|
|
|
|||
|
|
@ -39,12 +39,11 @@ export async function addWyzieCaptions(
|
|||
try {
|
||||
const searchParams: any = {
|
||||
encoding: 'utf-8',
|
||||
source: ['subdl', 'opensubtitles'],
|
||||
source: 'all',
|
||||
imdb_id: imdbId,
|
||||
};
|
||||
|
||||
if (tmdbId && imdbId) {
|
||||
searchParams.imdb_id = imdbId;
|
||||
} else if (tmdbId && !imdbId) {
|
||||
if (tmdbId && !imdbId) {
|
||||
searchParams.tmdb_id = typeof tmdbId === 'string' ? parseInt(tmdbId, 10) : tmdbId;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue