Make runners compatible with multi stream output

This commit is contained in:
mrjvs
2023-12-25 00:23:21 +01:00
parent e5989ffbb0
commit b70d9aaaf7
2 changed files with 25 additions and 17 deletions

View File

@@ -50,12 +50,16 @@ export async function scrapeInvidualSource(
media: ops.media,
});
// stream doesn't satisfy the feature flags, so gets removed in output
if (output?.stream && (!isValidStream(output.stream) || !flagsAllowedInFeatures(ops.features, output.stream.flags))) {
output.stream = undefined;
// filter output with only valid streams
if (output?.stream) {
output.stream = output.stream
.filter((stream) => isValidStream(stream))
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
}
if (!output) throw new Error('output is null');
if ((!output.stream || output.stream.length === 0) && output.embeds.length === 0)
throw new NotFoundError('No streams found');
return output;
}
@@ -88,9 +92,10 @@ export async function scrapeIndividualEmbed(
},
});
if (!isValidStream(output.stream)) throw new NotFoundError('stream is incomplete');
if (!flagsAllowedInFeatures(ops.features, output.stream.flags))
throw new NotFoundError("stream doesn't satisfy target feature flags");
output.stream = output.stream
.filter((stream) => isValidStream(stream))
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
if (output.stream.length === 0) throw new NotFoundError('No streams found');
return output;
}

View File

@@ -80,12 +80,14 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
...contextBase,
media: ops.media,
});
if (output?.stream && !isValidStream(output?.stream)) {
throw new NotFoundError('stream is incomplete');
}
if (output?.stream && !flagsAllowedInFeatures(ops.features, output.stream.flags)) {
throw new NotFoundError("stream doesn't satisfy target feature flags");
if (output) {
output.stream = (output.stream ?? [])
.filter((stream) => isValidStream(stream))
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
}
if (!output) throw Error('No output');
if ((!output.stream || output.stream.length === 0) && output.embeds.length === 0)
throw new NotFoundError('No streams found');
} catch (err) {
if (err instanceof NotFoundError) {
ops.events?.update?.({
@@ -107,10 +109,10 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
if (!output) throw new Error('Invalid media type');
// return stream is there are any
if (output.stream) {
if (output.stream?.[0]) {
return {
sourceId: s.id,
stream: output.stream,
stream: output.stream[0],
};
}
@@ -144,9 +146,10 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
...contextBase,
url: e.url,
});
if (!flagsAllowedInFeatures(ops.features, embedOutput.stream.flags)) {
throw new NotFoundError("stream doesn't satisfy target feature flags");
}
embedOutput.stream = embedOutput.stream
.filter((stream) => isValidStream(stream))
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
if (embedOutput.stream.length === 0) throw new NotFoundError('No streams found');
} catch (err) {
if (err instanceof NotFoundError) {
ops.events?.update?.({
@@ -169,7 +172,7 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
return {
sourceId: s.id,
embedId: scraper.id,
stream: embedOutput.stream,
stream: embedOutput.stream[0],
};
}
}