mirror of
https://github.com/p-stream/p-stream.git
synced 2026-04-11 23:50:22 +00:00
attempt to fix subtitle download
This commit is contained in:
parent
9dc2e0099b
commit
30c80053b6
1 changed files with 26 additions and 6 deletions
|
|
@ -8,7 +8,7 @@ import { OptionItem } from "@/components/form/Dropdown";
|
|||
import { Icon, Icons } from "@/components/Icon";
|
||||
import { OverlayPage } from "@/components/overlays/OverlayPage";
|
||||
import { Menu } from "@/components/player/internals/ContextMenu";
|
||||
import { convertSubtitlesToSrtDataurl } from "@/components/player/utils/captions";
|
||||
import { convertSubtitlesToSrt } from "@/components/player/utils/captions";
|
||||
import { Transition } from "@/components/utils/Transition";
|
||||
import { useOverlayRouter } from "@/hooks/useOverlayRouter";
|
||||
import { usePlayerStore } from "@/stores/player/store";
|
||||
|
|
@ -125,11 +125,31 @@ export function DownloadView({ id }: { id: string }) {
|
|||
const sourceType = usePlayerStore((s) => s.source?.type);
|
||||
const selectedCaption = usePlayerStore((s) => s.caption?.selected);
|
||||
const openSubtitleDownload = useCallback(() => {
|
||||
const dataUrl = selectedCaption
|
||||
? convertSubtitlesToSrtDataurl(selectedCaption?.srtData)
|
||||
: null;
|
||||
if (!dataUrl) return;
|
||||
window.open(dataUrl);
|
||||
if (!selectedCaption?.srtData) return;
|
||||
|
||||
try {
|
||||
// Convert subtitles to SRT format
|
||||
const srtContent = convertSubtitlesToSrt(selectedCaption.srtData);
|
||||
|
||||
// Create a Blob with the SRT content
|
||||
const blob = new Blob([srtContent], { type: "application/x-subrip" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
// Create an anchor element for downloading
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "subtitles.srt";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Clean up
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
console.error("Error downloading subtitles:", error);
|
||||
}
|
||||
}, [selectedCaption]);
|
||||
|
||||
const playerOptions = useMemo(
|
||||
|
|
|
|||
Loading…
Reference in a new issue