mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-30 23:11:52 +01:00
handle errors for domain extraction
This commit is contained in:
parent
7a5a9fe6fb
commit
2064e42bcb
@ -2,21 +2,23 @@ import { Stream } from "@movie-web/providers";
|
|||||||
|
|
||||||
import { setDomainRule } from "@/backend/extension/messaging";
|
import { setDomainRule } from "@/backend/extension/messaging";
|
||||||
|
|
||||||
function extractDomain(url: string): string {
|
function extractDomain(url: string): string | null {
|
||||||
try {
|
try {
|
||||||
const u = new URL(url);
|
const u = new URL(url);
|
||||||
return u.hostname;
|
return u.hostname;
|
||||||
} catch {
|
} catch {
|
||||||
return url;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractDomainsFromStream(stream: Stream): string[] {
|
function extractDomainsFromStream(stream: Stream): string[] {
|
||||||
if (stream.type === "hls") {
|
if (stream.type === "hls") {
|
||||||
return [extractDomain(stream.playlist)];
|
return [extractDomain(stream.playlist)].filter((v): v is string => !!v);
|
||||||
}
|
}
|
||||||
if (stream.type === "file") {
|
if (stream.type === "file") {
|
||||||
return Object.values(stream.qualities).map((v) => extractDomain(v.url));
|
return Object.values(stream.qualities)
|
||||||
|
.map((v) => extractDomain(v.url))
|
||||||
|
.filter((v): v is string => !!v);
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user