jikan-me / jikan

Unofficial MyAnimeList PHP+REST API which provides functions other than the official API
https://jikan.moe
MIT License
875 stars 93 forks source link

Add anime videos episodes #452

Closed irfan-dahir closed 2 years ago

irfan-dahir commented 2 years ago

A much-requested feature. Issue ref #445

Currently, anime videos return anime episodes and promo videos.

However, anime videos allow pagination on MAL. And this page specifically returns video thumbnails from Crunchyroll. With the way AnimeVideos works, it returns only the first listing of anime episodes, trailers, and even Music Videos (which is currently not parsed by Jikan - PR as of #453 ).

Any sort of results-based model with pagination requires a different implementation so what I've done here is created a completely new request instead which can be called on by the REST API as a sub endpoint.


Usage

$jikan = new \Jikan\MyAnimeList\MalClient();

$data = $jikan->getAnimeVideosEpisodes(
    new \Jikan\Request\Anime\AnimeVideosEpisodesRequest(21, 4) // mal_id, page
);

var_dump($data->getResults(), $data->getLastVisiblePage(), $data->hasNextPage());

Notes on REST API implementation

We won't be able to fit in the updated code here: GET /v4/anime/21/videos as an associative array is returned for episode listing. We need the parser to return a results-based model in order to handle the pagination on the REST API as well. So instead we'll implement this with all its pagination glory as a new REST API endpoint GET /v4/anime/21/videos/episodes