mal_id = $id; $jikan = new Malclient; try { $animeInfo = $jikan->getAnime( (new \Jikan\Request\Anime\AnimeRequest( $this->mal_id )) ); } catch (\Exception $e) { echo "Problem requesting AnimeInfo for (" . $this->mal_id . ") continue\n"; echo $e->getMessage(); echo "\n\n"; return; } if ( $skip_if_unpopular && 10000 > $animeInfo->getMembers() ) { echo "Anime (" . $this->mal_id . ") has only " . $animeInfo->getMembers() . " Members. Not worth to keep. Skipping\n"; return; } /* if ( strtolower("not yet aired") == strtolower($animeInfo->getStatus()) ) { echo "Anime (" . $this->mal_id . ") has not aired yet. Skipping\n"; return; } */ $this->url = $animeInfo->GetUrl(); $this->image_url = $animeInfo->getImages()->getJpg()->getImageUrl(); $this->title_eng = $animeInfo->getTitleEnglish(); $this->title_rom = $animeInfo->getTitle(); $this->title_nat = $animeInfo->getTitleJapanese(); $this->title_pref = $animeInfo->getTitle(); $this->anime_type = $animeInfo->getType(); $this->broadcasted = $animeInfo->getBroadcast(); $this->episodes = $animeInfo->getEpisodes(); $this->airing_status = getAiringStatusCode($animeInfo->getStatus()); if ( is_null($animeInfo->getPremiered()) ) { if ( env('ANIME_NOT_YET_AIRED') != $this->airing_status ) { $tmp_date = getSeasonFromDate( $animeInfo->getAired()->getFrom() ); $this->season_name = $tmp_date["name"]; $this->season_year = $tmp_date["year"]; } } else { $this->season_name = explode(" ", $animeInfo->getPremiered())[0]; $this->season_year = explode(" ", $animeInfo->getPremiered())[1]; } } public function getStats() { return $this->hasMany('App\AnimeStats', 'mal_id', 'mal_id'); } public function getAiring() { return $this->hasMany('App\Airing', 'mal_id', 'mal_id'); } public function user() { return $this->belongsToMany('App\MALUser', 'is_watching', 'mal_id', 'user_id') ->as('anime') ->withPivot('episodes_watched', 'score_user') ->withTimestamps(); } public function getDataFromAnilist() { $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" => $this->mal_id, ]; // Make the HTTP Api request try { $http = new \GuzzleHttp\Client; $response = $http->post('https://graphql.anilist.co', [ 'json' => [ 'query' => $query, 'variables' => $variables, ] ]); $data = json_decode( $response->getBody() )->data->Media; } catch (\Exception $e) { echo "getDataFromAnilist: Problem with Guzzle connecting to Anilist on anime: (" . $this->mal_id . ")\n"; return ""; } return $data; } public function getEnhancementFromAnilist() { $query = ' query($id: Int!) { Media(idMal: $id, type: ANIME) { title { userPreferred } description hashtag duration } } '; $variables = [ "id" => $this->mal_id, ]; // Make the HTTP Api request try { $http = new \GuzzleHttp\Client; $response = $http->post('https://graphql.anilist.co', [ 'json' => [ 'query' => $query, 'variables' => $variables, ] ]); $data = json_decode( $response->getBody() )->data->Media; $rate_limit = $response->getHeader("X-RateLimit-Remaining")[0]; echo "Try Block: Rate Limit: " . $rate_limit . "\n"; Log::info("getEnhancementFromAnilist: Try Block: Rate Limit: " . $rate_limit . "\n"); if ( $rate_limit <= 10 ) { echo " sleep 5 seconds\n\n"; sleep(5); } } catch (\Exception $e) { echo "getEnhancementFromAnilist: Problem with Guzzle connecting to Anilist on anime: (" . $this->mal_id . ")\n"; echo $e->getMessage(); echo "\n"; return ""; } echo "got enhancement for anime " . $this->mal_id . "\n\n"; Log::info("got enhancement for anime " . $this->mal_id . "\n"); return $data; } }