diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json index 1353e26a..1fe42710 100644 --- a/src/assets/locales/en.json +++ b/src/assets/locales/en.json @@ -804,6 +804,8 @@ "previewLabel": "Subtitle preview:", "offChoice": "Off", "onChoice": "On", + "autoSelectChoice": "Auto select", + "autoSelectDifferentChoice": "Tap again to auto select different subtitle", "SourceChoice": "Source Subtitles", "OpenSubtitlesChoice": "External Subtitles", "loadingExternal": "Loading external subtitles...", diff --git a/src/components/player/atoms/settings/CaptionsView.tsx b/src/components/player/atoms/settings/CaptionsView.tsx index fbc8d0f0..366f1931 100644 --- a/src/components/player/atoms/settings/CaptionsView.tsx +++ b/src/components/player/atoms/settings/CaptionsView.tsx @@ -312,8 +312,19 @@ export function CaptionsView({ const { t } = useTranslation(); const router = useOverlayRouter(id); const selectedCaptionId = usePlayerStore((s) => s.caption.selected?.id); - const { disable } = useCaptions(); + const { disable, selectRandomCaptionFromLastUsedLanguage } = useCaptions(); + const [isRandomSelecting, setIsRandomSelecting] = useState(false); const [dragging, setDragging] = useState(false); + + const handleRandomSelect = async () => { + if (isRandomSelecting) return; // Prevent multiple simultaneous calls + setIsRandomSelecting(true); + try { + await selectRandomCaptionFromLastUsedLanguage(); + } finally { + setIsRandomSelecting(false); + } + }; const setCaption = usePlayerStore((s) => s.setCaption); const videoTime = usePlayerStore((s) => s.progress.time); const srtData = usePlayerStore((s) => s.caption.selected?.srtData); @@ -514,6 +525,22 @@ export function CaptionsView({ {t("player.menus.subtitles.offChoice")} + {/* Enable subtitles option */} + handleRandomSelect()} + selected={!!selectedCaptionId} + loading={isRandomSelecting} + > +
+ {t("player.menus.subtitles.autoSelectChoice")} + {selectedCaptionId && ( + + {t("player.menus.subtitles.autoSelectDifferentChoice")} + + )} +
+
+ {/* Custom upload option */} @@ -536,7 +563,7 @@ export function CaptionsView({ {!isLoadingExternalSubtitles && sourceCaptions.length === 0 && externalCaptions.length === 0 && ( -
+
{t("player.menus.subtitles.empty")}
@@ -553,7 +580,7 @@ export function CaptionsView({ )} {/* Language selection */} - {groupedCaptions.length > 0 ? ( + {groupedCaptions.length > 0 && groupedCaptions.map( ({ language, languageName, captions: captionsForLang }) => ( ), - ) - ) : ( -
- {t("player.menus.subtitles.notFound")} -
- )} - - {/* Loading indicator for external subtitles while source exists */} - {isLoadingExternalSubtitles && sourceCaptions.length > 0 && ( -
- {t("player.menus.subtitles.loadingExternal") || - "Loading external subtitles..."} -
- )} + )}