您的位置:首页 > 运维架构 > 网站架构

关于音频网站的一些探索

2019-06-16 09:37 1191 查看
关于音频网站的一些探索

打开喜马拉雅首页,f12,media,点击一个节目试听

主要观察结果如下:

服务器:Tengine

时长 00:19:32

地址为同一个:http://audio.xmcdn.com/group59/M0B/A1/84/wKgLelzAV2zT7A2dAJDXru_6bKs549.m4a
音频文件的格式为 m4a
因此请求的 Accept: audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5
响应的 Content-Type: audio/x-m4a

分三次请求的,通过header中的 Range字段来标识区间
Range: bytes=0-
Range: bytes=3874631-
Range: bytes=5049307-

状态码:206
HTTP/206 “Partial Content”响应.这种响应是在客户端表明自己只需要目标URL上的部分资源的时候返回的.这种情况经常发生在客户端继续请求一个未完成的下载的时候

1--------------------------------
请求:

Request URL: http://audio.xmcdn.com/group59/M0B/A1/84/wKgLelzAV2zT7A2dAJDXru_6bKs549.m4a
Request Method: GET
Status Code: 206 Partial Content
Remote Address: 124.225.183.217:80
Referrer Policy: no-referrer-when-downgrade
Accept-Encoding: identity;q=1, *;q=0
chrome-proxy: frfr
Range: bytes=0-
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36

响应:
Accept-Ranges: bytes
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Age: 158410
Cache-Control: max-age=315360000
Connection: keep-alive
Content-Length: 9492398
Content-Range: bytes 0-9492397/9492398
Content-Type: audio/x-m4a
Date: Fri, 26 Apr 2019 08:56:32 GMT
Expires: Sat, 21 Apr 2029 12:56:22 GMT
Last-Modified: Wed, 24 Apr 2019 12:32:44 GMT
Server: Tengine
X-Real-Server: 192.168.11.122:80
X-Via: 1.1 tongdianxin114:9 (Cdn Cache Server V2.0)[79 200 2], 1.1 PSgslzdx9oy153:0 (Cdn Cache Server V2.0)[0 200 0], 1.1 PShndx3we111:1 (Cdn Cache Server V2.0)[63 200 0]

2--------------------------------
请求:

Request URL: http://audio.xmcdn.com/group59/M0B/A1/84/wKgLelzAV2zT7A2dAJDXru_6bKs549.m4a
Request Method: GET
Status Code: 206 Partial Content
Remote Address: 124.225.183.217:80
Referrer Policy: no-referrer-when-downgrade
Accept-Encoding: identity;q=1, *;q=0
Range: bytes=3874631-
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36

响应:

Accept-Ranges: bytes
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Age: 158546
Cache-Control: max-age=315360000
Content-Length: 5617767
Content-Range: bytes 3874631-9492397/9492398
Content-Type: audio/x-m4a
Date: Fri, 26 Apr 2019 08:58:48 GMT
Expires: Sat, 21 Apr 2029 12:56:22 GMT
Last-Modified: Wed, 24 Apr 2019 12:32:44 GMT
Server: Tengine
X-Real-Server: 192.168.11.122:80
X-Via: 1.1 tongdianxin114:9 (Cdn Cache Server V2.0)[79 200 2], 1.1 PSgslzdx9oy153:0 (Cdn Cache Server V2.0)[0 200 0], 1.1 PShndx3we111:1 (Cdn Cache Server V2.0)[0 200 0]

3--------------------------------
请求:

Request URL: http://audio.xmcdn.com/group59/M0B/A1/84/wKgLelzAV2zT7A2dAJDXru_6bKs549.m4a
Request Method: GET
Status Code: 206 Partial Content
Remote Address: 124.225.183.217:80
Referrer Policy: no-referrer-when-downgrade
Accept-Encoding: identity;q=1, *;q=0
Range: bytes=5049307-
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36

响应:

Accept-Ranges: bytes
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Age: 158681
Cache-Control: max-age=315360000
Content-Length: 4443091
Content-Range: bytes 5049307-9492397/9492398
Content-Type: audio/x-m4a
Date: Fri, 26 Apr 2019 09:01:03 GMT
Expires: Sat, 21 Apr 2029 12:56:22 GMT
Last-Modified: Wed, 24 Apr 2019 12:32:44 GMT
Server: Tengine
X-Real-Server: 192.168.11.122:80
X-Via: 1.1 tongdianxin114:9 (Cdn Cache Server V2.0)[79 200 2], 1.1 PSgslzdx9oy153:0 (Cdn Cache Server V2.0)[0 200 0], 1.1 PShndx3we111:1 (Cdn Cache Server V2.0)[81 200 0]

----------------------------------

下载一个时长 01:01:31 的音频到本地

$cont = file_get_contents('http://audio.xmcdn.com/group48/M01/C9/EC/wKgKlVuOS3DTuvNIAcf6jxoR3Qs090.m4a');
file_put_contents('D:/phpStudy/PHPTutorial/WWW/audio/audio.m4a', $cont);

CMD进入audio目录
git clone https://github.com/JamesHeinrich/getID3.git
下载音频操作类

test.php--------------------

include_once('./getID3/getid3/getid3.php');

$path = './audio.m4a';

$getID3 = new getID3();

$info = $getID3->analyze($path);

print_r($info);

注释:
filesize	文件大小
playtime_string		格式化的时长,字符串
playtime_seconds	时长,秒

可见,分析的还是很准确的。

因此,在后台上传音频之后就可以分析出音频的所有信息。

一个简易的播放页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<audio src="audio.m4a" controls="controls" preload loop="loop" autoplay="autoplay"></audio>
</body>
</html>

访问这个页面,发现,响应是206,且包含Range头,可见,音频的分段加载,是由浏览器自己来控制,并不需要做额外的处理了。

结束。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: