Files
nerandClaude Opus 4.8 ecc57ff135 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>
2026-08-08 13:17:12 +03:00

35 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import torrentTitle from 'parse-torrent-title';
const SEASONS = [
/\(\s*[cс]езон[а-яіїєґ]*\s*(\d+)(?:\s*[-–—−]\s*(\d+))?([^)]*)\)/i,
/\(\s*(\d+)(?:\s*[-–—−]\s*(\d+))?\s*[cс]езон[а-яіїєґ]*([^)]*)\)/i,
/\(\s*seasons?\s*(\d+)(?:\s*[-–—−]\s*(\d+))?([^)]*)\)/i
];
const EPISODES = /,\s*(?:сері[яїй][^\d)]*)?(\d+)(?:\s*[-–—−]\s*(\d+))?(?:[^\d)]*?\s(?:зі?|of)\s*(\d+))?/i;
export const parseTolokaTitle = (originalTitle: string) => {
const seasonMatch = SEASONS.map((pattern) => originalTitle.match(pattern)).find(Boolean);
const cleaned = SEASONS.reduce((title, pattern) => title.replace(pattern, ' '), originalTitle)
.replace(/\s+/g, ' ')
.trim();
const parsed = torrentTitle.parse(cleaned);
const title = parsed.title.replace(/\s*[/|]\s*$/, '');
if (!seasonMatch) {
const { season, episode } = parsed;
return { ...parsed, title, episodes: season && episode ? `S${season}:E${episode}` : undefined };
}
const [, seasonFrom, seasonTo, details] = seasonMatch;
const [, from, to, total] = details.match(EPISODES) || [];
const hasEpisodes = from && (to || total || /сері/i.test(details));
const season = `S${seasonFrom}${seasonTo ? `-${seasonTo}` : ''}`;
const episodes = hasEpisodes ? `:E${from}${to ? `-${to}` : ''}${total ? `/${total}` : ''}` : '';
return { ...parsed, title, episodes: `${season}${episodes}` };
};