-
Notifications
You must be signed in to change notification settings - Fork 264
/
Copy pathindex.php
64 lines (51 loc) · 1.39 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require '../vendor/autoload.php';
use Metowolf\Meting;
function handler($server, $type, $id)
{
if (empty($id)) {
throw new Exception('require id.');
}
if (!in_array($server, ['netease', 'tencent', 'baidu', 'xiami', 'kugou', 'kuwo'])) {
throw new Exception('unsupported server.');
}
if (!in_array($type, ['song', 'album', 'search', 'artist', 'playlist', 'lrc', 'url', 'pic'])) {
throw new Exception('unsupported type.');
}
$api = new Meting($server);
$api->format(true);
if (getenv('METING_PROXY')) {
$api->proxy(getenv('METING_PROXY'));
}
if (!empty($_SERVER['HTTP_COOKIE'])) {
$api->cookie($_SERVER['HTTP_COOKIE']);
}
if ($type == 'lrc') {
$type = 'lyric';
}
$data = $api->$type($id);
$data = json_decode($data, true);
return $data;
}
function main()
{
$server = $_GET['server'] ?? 'netease';
$type = $_GET['type'] ?? 'search';
$id = $_GET['id'] ?? 'hello';
try {
$data = handler($server, $type, $id);
$result = [
'success' => true,
'message' => $data
];
} catch (Exception $e) {
$result = [
'success' => false,
'message' => $e->getMessage()
];
}
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
echo json_encode($result);
}
main();