mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 12:43:25 +00:00
check validity of stream before returning
This commit is contained in:
@@ -6,6 +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';
|
||||
|
||||
export type IndividualSourceRunnerOptions = {
|
||||
features: FeatureMap;
|
||||
@@ -50,7 +51,7 @@ export async function scrapeInvidualSource(
|
||||
});
|
||||
|
||||
// stream doesn't satisfy the feature flags, so gets removed in output
|
||||
if (output?.stream && !flagsAllowedInFeatures(ops.features, output.stream.flags)) {
|
||||
if (output?.stream && (!isValidStream(output.stream) || !flagsAllowedInFeatures(ops.features, output.stream.flags))) {
|
||||
output.stream = undefined;
|
||||
}
|
||||
|
||||
@@ -87,7 +88,9 @@ 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");
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@@ -8,6 +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';
|
||||
|
||||
export type RunOutput = {
|
||||
sourceId: string;
|
||||
@@ -79,6 +80,9 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
|
||||
...contextBase,
|
||||
media: ops.media,
|
||||
});
|
||||
if (!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");
|
||||
}
|
||||
|
17
src/utils/valid.ts
Normal file
17
src/utils/valid.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Stream } from '@/providers/streams';
|
||||
|
||||
export function isValidStream(stream: Stream | undefined): boolean {
|
||||
if (!stream) return false;
|
||||
if (stream.type === 'hls') {
|
||||
if (!stream.playlist) return false;
|
||||
return true;
|
||||
}
|
||||
if (stream.type === 'file') {
|
||||
const validQualities = Object.values(stream.qualities).filter((v) => v.url.length > 0);
|
||||
if (validQualities.length === 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// unknown file type
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user