update wyzie subs

This commit is contained in:
Pas 2025-04-30 20:11:34 -06:00
parent 8231a767cf
commit a12f5641e1
3 changed files with 38 additions and 13 deletions

View file

@ -95,7 +95,7 @@
"node-fetch": "^3.3.2",
"set-cookie-parser": "^2.7.1",
"unpacker": "^1.0.1",
"wyzie-lib": "^2.2.1"
"wyzie-lib": "^2.2.3"
},
"packageManager": "pnpm@9.14.4"
}

View file

@ -45,8 +45,8 @@ importers:
specifier: ^1.0.1
version: 1.0.1
wyzie-lib:
specifier: ^2.2.1
version: 2.2.1
specifier: ^2.2.3
version: 2.2.3
devDependencies:
'@nabla/vite-plugin-eslint':
specifier: ^2.0.5
@ -2539,8 +2539,8 @@ packages:
utf-8-validate:
optional: true
wyzie-lib@2.2.1:
resolution: {integrity: sha512-oZtJnCTQCqLZimlD1Ex195+8e21/G5BWhixCE5/4Of77AI9igmIQCo/thWngOsdOufcnzvzTPYkWoNDxHc5lQg==}
wyzie-lib@2.2.3:
resolution: {integrity: sha512-UtRQfpzrbFeNJPRgOwB5GqccNWVTYzZao2Km/zv6SZ/J31lGlxh84euAUDR1cSsBec+SYrH2MgWpA8yyXFobMQ==}
y18n@5.0.8:
resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==}
@ -5248,7 +5248,7 @@ snapshots:
ws@8.18.0: {}
wyzie-lib@2.2.1: {}
wyzie-lib@2.2.3: {}
y18n@5.0.8: {}

View file

@ -3,6 +3,32 @@ import { type SubtitleData, searchSubtitles } from 'wyzie-lib';
import { Caption } from '@/providers/captions';
function isSubdlUrl(url: string) {
return url.endsWith('.subdl');
}
export function filterSubtitles(list: Caption[]) {
const selected: Record<string, Caption> = {};
for (const sub of list) {
const existing = selected[sub.language];
if (!existing) {
selected[sub.language] = sub;
continue;
}
const existingIsSubdl = isSubdlUrl(existing.url);
const currentIsSubdl = isSubdlUrl(sub.url);
if (existingIsSubdl && !currentIsSubdl) {
selected[sub.language] = sub;
}
}
return Object.values(selected);
}
export async function addWyzieCaptions(
captions: Caption[],
tmdbId: string | number,
@ -12,15 +38,14 @@ export async function addWyzieCaptions(
): Promise<Caption[]> {
try {
const searchParams: any = {
format: 'srt',
encoding: 'utf-8',
source: ['subdl', 'opensubtitles'],
};
// Prefer TMDB ID if available, otherwise use IMDB ID
if (tmdbId) {
searchParams.tmdb_id = typeof tmdbId === 'string' ? parseInt(tmdbId, 10) : tmdbId;
} else if (imdbId) {
if (tmdbId && imdbId) {
searchParams.imdb_id = imdbId;
} else if (tmdbId && !imdbId) {
searchParams.tmdb_id = typeof tmdbId === 'string' ? parseInt(tmdbId, 10) : tmdbId;
}
if (season && episode) {
@ -35,12 +60,12 @@ export async function addWyzieCaptions(
const wyzieCaptions: Caption[] = wyzieSubtitles.map((subtitle) => ({
id: subtitle.id,
url: subtitle.url,
type: subtitle.format as 'srt' | 'vtt',
type: subtitle.format === 'srt' || subtitle.format === 'vtt' ? subtitle.format : 'srt',
hasCorsRestrictions: false,
language: subtitle.language,
}));
return [...captions, ...wyzieCaptions];
return [...captions, ...filterSubtitles(wyzieCaptions)];
} catch (error) {
console.error('Error fetching Wyzie subtitles:', error);
return captions;