api: initial subtitles functionality with youtube support

this took way more effort than i expected it to do, mostly because of youtube locking everything down to shit

local processing doesn't function with subtitles yet, wasm needs to be updated
This commit is contained in:
wukko
2025-06-18 20:19:19 +06:00
parent 967552b26b
commit 259a0758f1
5 changed files with 149 additions and 38 deletions

View File

@@ -41,7 +41,10 @@ export function createStream(obj) {
audioFormat: obj.audioFormat,
isHLS: obj.isHLS || false,
originalRequest: obj.originalRequest
originalRequest: obj.originalRequest,
// url to a subtitle file
subtitles: obj.subtitles,
};
// FIXME: this is now a Promise, but it is not awaited
@@ -94,6 +97,18 @@ export function createProxyTunnels(info) {
);
}
if (info.subtitles) {
proxyTunnels.push(
createStream({
url: info.subtitles,
type: "proxy",
service: `${info?.service}-subtitles`,
headers: info?.headers,
requestIP: info?.requestIP
})
);
}
return proxyTunnels;
}
@@ -111,7 +126,7 @@ export function getInternalTunnelFromURL(url) {
return getInternalTunnel(id);
}
export function createInternalStream(url, obj = {}) {
export function createInternalStream(url, obj = {}, isSubtitles) {
assert(typeof url === 'string');
let dispatcher = obj.dispatcher;
@@ -132,9 +147,12 @@ export function createInternalStream(url, obj = {}) {
headers = new Map(Object.entries(obj.headers));
}
// subtitles don't need special treatment unlike big media files
const service = isSubtitles ? `${obj.service}-subtitles` : obj.service;
internalStreamCache.set(streamID, {
url,
service: obj.service,
service,
headers,
controller,
dispatcher,
@@ -245,6 +263,14 @@ function wrapStream(streamInfo) {
}
} else throw 'invalid urls';
if (streamInfo.subtitles) {
streamInfo.subtitles = createInternalStream(
streamInfo.subtitles,
streamInfo,
/*isSubtitles=*/true
);
}
return streamInfo;
}