huya流代理
This commit is contained in:
36
src/app/api/web-live/proxy/[filename]/route.ts
Normal file
36
src/app/api/web-live/proxy/[filename]/route.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const url = searchParams.get('url');
|
||||
|
||||
if (!url) {
|
||||
return NextResponse.json({ error: '缺少URL参数' }, { status: 400 });
|
||||
}
|
||||
|
||||
const streamRes = await fetch(url, {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
||||
'Referer': 'https://www.huya.com/'
|
||||
}
|
||||
});
|
||||
|
||||
if (!streamRes.ok) {
|
||||
return NextResponse.json({ error: '无法获取直播流' }, { status: 404 });
|
||||
}
|
||||
|
||||
return new NextResponse(streamRes.body, {
|
||||
headers: {
|
||||
'Content-Type': streamRes.headers.get('Content-Type') || 'application/octet-stream',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : '代理失败' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -56,9 +56,10 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
const { sFlvUrl, sStreamName, sFlvUrlSuffix, sFlvAntiCode } = streamInfo;
|
||||
const newAntiCode = getAntiCode(sFlvAntiCode, sStreamName);
|
||||
const url = `${sFlvUrl}/${sStreamName}.${sFlvUrlSuffix}?${newAntiCode}`;
|
||||
const streamUrl = `${sFlvUrl}/${sStreamName}.${sFlvUrlSuffix}?${newAntiCode}`;
|
||||
const proxyUrl = `/api/web-live/proxy/proxy.flv?url=${encodeURIComponent(streamUrl)}`;
|
||||
|
||||
return NextResponse.json({ url });
|
||||
return NextResponse.json({ url: proxyUrl });
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: '不支持的平台' }, { status: 400 });
|
||||
|
||||
@@ -94,6 +94,7 @@ export default function WebLivePage() {
|
||||
url: videoUrl,
|
||||
isLive: true,
|
||||
autoplay: true,
|
||||
fullscreen: true,
|
||||
customType: {
|
||||
m3u8: m3u8Loader,
|
||||
flv: flvLoader
|
||||
|
||||
Reference in New Issue
Block a user