Add proxyDepth option for hls

This commit is contained in:
TPN 2024-07-03 13:45:27 +01:00
parent c8b3a151ff
commit 70127b8588
No known key found for this signature in database
GPG key ID: 40AE091637892B91
2 changed files with 9 additions and 2 deletions

View file

@ -30,6 +30,7 @@ export type FileBasedStream = StreamCommon & {
export type HlsBasedStream = StreamCommon & {
type: 'hls';
playlist: string;
proxyDepth?: 0 | 1 | 2;
};
export type Stream = FileBasedStream | HlsBasedStream;

View file

@ -13,12 +13,18 @@ export function setupProxy(stream: Stream): Stream {
? encodeURIComponent(JSON.stringify(stream.headers))
: null;
const options = encodeURIComponent(
JSON.stringify({
...(stream.type === 'hls' && { depth: stream.proxyDepth ?? 0 }),
}),
);
if (stream.type === 'hls')
stream.playlist = `https://proxy.nsbx.ru/hls/${encodeURIComponent(stream.playlist)}/${headers}`;
stream.playlist = `https://proxy.nsbx.ru/hls/${encodeURIComponent(stream.playlist)}/${headers}/${options}`;
if (stream.type === 'file')
Object.entries(stream.qualities).forEach((entry) => {
entry[1].url = `https://proxy.nsbx.ru/mp4/${encodeURIComponent(entry[1].url)}/${headers}`;
entry[1].url = `https://proxy.nsbx.ru/mp4/${encodeURIComponent(entry[1].url)}/${headers}/${options}`;
});
stream.headers = {};