mirror of
https://github.com/p-stream/providers.git
synced 2026-04-21 11:42:28 +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
|
// Fall back to OpenSubtitles if no Wyzie subs found
|
||||||
if (!playableStream.captions.some((caption) => caption.wyziesubs)) {
|
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 = await addOpenSubtitlesCaptions(
|
||||||
playableStream.captions,
|
playableStream.captions,
|
||||||
ops,
|
mediaInfo,
|
||||||
btoa(
|
ops.media.imdbId,
|
||||||
`${ops.media.imdbId}${
|
|
||||||
ops.media.type === 'show' ? `.${ops.media.season.number}.${ops.media.episode.number}` : ''
|
|
||||||
}`,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -172,9 +179,21 @@ export async function scrapeIndividualEmbed(
|
||||||
const playableStreams = await validatePlayableStreams(output.stream, ops, embedScraper.id);
|
const playableStreams = await validatePlayableStreams(output.stream, ops, embedScraper.id);
|
||||||
if (playableStreams.length === 0) throw new NotFoundError('No playable streams found');
|
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)
|
for (const playableStream of playableStreams)
|
||||||
playableStream.captions = await addOpenSubtitlesCaptions(playableStream.captions, ops, media);
|
playableStream.captions = await addOpenSubtitlesCaptions(playableStream.captions, mediaInfo, media);
|
||||||
|
}
|
||||||
|
|
||||||
output.stream = playableStreams;
|
output.stream = playableStreams;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import { reorderOnIdList } from '@/utils/list';
|
||||||
import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles';
|
import { addOpenSubtitlesCaptions } from '@/utils/opensubtitles';
|
||||||
import { requiresProxy, setupProxy } from '@/utils/proxy';
|
import { requiresProxy, setupProxy } from '@/utils/proxy';
|
||||||
import { isValidStream, validatePlayableStream } from '@/utils/valid';
|
import { isValidStream, validatePlayableStream } from '@/utils/valid';
|
||||||
import { addWyzieCaptions } from '@/utils/wyziesubs';
|
|
||||||
|
|
||||||
export type RunOutput = {
|
export type RunOutput = {
|
||||||
sourceId: string;
|
sourceId: string;
|
||||||
|
|
@ -119,27 +118,15 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
||||||
// opensubtitles
|
// opensubtitles
|
||||||
if (!ops.disableOpensubtitles) {
|
if (!ops.disableOpensubtitles) {
|
||||||
if (ops.media.imdbId) {
|
if (ops.media.imdbId) {
|
||||||
// Try Wyzie subs first
|
playableStream.captions = await addOpenSubtitlesCaptions(
|
||||||
playableStream.captions = await addWyzieCaptions(
|
|
||||||
playableStream.captions,
|
playableStream.captions,
|
||||||
ops.media.tmdbId,
|
ops,
|
||||||
ops.media.imdbId,
|
btoa(
|
||||||
ops.media.type === 'show' ? ops.media.season.number : undefined,
|
`${ops.media.imdbId}${
|
||||||
ops.media.type === 'show' ? ops.media.episode.number : undefined,
|
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
|
// opensubtitles
|
||||||
if (!ops.disableOpensubtitles) {
|
if (!ops.disableOpensubtitles) {
|
||||||
if (ops.media.imdbId) {
|
if (ops.media.imdbId) {
|
||||||
// Try Wyzie subs first
|
playableStream.captions = await addOpenSubtitlesCaptions(
|
||||||
playableStream.captions = await addWyzieCaptions(
|
|
||||||
playableStream.captions,
|
playableStream.captions,
|
||||||
ops.media.tmdbId,
|
ops,
|
||||||
ops.media.imdbId,
|
btoa(
|
||||||
ops.media.type === 'show' ? ops.media.season.number : undefined,
|
`${ops.media.imdbId}${
|
||||||
ops.media.type === 'show' ? ops.media.episode.number : undefined,
|
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];
|
embedOutput.stream = [playableStream];
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,17 @@
|
||||||
|
import { ScrapeMedia } from '@/entrypoint/utils/media';
|
||||||
import { Caption, labelToLanguageCode, removeDuplicatedLanguages } from '@/providers/captions';
|
import { Caption, labelToLanguageCode, removeDuplicatedLanguages } from '@/providers/captions';
|
||||||
import { IndividualEmbedRunnerOptions } from '@/runners/individualRunner';
|
import { IndividualEmbedRunnerOptions } from '@/runners/individualRunner';
|
||||||
import { ProviderRunnerOptions } from '@/runners/runner';
|
import { ProviderRunnerOptions } from '@/runners/runner';
|
||||||
|
|
||||||
|
import { addWyzieCaptions } from './wyziesubs';
|
||||||
|
|
||||||
|
type CaptionOptions = (ProviderRunnerOptions | IndividualEmbedRunnerOptions) & {
|
||||||
|
media?: ScrapeMedia;
|
||||||
|
};
|
||||||
|
|
||||||
export async function addOpenSubtitlesCaptions(
|
export async function addOpenSubtitlesCaptions(
|
||||||
captions: Caption[],
|
captions: Caption[],
|
||||||
ops: ProviderRunnerOptions | IndividualEmbedRunnerOptions,
|
ops: CaptionOptions,
|
||||||
media: string,
|
media: string,
|
||||||
): Promise<Caption[]> {
|
): Promise<Caption[]> {
|
||||||
try {
|
try {
|
||||||
|
|
@ -12,6 +19,28 @@ export async function addOpenSubtitlesCaptions(
|
||||||
.split('.')
|
.split('.')
|
||||||
.map((x, i) => (i === 0 ? x : Number(x) || null));
|
.map((x, i) => (i === 0 ? x : Number(x) || null));
|
||||||
if (!imdbId) return captions;
|
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: {
|
const Res: {
|
||||||
LanguageName: string;
|
LanguageName: string;
|
||||||
SubDownloadLink: string;
|
SubDownloadLink: string;
|
||||||
|
|
|
||||||
|
|
@ -39,12 +39,11 @@ export async function addWyzieCaptions(
|
||||||
try {
|
try {
|
||||||
const searchParams: any = {
|
const searchParams: any = {
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
source: ['subdl', 'opensubtitles'],
|
source: 'all',
|
||||||
|
imdb_id: imdbId,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tmdbId && imdbId) {
|
if (tmdbId && !imdbId) {
|
||||||
searchParams.imdb_id = imdbId;
|
|
||||||
} else if (tmdbId && !imdbId) {
|
|
||||||
searchParams.tmdb_id = typeof tmdbId === 'string' ? parseInt(tmdbId, 10) : tmdbId;
|
searchParams.tmdb_id = typeof tmdbId === 'string' ? parseInt(tmdbId, 10) : tmdbId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue