Skip to content

Commit

Permalink
fixed no episodes bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Toasty360 committed Nov 2, 2024
1 parent 853f1e8 commit 51f558f
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 117 deletions.
115 changes: 60 additions & 55 deletions dist/providers/meta/anilist.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/providers/meta/anilist.js.map

Large diffs are not rendered by default.

125 changes: 64 additions & 61 deletions src/providers/meta/anilist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,77 +934,80 @@ class Anilist extends AnimeParser {
season?: string,
startDate?: number
) => {
const kitsuEpisodes = await this.client.post(this.kitsuGraphqlUrl, options);
const episodesList = new Map();
if (kitsuEpisodes?.data.data) {
const { nodes } = kitsuEpisodes.data.data.searchAnimeByTitle;

if (nodes) {
nodes.forEach((node: any) => {
if (node.season === season && node.startDate.trim().split('-')[0] === startDate?.toString()) {
const episodes = node.episodes.nodes;

for (const episode of episodes) {
const i = episode?.number.toString().replace(/"/g, '');

let name = undefined;
let description = undefined;
let thumbnail = undefined;

let thumbnailHash = undefined;

if (episode?.description?.en)
description = episode?.description.en.toString().replace(/"/g, '').replace('\\n', '\n');
if (episode?.thumbnail) {
thumbnail = episode?.thumbnail.original.url.toString().replace(/"/g, '');
thumbnailHash = getHashFromImage(
episode?.thumbnail.original.url.toString().replace(/"/g, '')
);
}
try {
const kitsuEpisodes = await this.client.post(this.kitsuGraphqlUrl, options);
const episodesList = new Map();
if (kitsuEpisodes?.data.data) {
const { nodes } = kitsuEpisodes.data.data.searchAnimeByTitle;

if (nodes) {
nodes.forEach((node: any) => {
if (node.season === season && node.startDate.trim().split('-')[0] === startDate?.toString()) {
const episodes = node.episodes.nodes;

for (const episode of episodes) {
const i = episode?.number.toString().replace(/"/g, '');

let name = undefined;
let description = undefined;
let thumbnail = undefined;

let thumbnailHash = undefined;

if (episode?.description?.en)
description = episode?.description.en.toString().replace(/"/g, '').replace('\\n', '\n');
if (episode?.thumbnail) {
thumbnail = episode?.thumbnail.original.url.toString().replace(/"/g, '');
thumbnailHash = getHashFromImage(
episode?.thumbnail.original.url.toString().replace(/"/g, '')
);
}

if (episode) {
if (episode.titles?.canonical) name = episode.titles.canonical.toString().replace(/"/g, '');
if (episode) {
if (episode.titles?.canonical) name = episode.titles.canonical.toString().replace(/"/g, '');
episodesList.set(i, {
episodeNum: episode?.number.toString().replace(/"/g, ''),
title: name,
description,
createdAt: episode?.createdAt,
thumbnail,
});
continue;
}
episodesList.set(i, {
episodeNum: episode?.number.toString().replace(/"/g, ''),
title: name,
description,
createdAt: episode?.createdAt,
episodeNum: undefined,
title: undefined,
description: undefined,
createdAt: undefined,
thumbnail,
thumbnailHash,
});
continue;
}
episodesList.set(i, {
episodeNum: undefined,
title: undefined,
description: undefined,
createdAt: undefined,
thumbnail,
thumbnailHash,
});
}
}
});
});
}
}
}

const newEpisodeList: IAnimeEpisode[] = [];
if (possibleProviderEpisodes?.length !== 0) {
possibleProviderEpisodes?.forEach((ep: any, i: any) => {
const j = (i + 1).toString();
newEpisodeList.push({
id: ep.id as string,
title: ep.title ?? episodesList.get(j)?.title ?? null,
image: ep.image ?? episodesList.get(j)?.thumbnail ?? null,
imageHash: getHashFromImage(ep.image ?? episodesList.get(j)?.thumbnail ?? null),
number: ep.number as number,
createdAt: ep.createdAt ?? episodesList.get(j)?.createdAt ?? null,
description: ep.description ?? episodesList.get(j)?.description ?? null,
url: (ep.url as string) ?? null,
const newEpisodeList: IAnimeEpisode[] = [];
if (possibleProviderEpisodes?.length !== 0) {
possibleProviderEpisodes?.forEach((ep: any, i: any) => {
const j = (i + 1).toString();
newEpisodeList.push({
id: ep.id as string,
title: ep.title ?? episodesList.get(j)?.title ?? null,
image: ep.image ?? episodesList.get(j)?.thumbnail ?? null,
imageHash: getHashFromImage(ep.image ?? episodesList.get(j)?.thumbnail ?? null),
number: ep.number as number,
createdAt: ep.createdAt ?? episodesList.get(j)?.createdAt ?? null,
description: ep.description ?? episodesList.get(j)?.description ?? null,
url: (ep.url as string) ?? null,
});
});
});
}
return newEpisodeList;
} catch (error) {
return possibleProviderEpisodes;
}

return newEpisodeList;
};

/**
Expand Down

0 comments on commit 51f558f

Please sign in to comment.