mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-02-27 15:24:42 +08:00
feat: add epg info
This commit is contained in:
52
src/app/api/live/epg/route.ts
Normal file
52
src/app/api/live/epg/route.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getCachedLiveChannels } from '@/lib/live';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const sourceKey = searchParams.get('source');
|
||||
const tvgId = searchParams.get('tvgId');
|
||||
|
||||
if (!sourceKey) {
|
||||
return NextResponse.json({ error: '缺少直播源参数' }, { status: 400 });
|
||||
}
|
||||
|
||||
if (!tvgId) {
|
||||
return NextResponse.json({ error: '缺少频道tvg-id参数' }, { status: 400 });
|
||||
}
|
||||
|
||||
const channelData = await getCachedLiveChannels(sourceKey);
|
||||
|
||||
if (!channelData) {
|
||||
// 频道信息未找到时返回空的节目单数据
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: {
|
||||
tvgId,
|
||||
source: sourceKey,
|
||||
epgUrl: '',
|
||||
programs: []
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 从epgs字段中获取对应tvgId的节目单信息
|
||||
const epgData = channelData.epgs[tvgId] || [];
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: {
|
||||
tvgId,
|
||||
source: sourceKey,
|
||||
epgUrl: channelData.epgUrl,
|
||||
programs: epgData
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: '获取节目单信息失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,18 @@ export async function GET(request: Request) {
|
||||
}
|
||||
|
||||
function rewriteM3U8Content(content: string, baseUrl: string, req: Request, allowCORS: boolean) {
|
||||
const protocol = req.headers.get('x-forwarded-proto') || 'http';
|
||||
// 从 referer 头提取协议信息
|
||||
const referer = req.headers.get('referer');
|
||||
let protocol = 'http';
|
||||
if (referer) {
|
||||
try {
|
||||
const refererUrl = new URL(referer);
|
||||
protocol = refererUrl.protocol.replace(':', '');
|
||||
} catch (error) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
const host = req.headers.get('host');
|
||||
const proxyBase = `${protocol}://${host}/api/proxy`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user