parse( $username ); } } public function parse( $username ) { $this->jikan = new MalClient; $this->animeList = $this->jikan->getUserAnimelist( new \Jikan\Request\User\UserAnimeListRequest( $username, 1, 1 ) ); foreach ( $this->animeList as $entry ) { // currently watching if ( $this::STATUS_WATCHING != $entry->getAiringStatus() ){ continue; } $data = $this->getDataFromAnilist( $entry->getMalID() ); // check if anilist has no info about airing next episode (this happens!) if ( is_null( $data->nextAiringEpisode ) ) { continue; } $animeInfo = $this->jikan->getAnime( (new \Jikan\Request\Anime\AnimeRequest( $entry->getMalID() )) ); $anime = new AnimeWatching( $entry->getMalID(), false ); $anime->url = $entry->getUrl(); $anime->title_eng = $data->title->english; $anime->title_rom = $data->title->romaji; $anime->title_nat = $data->title->native; $anime->title_pref = $data->title->userPreferred; $anime->airing_at = Carbon::createFromTimestamp($data->nextAiringEpisode->airingAt); $anime->time_until_airing = Carbon::createFromTimestamp($data->nextAiringEpisode->timeUntilAiring); $anime->episode = $data->nextAiringEpisode->episode; $anime->duration = $data->duration; $anime->episodes_complete = $data->episodes; $anime->episodes_watched = $entry->getWatchedEpisodes(); $anime->score_user = $entry->getScore(); $anime->score = $animeInfo->getScore(); $anime->rank = $animeInfo->getRank(); $anime->popularity = $animeInfo->getPopularity(); $this->animeSchedule[] = $anime; } } public function getSchedule() { return $this->animeSchedule; } public function getCalendar() { $vCalendar = new Calendar('animes.iamfabulous.de'); $vCalendar->setName('Anime Schedule'); foreach ( $this->animeSchedule as $anime ) { $vEvent = new Event(); $vEvent ->setDtStart(new \DateTime($anime->airing_at)) ->setDtEnd( new \DateTime($anime->airing_at->add($anime->duration, 'minutes')) ) ->setNoTime(false) ->setSummary( $anime->title_pref . " (" . $anime->episode . "/" . $anime->episodes_complete . ")" ) ->setUrl( env("APP_URL") ) ->setDescription( "(Episode " . $anime->episode . "/" . $anime->episodes_complete . ") You have watched " . $anime->episodes_watched . " episodes of " . $anime->title_pref . " and scored it with " . $anime->score_user . ". (Public score: ". $anime->score .")\n\n" . $anime->url ); $vCalendar->addComponent($vEvent); } return $vCalendar->render(); } private function getDataFromAnilist( $malID ) { $query = ' query($id: Int!) { Media(idMal: $id, type: ANIME) { title { romaji english native userPreferred } nextAiringEpisode { airingAt timeUntilAiring episode } episodes duration } } '; // Define our query variables and values that will be used in the query request $variables = [ "id" => $malID, ]; // Make the HTTP Api request $http = new \GuzzleHttp\Client; $response = $http->post('https://graphql.anilist.co', [ 'json' => [ 'query' => $query, 'variables' => $variables, ] ]); $data = json_decode( $response->getBody() )->data->Media; return $data; } protected function getIsWatching( $username ) { $animeList = $this->getUserAnimeList( $username ); $anime = array(); foreach ( $animeList as $entry ) { // currently watching if ( $this::STATUS_WATCHING != $entry->getAiringStatus() ){ continue; } $anime[] = array( "mal_id" => $entry->getMalID(), "episodes_watched" => $entry->getWatchedEpisodes(), "score_user" => $entry->getScore(), ); } return $anime; } protected function getUserAnimeList( $username ) { $jikan = new MalClient; $animeList = $jikan->getUserAnimelist( new \Jikan\Request\User\UserAnimeListRequest( $username, 1, 1 ) ); return $animeList; } public function test() { echo "
";
var_dump( $this->getIsWatching('ll-') );
}
}