Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Bump the cooldown to 3 seconds and implement 1s cooldown for md5 checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklul committed Apr 1, 2020
1 parent 291fa8f commit 68fb4e6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ private function main()

if (isset($results['error']) && $results['error'] === 'ShortLimitReached') {
$results = $this->applyCooldown(
1,
3,
$results,
function () use ($entry) {
return $this->reverseSearch($this->PATH_IMAGES . '/' . $entry);
Expand Down Expand Up @@ -1038,10 +1038,11 @@ function () {
* @param string $tags
* @param int $page
* @param int $limit
* @param bool $retry
*
* @return string|bool
*/
private function apiRequest($tags, $page = 1, $limit = 1)
private function apiRequest($tags, $page = 1, $limit = 1, $retry = true)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://e621.net/posts.json?limit=' . $limit . '&page=' . $page . '&tags=' . $tags);
Expand All @@ -1064,6 +1065,15 @@ private function apiRequest($tags, $page = 1, $limit = 1)
$this->printout("\n" . $output . "\n");
}

if ($retry) {
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code === 429) {
sleep(1);

return $this->apiRequest($tags, $page, $limit, false);
}
}

return $output;
}

Expand Down

0 comments on commit 68fb4e6

Please # to comment.