feat(player): external subtitles via OpenSubtitles

Add an OpenSubtitles client, /api/subtitles routes and useSubtitles to
fetch subtitles by show/episode/filename, wire them as player tracks
alongside embedded ones, and strip hls.js's auto-added tracks. New
OPENSUBTITLES_* / SUBTITLE_LANGUAGES env vars (documented in env.example).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
nerandClaude Opus 4.8 committed 2026-08-08 13:17:12 +03:00
1 parent c695697c4f
commit ecc57ff135
24 files changed
+372 -67

No files matched your search

-4
View File
@@ -16,8 +16,6 @@ const makeQueryClient = () => {
let browserQueryClient: QueryClient | undefined = undefined;
// One client per server request (React cache is request-scoped), so generateMetadata
// and the page share fetches instead of hitting TMDB twice for the same data.
const getServerQueryClient = cache(makeQueryClient);
const getQueryClient = () => {
@@ -25,8 +23,6 @@ const getQueryClient = () => {
try {
return getServerQueryClient();
} catch (_) {
// cache() only works in the RSC runtime; the SSR pass of client components
// (e.g. Providers) lands here and keeps its own per-render client as before
return makeQueryClient();
}
}
+7 -4
View File
@@ -13,8 +13,6 @@ export const slugify = (value: string) =>
.slice(0, 60)
.replace(/-+$/, '');
// Keyword-carrying show URL (/movie/27205-inception); the slug is optional decoration —
// routing only relies on the leading numeric id.
export const showPath = ({ type, id, title }: Pick<Show, 'type' | 'id' | 'title'>) => {
const slug = slugify(title || '');
@@ -50,11 +48,16 @@ export const getMagnetHash = (link: string) => {
return hash?.toUpperCase();
};
// Stable identity for a torrent that survives the lazy empty -> fetched magnet transition:
// Toloka has a permanent download URL, the rest always carry a magnet infohash.
export const torrentKey = (torrent: Torrent) =>
torrent.download || getMagnetHash(torrent.magnet) || torrent.hash || torrent.id;
export const parseSeasonEpisode = (value?: string): { season?: number; episode?: number } => {
const [, season, episode] =
value?.match(/S(\d{1,2})[ ._-]*E(\d{1,3})/i) || value?.match(/\b(\d{1,2})x(\d{2,3})\b/) || [];
return season ? { season: Number(season), episode: Number(episode) } : {};
};
export const seasonFromEpisodes = (episodes?: string): number | undefined => {
if (!episodes) return undefined;
if (/^S\d+\s*[-–—]\s*\d+/i.test(episodes)) return undefined;