forked from featmaker/Music-Lrc-Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
song.php
32 lines (32 loc) · 901 Bytes
/
song.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
<?php
header('content="text/html;charset=utf-8"');
$method = $_GET['method'];
if ($method == 'getList') {
$list = [];
$files = scandir('mp3/song');
foreach ($files as $key => $value) {
if ($value == '.' || $value == '..') {
continue;
}
$list[] = explode('.',iconv("gb2312", "utf-8", $value))[0];
}
echo json_encode(['name'=>$list]);
} elseif ($method == 'getLrc') {
$name = iconv("utf-8", "gb2312", $_GET['name'].'.lrc');
$path = './mp3/lrc/'.$name;
if (file_exists($path)) {
$lrc = file_get_contents($path);
$data = [];
$times = [];
$time = preg_match_all('/(\[.*\])(.*)/',$lrc,$data);
foreach ($data[1] as $key => $value) {
$min = intval(substr($value,1,3))*60;
$sec = (floatval(substr($value,4,-1)));
$secs = $min+$sec;
$times[] = $secs;
}
echo json_encode(['msg'=>'yes','time'=>$times,'lrc'=>$data[2]]);
} else {
echo json_encode(['msg'=>'no']);
}
}