Browse Source

improve most voted algorithm, remove temporary state

Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
pull/497/head
mrjvs 2 years ago
parent
commit
e41d1fdb3f
  1. 12
      src/backend/helpers/subs.ts
  2. 39
      src/components/player/atoms/settings/CaptionsView.tsx
  3. 2
      src/components/player/internals/ContextMenu/Input.tsx
  4. 4
      src/components/player/internals/ContextMenu/Links.tsx

12
src/backend/helpers/subs.ts

@ -82,9 +82,14 @@ export async function searchSubtitles( @@ -82,9 +82,14 @@ export async function searchSubtitles(
});
return Object.values(sortedByLanguage).map((langs) => {
const sortedByRating = langs
.filter((v): v is SubtitleSearchItem => !!v.attributes.legacy_subtitle_id) // must have legacy id
.sort((a, b) => b.attributes.ratings - a.attributes.ratings);
const onlyLegacySubs = langs.filter(
(v): v is SubtitleSearchItem => !!v.attributes.legacy_subtitle_id
);
const sortedByRating = onlyLegacySubs.sort(
(a, b) =>
b.attributes.ratings * (b.attributes.votes ?? 0) -
a.attributes.ratings * (a.attributes.votes ?? 0)
);
return sortedByRating[0];
});
}
@ -95,6 +100,7 @@ export function languageIdToName(langId: string): string | null { @@ -95,6 +100,7 @@ export function languageIdToName(langId: string): string | null {
export async function downloadSrt(legacySubId: string): Promise<string> {
// TODO there is cloudflare protection so this may not always work. what to do about that?
// TODO also there is ratelimit on the page itself
// language code is hardcoded here, it does nothing
const zipFile = await proxiedFetch<ArrayBuffer>(
`https://dl.opensubtitles.org/en/subtitleserve/sub/${legacySubId}`,

39
src/components/player/atoms/settings/CaptionsView.tsx

@ -106,10 +106,6 @@ export function CaptionsView({ id }: { id: string }) { @@ -106,10 +106,6 @@ export function CaptionsView({ id }: { id: string }) {
[download, setCurrentlyDownloading]
);
let downloadProgress: ReactNode = null;
if (downloadReq.loading) downloadProgress = <p>downloading...</p>;
else if (downloadReq.error) downloadProgress = <p>failed to download...</p>;
let content: ReactNode = null;
if (req.loading) content = <p>loading...</p>;
else if (req.error) content = <p>errored!</p>;
@ -153,22 +149,25 @@ export function CaptionsView({ id }: { id: string }) { @@ -153,22 +149,25 @@ export function CaptionsView({ id }: { id: string }) {
return (
<>
<Menu.BackLink
onClick={() => router.navigate("/")}
rightSide={
<button
type="button"
onClick={() => router.navigate("/captions/settings")}
>
Customize
</button>
}
>
Captions
</Menu.BackLink>
<Menu.Section className="pb-6">
<Input value={searchQuery} onInput={setSearchQuery} />
{downloadProgress}
<div>
<Menu.BackLink
onClick={() => router.navigate("/")}
rightSide={
<button
type="button"
onClick={() => router.navigate("/captions/settings")}
>
Customize
</button>
}
>
Captions
</Menu.BackLink>
<div className="mt-3">
<Input value={searchQuery} onInput={setSearchQuery} />
</div>
</div>
<Menu.Section className="!pt-1 mt-2 pb-3">
<CaptionOption onClick={() => disable()} selected={!lang}>
Off
</CaptionOption>

2
src/components/player/internals/ContextMenu/Input.tsx

@ -5,7 +5,7 @@ export function Input(props: { @@ -5,7 +5,7 @@ export function Input(props: {
onInput: (str: string) => void;
}) {
return (
<div className="w-full relative mb-6">
<div className="w-full relative">
<Icon
className="pointer-events-none absolute top-1/2 left-3 transform -translate-y-1/2 text-video-context-inputPlaceholder"
icon={Icons.SEARCH}

4
src/components/player/internals/ContextMenu/Links.tsx

@ -68,7 +68,7 @@ export function Link(props: { @@ -68,7 +68,7 @@ export function Link(props: {
const content = (
<div className={classNames("flex items-center flex-1", props.className)}>
<div className="flex-1 text-left">{props.children}</div>
<div>{props.rightSide}</div>
<div className="flex">{props.rightSide}</div>
</div>
);
@ -134,7 +134,7 @@ export function SelectableLink(props: { @@ -134,7 +134,7 @@ export function SelectableLink(props: {
<Icon className="ml-2" icon={Icons.WARNING} />
</span>
);
if (props.loading) rightContent = <Spinner className="text-xl" />; // should override selected and error
if (props.loading) rightContent = <Spinner className="text-lg" />; // should override selected and error
return (
<Link

Loading…
Cancel
Save