Check if a stream returns a 200

This commit is contained in:
Jorrin
2024-03-31 17:25:07 +02:00
parent 5e49375daf
commit 55f963611c
3 changed files with 72 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ import { EmbedOutput, SourcererOutput } from '@/providers/base';
import { ProviderList } from '@/providers/get';
import { ScrapeContext } from '@/utils/context';
import { NotFoundError } from '@/utils/errors';
import { isValidStream } from '@/utils/valid';
import { isValidStream, validatePlayableStreams } from '@/utils/valid';
export type IndividualSourceRunnerOptions = {
features: FeatureMap;
@@ -68,6 +68,13 @@ export async function scrapeInvidualSource(
if ((!output.stream || output.stream.length === 0) && output.embeds.length === 0)
throw new NotFoundError('No streams found');
// only check for playable streams if there are streams, and if there are no embeds
if (output.stream && output.stream.length > 0 && output.embeds.length === 0) {
const playableStreams = await validatePlayableStreams(output.stream, ops);
if (playableStreams.length === 0) throw new NotFoundError('No playable streams found');
output.stream = playableStreams;
}
return output;
}
@@ -105,5 +112,9 @@ export async function scrapeIndividualEmbed(
.filter((stream) => flagsAllowedInFeatures(ops.features, stream.flags));
if (output.stream.length === 0) throw new NotFoundError('No streams found');
const playableStreams = await validatePlayableStreams(output.stream, ops);
if (playableStreams.length === 0) throw new NotFoundError('No playable streams found');
output.stream = playableStreams;
return output;
}

View File

@@ -8,7 +8,7 @@ import { Stream } from '@/providers/streams';
import { ScrapeContext } from '@/utils/context';
import { NotFoundError } from '@/utils/errors';
import { reorderOnIdList } from '@/utils/list';
import { isValidStream } from '@/utils/valid';
import { isValidStream, validatePlayableStream } from '@/utils/valid';
export type RunOutput = {
sourceId: string;
@@ -104,9 +104,11 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
// return stream is there are any
if (output.stream?.[0]) {
const playableStream = await validatePlayableStream(output.stream[0], ops);
if (!playableStream) throw new NotFoundError('No streams found');
return {
sourceId: source.id,
stream: output.stream[0],
stream: playableStream,
};
}
@@ -161,11 +163,13 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
ops.events?.update?.(updateParams);
continue;
}
const playableStream = await validatePlayableStream(embedOutput.stream[0], ops);
if (!playableStream) throw new NotFoundError('No streams found');
return {
sourceId: source.id,
embedId: scraper.id,
stream: embedOutput.stream[0],
stream: playableStream,
};
}
}