mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
Merge pull request #915 from movie-web/fix/#904
route subtitles through extension if installed
This commit is contained in:
commit
87c6be9a61
1 changed files with 21 additions and 1 deletions
|
@ -5,6 +5,11 @@ import { convertSubtitlesToSrt } from "@/components/player/utils/captions";
|
||||||
import { CaptionListItem } from "@/stores/player/slices/source";
|
import { CaptionListItem } from "@/stores/player/slices/source";
|
||||||
import { SimpleCache } from "@/utils/cache";
|
import { SimpleCache } from "@/utils/cache";
|
||||||
|
|
||||||
|
import {
|
||||||
|
isExtensionActiveCached,
|
||||||
|
sendExtensionRequest,
|
||||||
|
} from "../extension/messaging";
|
||||||
|
|
||||||
export const subtitleTypeList = list().map((type) => `.${type}`);
|
export const subtitleTypeList = list().map((type) => `.${type}`);
|
||||||
const downloadCache = new SimpleCache<string, string>();
|
const downloadCache = new SimpleCache<string, string>();
|
||||||
downloadCache.setCompare((a, b) => a === b);
|
downloadCache.setCompare((a, b) => a === b);
|
||||||
|
@ -21,7 +26,22 @@ export async function downloadCaption(
|
||||||
|
|
||||||
let data: string | undefined;
|
let data: string | undefined;
|
||||||
if (caption.needsProxy) {
|
if (caption.needsProxy) {
|
||||||
data = await proxiedFetch<string>(caption.url, { responseType: "text" });
|
if (isExtensionActiveCached()) {
|
||||||
|
const extensionResponse = await sendExtensionRequest({
|
||||||
|
url: caption.url,
|
||||||
|
method: "GET",
|
||||||
|
});
|
||||||
|
if (
|
||||||
|
!extensionResponse?.success ||
|
||||||
|
typeof extensionResponse.response.body !== "string"
|
||||||
|
) {
|
||||||
|
throw new Error("failed to get caption data from extension");
|
||||||
|
}
|
||||||
|
|
||||||
|
data = extensionResponse.response.body;
|
||||||
|
} else {
|
||||||
|
data = await proxiedFetch<string>(caption.url, { responseType: "text" });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
data = await fetch(caption.url).then((v) => v.text());
|
data = await fetch(caption.url).then((v) => v.text());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue