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

View File

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