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>
26 lines
708 B
TypeScript
26 lines
708 B
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
|
|
import tlk from '@/data/parsers/tlk';
|
|
import { STREAM_URL } from '@/env';
|
|
|
|
export async function GET({ nextUrl: { searchParams } }: NextRequest) {
|
|
const tid = searchParams.get('tid');
|
|
|
|
if (!tid || !/^\d+$/.test(tid)) {
|
|
return NextResponse.json({ error: 'tid required' }, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
const magnet = await tlk.magnet(`download.php?id=${tid}`);
|
|
const [, infoHash] = magnet.match(/btih:([a-z0-9]+)/i) || [];
|
|
|
|
return NextResponse.json({
|
|
infoHash: infoHash?.toLowerCase() ?? null,
|
|
magnet,
|
|
m3u: `${STREAM_URL}/stream?m3u&link=${magnet}`
|
|
});
|
|
} catch (_) {
|
|
return NextResponse.error();
|
|
}
|
|
}
|