Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Commit

Permalink
fix: Вместо английских названий "Episode 1" будут отображаться русские
Browse files Browse the repository at this point in the history
  • Loading branch information
cawa-93 committed Aug 21, 2021
1 parent 28b9d21 commit 23e2c63
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 70 deletions.
4 changes: 2 additions & 2 deletions packages/renderer/src/components/WatchPage/EpisodesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default defineComponent({
emits: ['update:currentEpisode'],
setup(props, {emit}) {
const allEpisodesMeta = asyncComputed<Map<number, { title: string, filler: boolean, recap: boolean }> | undefined>(() => {
const allEpisodesMeta = asyncComputed<Map<number, { title?: string, filler: boolean, recap: boolean }> | undefined>(() => {
const seriesId = props.seriesId;
return seriesId && props.episodes.length
? Promise.allSettled(props.episodes.map(e => getEpisodeMeta(seriesId, e.number)))
Expand All @@ -57,7 +57,7 @@ export default defineComponent({
accum.set(result.value.episode_id, result.value);
return accum;
}, new Map<number, { title: string, filler: boolean, recap: boolean }>());
}, new Map<number, { title?: string, filler: boolean, recap: boolean }>());
})
: undefined;
},
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/src/utils/videoProvider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function clearVideosCache(providerTranslationId: number): Promise<boolean


export function getEpisodeMeta(malId: number, episodeNumber: number): Promise<{
title: string
title?: string
filler: boolean,
recap: boolean,
episode_id: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ export async function getEpisodes(myAnimeListId: number): Promise<Episode[]> {
return [];
}

// const malEpisodes = await getEpisodesTitles(myAnimeListId);
return resolveEpisodesList(targetSeries, new Map);
return resolveEpisodesList(targetSeries);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Фильтр эпизодов', () => {
for (const {originalSeries, expectedEpisodes} of expectedData) {
it('Фильтр для ' + originalSeries.seriesId, () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const resolved = resolveEpisodesList(originalSeries as any, new Map);
const resolved = resolveEpisodesList(originalSeries as any);
expect(resolved.map((e: { id: number }) => e.id)).toEqual(expectedEpisodes);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type * as sm from '/@/utils/videoProvider/providers/anime365/anime365-interfaces';
import type {Episode} from '/@/utils/videoProvider';
import type {MalEpisode} from '/@/utils/videoProvider/providers/mal/malEpisode';


export function resolveEpisodesList(targetSeries: Pick<sm.Series, 'episodes' | 'type' | 'numberOfEpisodes'>, malEpisodes: Map<number, MalEpisode>): Episode[] {
export function resolveEpisodesList(targetSeries: Pick<sm.Series, 'episodes' | 'type' | 'numberOfEpisodes'>): Episode[] {
const episodes = targetSeries.episodes;
if (!episodes || episodes.length === 0) {
return [];
Expand Down Expand Up @@ -57,20 +56,10 @@ export function resolveEpisodesList(targetSeries: Pick<sm.Series, 'episodes' | '
return accum;
}

const malEpisode = malEpisodes.get(number);
const title = episode.episodeTitle
|| (
malEpisode && !/Episode [0-9]+/.test(malEpisode.title)
? `${number}. ${malEpisode.title}`
: episode.episodeFull
);

accum.push({
id: episode.id,
title,
title: episode.episodeFull,
number,
recap: malEpisode?.recap,
filler: malEpisode?.filler,
});

return accum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ export function getEpisodesMeta(malId: number, episodeNumber: number): Promise<M
}

const targetEpisodeIndex = episodeNumber - (targetPage - 1) * 100 - 1;
return episodes[targetEpisodeIndex];
const targetEpisode = episodes[targetEpisodeIndex];

// Если у загруженного эпизода название в шаблоне "Episode 1"
// Удалить это название будто его вовсе нет.
// Это нужно для того чтобы вместо английских названий "Episode 1" отображалить русские "Серия 1"
if (targetEpisode?.title && /^Episode\.?\s+\d+$/.test(targetEpisode?.title)) {
delete targetEpisode.title;
}

return targetEpisode;
});
}

Expand All @@ -27,52 +36,3 @@ function getEpisodesPaginated(seriesId: number, page = 1): Promise<MalEpisode[]
return undefined;
});
}


// async function getEpisodesTitles(seriesId: number, timeout = SECOND_MS * 3): Promise<Map<number, MalEpisode>> {
// const episodes = new Map<number, MalEpisode>();
//
// const controller = new AbortController();
//
// const timeoutId = setTimeout(() => controller.abort(), timeout);
//
// const firstPage: MalResponse | undefined = await fetch(`https://api.jikan.moe/v3/anime/${seriesId}/episodes/1`, {
// signal: controller.signal,
// })
// .then(r => r.json())
// .catch(e => {
// console.error(e);
// return undefined;
// });
//
// clearTimeout(timeoutId);
//
//
// if (!firstPage?.episodes?.length) {
// return episodes;
// }
//
// firstPage.episodes.forEach(e => episodes.set(e.episode_id, e));
//
// if (firstPage.episodes_last_page && firstPage.episodes_last_page > 1) {
// const promises: Promise<MalResponse>[] = [];
// for (let i = 2; i <= firstPage.episodes_last_page; i++) {
// const controller = new AbortController();
// const timeoutId = setTimeout(() => controller.abort(), timeout);
// promises.push(
// fetch(`https://api.jikan.moe/v3/anime/${seriesId}/episodes/${i}`, {signal: controller.signal})
// .then(r => r.json())
// .finally(() => clearTimeout(timeoutId)),
// );
// }
//
// const responses = await Promise.allSettled(promises);
// responses.forEach(response => {
// if (response.status === 'fulfilled' && response.value.episodes && response.value.episodes.length) {
// response.value.episodes.forEach(e => episodes.set(e.episode_id, e));
// }
// });
// }
//
// return episodes;
// }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface MalEpisode {
episode_id: number
title: string
title?: string
filler: boolean,
recap: boolean,
}
Expand Down

0 comments on commit 23e2c63

Please sign in to comment.