-
Notifications
You must be signed in to change notification settings - Fork 0
/
BiliUrlResolver.php
51 lines (48 loc) · 1.58 KB
/
BiliUrlResolver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
use Workerman\Protocols\Http\Response;
require_once __DIR__ . '/vendor/autoload.php';
$http_worker = new Worker("http://[::]:2399");
$http_worker->count = 1;
$http_worker->onMessage = function (TcpConnection $connection, Request $request) {
$response = new Response(200, [
'Content-Security-Policy' => "img-src 'none'",
'X-Powered-by' => 'workerman',
'Connection' => 'close',
], "");
$url = ltrim($request->uri(), '/');
echo "recv url:$url, ";
if (filter_var($url, FILTER_VALIDATE_URL)) {
echo "url is ok, calling you-get;\n";
exec("you-get --json $url", $output, $errno);
echo "exec you-get result: $errno;\n";
$output = implode("\n", $output);
//var_dump($output);
if ($errno == 0) {
$res = [];
$arr = json_decode($output, true);
foreach ($arr["streams"] as $now) {
//var_dump($now["src"]);
$res = array_merge($res, $now["src"]);
}
//var_dump($res);
foreach($res as $r)
{
//var_dump($r);
if(strstr($r, 'akamai')) {
$response->withStatus(301);
$response->header('Location', $r);
echo "output: 301 to $r\n";
break;
}
}
}
} else {
echo "bad url\n";
$response->withStatus(403);
}
$connection->close($response);
};
Worker::runAll();