Added option “functimeout”
This commit is contained in:
parent
b9ab074e1c
commit
e1bd0ec900
1 changed files with 18 additions and 13 deletions
|
@ -140,6 +140,11 @@ for ($i=1; $i<$argc; $i++) {
|
|||
mexit('option «'.$argv[$i].'» requires a time specification as an argument (use «-h» to read help).'.N,1);
|
||||
$i++;
|
||||
$opts['conntimeout']=parsetime($argv[$i]);
|
||||
} elseif ($argv[$i]=='-T' || $argv[$i]=='--functimeout') {
|
||||
if ($i+1>=$argc || parsetime($argv[$i+1])===false)
|
||||
mexit('option «'.$argv[$i].'» requires a time specification as an argument (use «-h» to read help).'.N,1);
|
||||
$i++;
|
||||
$opts['functimeout']=parsetime($argv[$i]);
|
||||
} elseif ($argv[$i]=='-l' || $argv[$i]=='--ldtoots') {
|
||||
if ($i+1>=$argc || preg_match('/^\d+$/',$argv[$i+1])!==1 || $argv[$i+1]+0>40 || $argv[$i+1]+0<10)
|
||||
mexit('option «'.$argv[$i].'» requires a number >= 10 and <= 40 as an argument (use «-h» to read help).'.N,1);
|
||||
|
@ -229,10 +234,10 @@ if ($count>1) {
|
|||
$oidata=null;
|
||||
}
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch nodeinfo specs on https...'.N);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/.well-known/nodeinfo',$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/.well-known/nodeinfo',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($buf['cont']===false) {
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch nodeinfo specs on http...'.N);
|
||||
$buf=@gurl('http://'.$opts['hostname'].'/.well-known/nodeinfo',$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf=@gurl('http://'.$opts['hostname'].'/.well-known/nodeinfo',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
}
|
||||
if ($buf['cont']!==false) {
|
||||
$buf=@json_decode($buf['cont'],true);
|
||||
|
@ -253,7 +258,7 @@ if ($buf['cont']!==false) {
|
|||
$niref=array_shift($nirefs);
|
||||
eecho(1,'«'.$opts['hostname'].'»: got and successfully parsed nodeinfo specs :-)'.N);
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch nodeinfo data...'.N);
|
||||
$buf=@gurl($niref,$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf=@gurl($niref,$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($buf['cont']!==false) {
|
||||
$buf=@json_decode($buf['cont'],true);
|
||||
if (is_array($buf)) {
|
||||
|
@ -298,7 +303,7 @@ if ($buf['cont']!==false) {
|
|||
}
|
||||
if ($idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='4.0.0') {
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch instance info from API v2...'.N);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v2/instance',$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v2/instance',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($buf['cont']!==false) {
|
||||
ckratelimit($buf['headers']);
|
||||
$buf=@json_decode($buf['cont'],true);
|
||||
|
@ -359,7 +364,7 @@ if ($idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='4
|
|||
eecho(2,'«'.$opts['hostname'].'»: could not fetch instance info from API v2: '.$buf['emsg'].'.'.N);
|
||||
}
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch instance extended description from API v1...'.N);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance/extended_description',$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance/extended_description',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($buf['cont']!==false) {
|
||||
ckratelimit($buf['headers']);
|
||||
$buf=@json_decode($buf['cont'],true);
|
||||
|
@ -375,7 +380,7 @@ if ($idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='4
|
|||
eecho(2,'«'.$opts['hostname'].'»: could not fetch instance extended description from API v1: '.$buf['emsg'].'.'.N);
|
||||
}
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch instance domain blocks from API v1...'.N);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance/domain_blocks',$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance/domain_blocks',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($buf['cont']!==false) {
|
||||
ckratelimit($buf['headers']);
|
||||
$buf=@json_decode($buf['cont'],true);
|
||||
|
@ -409,7 +414,7 @@ if ($idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='4
|
|||
}
|
||||
} else {// we still try to fetch instance info from api v1, if ver. < 4.0.0, since it could be a mastodon instance older than 2.1.2, when nodeinfo was introduced
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch instance info from API v1...'.N);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance',$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($buf['cont']!==false) {
|
||||
ckratelimit($buf['headers']);
|
||||
$buf=@json_decode($buf['cont'],true);
|
||||
|
@ -487,7 +492,7 @@ if ($idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='4
|
|||
|
||||
if ($idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='2.1.2') {
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch instance activity info from API v1...'.N);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance/activity',$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/instance/activity',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($buf['cont']!==false) {
|
||||
ckratelimit($buf['headers']);
|
||||
$buf=@json_decode($buf['cont'],true);
|
||||
|
@ -506,7 +511,7 @@ if ($idata['IsMastodon'] && !is_null($idata['Version']) && $idata['Version']>='3
|
|||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch instance tags trends info from API v1...'.N);
|
||||
$url='https://'.$opts['hostname'].'/api/v1/trends';
|
||||
if ($idata['Version']>='3.5.0') $url.='/tags';
|
||||
$buf=@gurl($url,$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf=@gurl($url,$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($buf['cont']!==false) {
|
||||
ckratelimit($buf['headers']);
|
||||
$buf=@json_decode($buf['cont'],true);
|
||||
|
@ -761,7 +766,7 @@ if ($instanswered && $opts['fetchusers'] && $idata['IsMastodon'] && !is_null($id
|
|||
$offset=$chunk*$limit;
|
||||
for ($att=0; $att<$opts['udiratts']; $att++) {
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch chunk '.($chunk+1).' of users info from directory API (attempt '.($att+1).'/'.$opts['udiratts'].')...'.N);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/directory?local=1&order=new&limit='.$limit.'&offset='.$offset,$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf=@gurl('https://'.$opts['hostname'].'/api/v1/directory?local=1&order=new&limit='.$limit.'&offset='.$offset,$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($buf['cont']!==false) {
|
||||
$xrlr=ckratelimit($buf['headers']);
|
||||
eecho(1,'«'.$opts['hostname'].'»: got chunk '.($chunk+1).' of users info from directory API on attempt '.($att+1).'/'.$opts['udiratts'].' (xrlr: '.$xrlr.') :-)'.N);
|
||||
|
@ -783,7 +788,7 @@ if ($instanswered && $opts['fetchusers'] && $idata['IsMastodon'] && !is_null($id
|
|||
/*if (!isset($user['noindex'])) {
|
||||
$user['noindex']=true;
|
||||
eecho(0,'«'.$opts['hostname'].'»: «'.$user['username'].'»: «noindex» is undefined, trying to define it by fetching user’s profile page...'.N);
|
||||
$page=gurl($user['url'],$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$page=gurl($user['url'],$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
// here ckratelimit is not needed because it's a normal web page, not json from mastodon api
|
||||
if ($page['cont']!==false) {
|
||||
//<meta content='noindex, noarchive' name='robots'>
|
||||
|
@ -804,7 +809,7 @@ if ($instanswered && $opts['fetchusers'] && $idata['IsMastodon'] && !is_null($id
|
|||
/*$user['tags']=[];
|
||||
if (!$user['noindex'] && !is_null($idata['Version']) && $idata['Version']>='3.3.0') {
|
||||
eecho(0,'«'.$opts['hostname'].'»: trying to fetch tags for user «'.$user['username'].'»...'.N);
|
||||
$tags=@gurl('https://'.$opts['hostname'].'/api/v1/accounts/'.$user['id'].'/featured_tags',$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$tags=@gurl('https://'.$opts['hostname'].'/api/v1/accounts/'.$user['id'].'/featured_tags',$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($tags['cont']!==false) {
|
||||
ckratelimit($tags['headers']);
|
||||
$tags=@json_decode($tags['cont'],true);
|
||||
|
@ -1093,7 +1098,7 @@ function ckratelimit($httpresphead) {
|
|||
*/
|
||||
function get_api($host, $path) {
|
||||
global $opts;
|
||||
$buf = @gurl('https://'.$host.$path,$opts['conntimeout'],$conn['functimeout'],['Accept: application/json']);
|
||||
$buf = @gurl('https://'.$host.$path,$opts['conntimeout'],$opts['functimeout'],['Accept: application/json']);
|
||||
if ($buf['cont']!==false) {
|
||||
ckratelimit($buf['headers']);
|
||||
$data = json_decode($buf['cont'], true);
|
||||
|
|
Loading…
Reference in a new issue