···8282 });
83838484 return Object.values(sortedByLanguage).map((langs) => {
8585- const sortedByRating = langs
8686- .filter((v): v is SubtitleSearchItem => !!v.attributes.legacy_subtitle_id) // must have legacy id
8787- .sort((a, b) => b.attributes.ratings - a.attributes.ratings);
8585+ const onlyLegacySubs = langs.filter(
8686+ (v): v is SubtitleSearchItem => !!v.attributes.legacy_subtitle_id
8787+ );
8888+ const sortedByRating = onlyLegacySubs.sort(
8989+ (a, b) =>
9090+ b.attributes.ratings * (b.attributes.votes ?? 0) -
9191+ a.attributes.ratings * (a.attributes.votes ?? 0)
9292+ );
8893 return sortedByRating[0];
8994 });
9095}
···9510096101export async function downloadSrt(legacySubId: string): Promise<string> {
97102 // TODO there is cloudflare protection so this may not always work. what to do about that?
103103+ // TODO also there is ratelimit on the page itself
98104 // language code is hardcoded here, it does nothing
99105 const zipFile = await proxiedFetch<ArrayBuffer>(
100106 `https://dl.opensubtitles.org/en/subtitleserve/sub/${legacySubId}`,