huya流代理

This commit is contained in:
mtvpls
2026-01-20 13:31:52 +08:00
parent 16e56dbb33
commit e2a94fee2d
3 changed files with 40 additions and 2 deletions

View 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 }
);
}
}

View File

@@ -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 });

View File

@@ -94,6 +94,7 @@ export default function WebLivePage() {
url: videoUrl,
isLive: true,
autoplay: true,
fullscreen: true,
customType: {
m3u8: m3u8Loader,
flv: flvLoader