Skip to content

Commit 406f3c1

Browse files
committed
音频元信息的接口
1 parent 5e9482b commit 406f3c1

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

qiniu/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .zone import Zone
1818
from .region import Region
1919

20+
from .services.media.audio import AudioManager
2021
from .services.storage.bucket import BucketManager, build_batch_copy, build_batch_rename, build_batch_move, \
2122
build_batch_stat, build_batch_delete, build_batch_restoreAr
2223
from .services.storage.uploader import put_data, put_file, put_stream

qiniu/http.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ def _get(url, params, auth, headers=None):
9191
return __return_wrapper(r)
9292

9393

94+
def _session_get(url, params, auth):
95+
if _session is None:
96+
_init()
97+
try:
98+
r = _session.get(
99+
url, params=params, auth=auth,
100+
timeout=config.get_default('connection_timeout'))
101+
except Exception as e:
102+
return None, ResponseInfo(None, e)
103+
return __return_wrapper(r)
104+
105+
94106
class _TokenAuth(AuthBase):
95107
def __init__(self, token):
96108
self.token = token

qiniu/services/media/__init__.py

Whitespace-only changes.

qiniu/services/media/audio.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: UTF-8 -*-
3+
# Xiang Wang @ 2020-03-06 16:02:02
4+
5+
6+
from qiniu import http
7+
8+
9+
class AudioManager(object):
10+
"""音频处理"""
11+
12+
def __init__(self, auth):
13+
self.auth = auth
14+
15+
def avinfo(self, url):
16+
"""获取一个文件的音视频元信息:
17+
接口地址: https://developer.qiniu.com/dora/api/1247/audio-and-video-metadata-information-avinfo
18+
19+
Args:
20+
url: 音视频的url链接
21+
22+
Returns:
23+
一个dict变量, 类似:
24+
{
25+
"streams": [
26+
{
27+
"index": 0,
28+
"codec_name": "h264",
29+
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
30+
"codec_type": "video",
31+
"codec_time_base": "1/30",
32+
"codec_tag_string": "avc1",
33+
"codec_tag": "0x31637661",
34+
"width": 1152,
35+
"height": 864,
36+
...
37+
},
38+
{
39+
"index": 1,
40+
"codec_name": "aac",
41+
"codec_long_name": "Advanced Audio Coding",
42+
"codec_type": "audio",
43+
"codec_time_base": "1/44100",
44+
"codec_tag_string": "mp4a",
45+
"codec_tag": "0x6134706d",
46+
...
47+
}
48+
],
49+
"format": {
50+
"nb_streams": 2,
51+
"format_name": "mov,mp4,m4a,3gp,3g2,mj2",
52+
"format_long_name": "QuickTime/MPEG-4/Motion JPEG 2000 format",
53+
"start_time": "0.000000",
54+
"duration": "6413.359589", # 注意,duration是字符串
55+
...
56+
}
57+
}
58+
一个ResponseInfo对象
59+
"""
60+
return http._session_get(url + "?avinfo", {}, self.auth)

0 commit comments

Comments
 (0)