Skip to content

Commit 67881b6

Browse files
committedFeb 13, 2021
optimize regex for detecting nodes
1 parent cc25ef2 commit 67881b6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed
 

‎actions/update-nodes.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
$promise->then(function ($resp) use ($guzzle, &$nodes, $listinfoUrl, &$deadProviders, &$totalAdded){
3030
$html = $resp->getBody();
3131
println('Hit ' . $listinfoUrl);
32-
preg_match_all('/href="listinfo\/(.*?)"/', $html, $m);
33-
if (empty($m[1])) {
32+
preg_match_all('/href="(\.\.\/)*listinfo\/(.*?)"/', $html, $m);
33+
if (empty($m[2])) {
3434
if (PRESERVE_EMPTY_PROVIDERS) {
3535
println('Provider ' . $listinfoUrl . ' returned an empty list. Preserved according to config.');
3636
} else {
@@ -40,7 +40,7 @@
4040
}
4141
return;
4242
}
43-
$testUrl = substr($listinfoUrl, 0, strlen($listinfoUrl) - 8) . 'subscribe/' . $m[1][0] . '?language=en';
43+
$testUrl = substr($listinfoUrl, 0, strlen($listinfoUrl) - 8) . 'subscribe/' . $m[2][0] . '?language=en';
4444
$promise2=$guzzle->getAsync($testUrl);
4545
$promise2->then(function ($resp2) use ($guzzle, &$nodes, $listinfoUrl, &$deadProviders, $m, &$totalAdded, $testUrl) {
4646
$testHtml = $resp2->getBody();
@@ -55,9 +55,14 @@
5555
file_put_contents(DEAD_PROVIDERS_JSON, pretty_json_encode($deadProviders));
5656
println('Provider ' . $listinfoUrl . ' forces a captcha. Skipped & Added to dead list.');
5757
return;
58+
}else if(intval($resp2->getStatusCode()/100)!=2){
59+
$deadProviders[] = $listinfoUrl;
60+
file_put_contents(DEAD_PROVIDERS_JSON, pretty_json_encode($deadProviders));
61+
println('Provider ' . $listinfoUrl . ' test failed. Skipped & Added to dead list.');
62+
return;
5863
}
5964
$singleAdded = 0;
60-
foreach ($m[1] as $item) {
65+
foreach ($m[2] as $item) {
6166
$url = substr($listinfoUrl, 0, strlen($listinfoUrl) - 8) . 'subscribe/' . $item;
6267
if (!in_array($url, $nodes)) {
6368
//println('Added node '.$url);

0 commit comments

Comments
 (0)