Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(gogoanime): Anime List #466

Merged
merged 6 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions dist/extractors/rapidcloud.js

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

4 changes: 2 additions & 2 deletions dist/extractors/vidcloud.js

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

3 changes: 1 addition & 2 deletions dist/extractors/vidcloud.js.map

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

1 change: 1 addition & 0 deletions dist/providers/anime/gogoanime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ declare class Gogoanime extends AnimeParser {
id: string | undefined;
title: string | undefined;
}[]>;
fetchAnimeList: (page?: number) => Promise<ISearch<IAnimeResult>>;
}
export default Gogoanime;
38 changes: 38 additions & 0 deletions dist/providers/anime/gogoanime.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/anime/gogoanime.js.map

Large diffs are not rendered by default.

40 changes: 38 additions & 2 deletions src/providers/anime/gogoanime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@
const alias = $('#alias_anime').attr('value');

const html = await this.client.get(
`${
this.ajaxUrl
`${this.ajaxUrl
}/load-list-episode?ep_start=${ep_start}&ep_end=${ep_end}&id=${movie_id}&default_ep=${0}&alias=${alias}`
);
const $$ = load(html.data);
Expand Down Expand Up @@ -475,6 +474,43 @@
throw new Error('Something went wrong. Please try again later.');
}
};

fetchAnimeList = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
const animeList: IAnimeResult[] = [];
let res = null;
try {
res = await this.client.get(`${this.baseUrl}/anime-list.html?page=${page}`);
} catch (err) {
try {
res = await this.client.get(`${this.baseUrl}/`);
} catch (error) {
throw new Error('Something went wrong. Please try again later.');
}
}
try {
const $ = load(res.data);
$('.anime_list_body .listing li').each((_index, element) => {
const img = $('div', $(element).attr('title')!);
const a = $(element).find('a');
animeList.push(
{
id: a.attr('href')?.replace(`/category/`, '')!,

Check warning on line 497 in src/providers/anime/gogoanime.ts

View check run for this annotation

codefactor.io / CodeFactor

src/providers/anime/gogoanime.ts#L497

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong. (@typescript-eslint/no-non-null-asserted-optional-chain)
title: a.text(),
image: $(img).find('img').attr('src'),
url: `${this.baseUrl}${a.attr('href')}`,
}
);
});
const hasNextPage = !$('div.anime_name.anime_list > div > div > ul > li').last().hasClass('selected');
return {
currentPage: page,
hasNextPage: hasNextPage,
results: animeList,
};
} catch (err) {
throw new Error('Something went wrong. Please try again later.');
}
};
}

// (async () => {
Expand Down
5 changes: 5 additions & 0 deletions test/anime/gogoanime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ test('returns a filled array of available genres', async () => {
expect(data).not.toEqual([]);
});

test('returns a filled array of anime list', async () => {
const data = await gogoanime.fetchAnimeList();
expect(data).not.toEqual([]);
});

test('returns a filled array of recent episodes', async () => {
const data = await gogoanime.fetchRecentEpisodes();
expect(data).not.toEqual([]);
Expand Down