|
9 | 9 | IPagination, |
10 | 10 | IPopularOngoingUpdate, |
11 | 11 | IRecentRelease, |
12 | | - IUrlParamsType |
| 12 | + IUrlParamsType, |
| 13 | + IAnime |
13 | 14 | } from './types'; |
14 | 15 | import { getIdFromPath } from './utils'; |
15 | 16 |
|
@@ -451,6 +452,99 @@ class GoGoAnime { |
451 | 452 | return animes; |
452 | 453 | } |
453 | 454 |
|
| 455 | + async animeInfo( |
| 456 | + id: string, |
| 457 | + axiosConfig?: AxiosRequestConfig |
| 458 | + ): Promise<IAnime> { |
| 459 | + const link = this.getUrlWithBase(`/category/${id}`); |
| 460 | + const res = await axios.get(link, axiosConfig); |
| 461 | + const $ = cheerioLoad(res.data); |
| 462 | + |
| 463 | + const animeInfoBody = $('.anime_info_body'); |
| 464 | + const animeInfoBodyBg = animeInfoBody.children('.anime_info_body_bg'); |
| 465 | + |
| 466 | + const movieId = |
| 467 | + $('input#movie_id.movie_id[type="hidden"]').attr('value') ?? ''; |
| 468 | + const thumbnail = animeInfoBodyBg.children('img').attr('src') ?? ''; |
| 469 | + const title = animeInfoBodyBg.children('h1').text().trim(); |
| 470 | + |
| 471 | + const info: IAnime = { |
| 472 | + id, |
| 473 | + link, |
| 474 | + title, |
| 475 | + thumbnail, |
| 476 | + movieId, |
| 477 | + genres: [], |
| 478 | + episodeCount: 0, |
| 479 | + episodePages: [] |
| 480 | + }; |
| 481 | + |
| 482 | + animeInfoBodyBg.children('p.type').each((_, ele) => { |
| 483 | + const p = $(ele); |
| 484 | + |
| 485 | + const type = p |
| 486 | + .children('span') |
| 487 | + .text() |
| 488 | + .replace(':', '') |
| 489 | + .trim() |
| 490 | + .toLowerCase(); |
| 491 | + |
| 492 | + const text = p.text().slice(`${type}:`.length).trim(); |
| 493 | + |
| 494 | + if (type === 'type') { |
| 495 | + info.type = text; |
| 496 | + return; |
| 497 | + } |
| 498 | + |
| 499 | + if (type === 'plot summary') { |
| 500 | + info.summary = text; |
| 501 | + return; |
| 502 | + } |
| 503 | + |
| 504 | + if (type === 'genre') { |
| 505 | + p.children('a').each((_, _ele) => { |
| 506 | + info.genres.push(this._getEntityFromA($(_ele))); |
| 507 | + }); |
| 508 | + return; |
| 509 | + } |
| 510 | + |
| 511 | + if (type === 'status') { |
| 512 | + info.status = text; |
| 513 | + return; |
| 514 | + } |
| 515 | + |
| 516 | + if (type === 'released') { |
| 517 | + info.released = text; |
| 518 | + return; |
| 519 | + } |
| 520 | + |
| 521 | + if (type === 'other name') { |
| 522 | + info.otherNames = text |
| 523 | + .split(', ') |
| 524 | + .map(t => t.trim()) |
| 525 | + .filter(t => t !== ''); |
| 526 | + return; |
| 527 | + } |
| 528 | + }); |
| 529 | + |
| 530 | + $('.anime_video_body ul#episode_page li').each((_, ele) => { |
| 531 | + const a = $(ele).children('a'); |
| 532 | + |
| 533 | + const start = Number(a.attr('ep_start')); |
| 534 | + const end = Number(a.attr('ep_end')); |
| 535 | + |
| 536 | + info.episodePages.push({ start, end }); |
| 537 | + }); |
| 538 | + |
| 539 | + info.episodePages.forEach(d => { |
| 540 | + if (d.end > info.episodeCount) { |
| 541 | + info.episodeCount = d.end; |
| 542 | + } |
| 543 | + }); |
| 544 | + |
| 545 | + return info; |
| 546 | + } |
| 547 | + |
454 | 548 | getUrlWithBase(path: string, params?: IUrlParamsType) { |
455 | 549 | return this.getUrl(this.baseUrl, path, params); |
456 | 550 | } |
|
0 commit comments