Skip to content

Commit

Permalink
Make addKey.php work fine for quota exhausted keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Loison committed Jun 29, 2023
1 parent 58ff841 commit af6c393
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion addKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'ignore_errors' => true,
]
];
$content = getJSON("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=mWdFMNQBcjs&key=$key", $httpOptions);
$content = getJSON("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=mWdFMNQBcjs&key=$key", $httpOptions, false);
// The force secret is used to store the YouTube Data API v3 even if it's not having quota, as we assume that the trusted instance that send it to this one has checked that it has quota.
if ($content['items'][0]['snippet']['title'] === 'A public video' || (isset($_GET['forceSecret']) && $_GET['forceSecret'] === ADD_KEY_FORCE_SECRET)) {
file_put_contents(KEYS_FILE, ($keysContent === '' || $keysContent === false ? '' : "\n") . $key, FILE_APPEND);
Expand Down
8 changes: 4 additions & 4 deletions common.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ function isRedirection($url)
return $code == 303;
}

function getRemote($url, $opts = [])
function getRemote($url, $opts = [], $verifyTrafficIfForbidden = true)
{
[$result, $headers] = fileGetContentsAndHeadersFromOpts($url, $opts);
foreach (HTTP_CODES_DETECTED_AS_SENDING_UNUSUAL_TRAFFIC as $HTTP_CODE_DETECTED_AS_SENDING_UNUSUAL_TRAFFIC) {
if (str_contains($headers[0], strval($HTTP_CODE_DETECTED_AS_SENDING_UNUSUAL_TRAFFIC))) {
if (str_contains($headers[0], strval($HTTP_CODE_DETECTED_AS_SENDING_UNUSUAL_TRAFFIC)) && ($HTTP_CODE_DETECTED_AS_SENDING_UNUSUAL_TRAFFIC != 403 || $verifyTrafficIfForbidden)) {
detectedAsSendingUnusualTraffic();
}
}
Expand All @@ -112,9 +112,9 @@ function detectedAsSendingUnusualTraffic()
dieWithJsonMessage('YouTube has detected unusual traffic from this YouTube operational API instance. Please try your request again later or see alternatives at https://github.com/Benjamin-Loison/YouTube-operational-API/issues/11');
}

function getJSON($url, $opts = [])
function getJSON($url, $opts = [], $verifyTrafficIfForbidden = true)
{
return json_decode(getRemote($url, $opts), true);
return json_decode(getRemote($url, $opts, $verifyTrafficIfForbidden), true);
}

function getJSONStringFromHTMLScriptPrefix($html, $scriptPrefix)
Expand Down

0 comments on commit af6c393

Please sign in to comment.