Skip to content
Merged

rtmp #37

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions oss2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def progress_callback(bytes_consumed, total_bytes):
`http_date` 函数把Unix Time转换为HTTP Date;而 `http_to_unixtime` 则做相反的转换。如 ::

>>> import oss2, time
>>> unix_time = int(time.time()) # 当前UNIX Time,设其职为 1449313829
>>> unix_time = int(time.time()) # 当前UNIX Time,设其值为 1449313829
>>> date_str = oss2.http_date(unix_time) # 得到 'Sat, 05 Dec 2015 11:10:29 GMT'
>>> oss2.http_to_unixtime(date_str) # 得到 1449313829

Expand Down Expand Up @@ -948,8 +948,8 @@ def post_vod_playlist(self, channel_name, playlist_name, start_time = 0, end_tim

param str channel_name: 要生成点播列表的live channel的名称
param str playlist_name: 要生成点播列表m3u8文件的名称
param int start_time: 点播的起始时间,为UNIX时间戳
param int end_time: 点播的结束时间,为UNIX时间戳
param int start_time: 点播的起始时间,Unix Time格式,可以使用int(time.time())获取
param int end_time: 点播的结束时间,Unix Time格式,可以使用int(time.time())获取
"""
key = channel_name + "/" + playlist_name
resp = self.__do_object('POST', key, params={Bucket.VOD: '',
Expand Down
39 changes: 26 additions & 13 deletions oss2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,28 +454,41 @@ class LiveChannelInfo(object):
"""Live channel(直播频道)配置。

:param status: 直播频道的状态,合法的值为"enabled"和"disabled"。
:type type: str
:type status: str

:param description: 直播频道的描述信息,最长为128字节。
:type description: str

:param modified: 直播频道的最后修改时间,这个字段仅在ListLiveChannel时使用。
:type modified: str

:param target: 直播频道的推流目标节点,包含目标协议相关的参数。
:type class:`LiveChannelInfoTarget <oss2.models.LiveChannelInfoTarget>`"""

:type class:`LiveChannelInfoTarget <oss2.models.LiveChannelInfoTarget>`

:param last_modified: 直播频道的最后修改时间,这个字段仅在`ListLiveChannel`时使用。
:type last_modified: int, 参考 :ref:`unix_time`。

:param name: 直播频道的名称。
:type name: str

:param play_url: 播放地址。
:type play_url: str

:param publish_url: 推流地址。
:type publish_url: str"""

def __init__(self,
status = 'enabled',
description = '',
target = None,
modified = None,
name = None):
last_modified = None,
name = None,
play_url = None,
publish_url = None):
self.status = status
self.description = description
self.target = target
self.modified = modified
self.last_modified = last_modified
self.name = name
self.play_url = play_url
self.publish_url = publish_url


class LiveChannelList(object):
Expand All @@ -497,7 +510,7 @@ class LiveChannelList(object):
:type marker: str

:param channels: List返回的直播频道列表
:type channels: list"""
:type channels: list,类型为 :class:`LiveChannelInfo`"""

def __init__(self,
prefix = '',
Expand Down Expand Up @@ -575,7 +588,7 @@ class LiveChannelStat(object):
:type remote_addr: str

:param connected_time: 本次推流开始时间。
:type connected_time: str
:type connected_time: int, unix time

:param video: 视频描述信息。
:type video: class:`LiveChannelVideoStat <oss2.models.LiveChannelVideoStat>`
Expand All @@ -600,10 +613,10 @@ class LiveRecord(object):
"""直播频道中的推流记录信息

:param start_time: 本次推流开始时间。
:type start_time: str
:type start_time: int,参考 :ref:`unix_time`。

:param end_time: 本次推流结束时间。
:type end_time: str
:type end_time: int, 参考 :ref:`unix_time`。

:param remote_addr: 推流时客户端的地址。
:type remote_addr: str"""
Expand Down
13 changes: 7 additions & 6 deletions oss2/xml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def _add_node_child(parent, tag):
def parse_list_objects(result, body):
root = ElementTree.fromstring(body)
url_encoded = _is_url_encoding(root)

result.is_truncated = _find_bool(root, 'IsTruncated')
if result.is_truncated:
result.next_marker = _find_object(root, 'NextMarker', url_encoded)
Expand Down Expand Up @@ -269,15 +268,17 @@ def parse_list_live_channel(result, body):
result.marker = _find_tag(root, 'Marker')
result.max_keys = _find_int(root, 'MaxKeys')
result.is_truncated = _find_bool(root, 'IsTruncated')
result.next_marker = _find_tag(root, 'NextMarker')

if result.is_truncated:
result.next_marker = _find_tag(root, 'NextMarker')

channels = root.findall('LiveChannel')
for channel in channels:
tmp = LiveChannelInfo()
tmp.name = _find_tag(channel, 'Name')
tmp.description = _find_tag(channel, 'Description')
tmp.status = _find_tag(channel, 'Status')
tmp.modified = _find_tag(channel, 'LastModified')
tmp.last_modified = iso8601_to_unixtime(_find_tag(channel, 'LastModified'))
tmp.play_url = _find_tag(channel, 'PlayUrls/Url')
tmp.publish_url = _find_tag(channel, 'PublishUrls/Url')

Expand Down Expand Up @@ -307,7 +308,7 @@ def parse_live_channel_stat(result, body):
if root.find('RemoteAddr') is not None:
result.remote_addr = _find_tag(root, 'RemoteAddr')
if root.find('ConnectedTime') is not None:
result.connected_time = iso8601_to_date(_find_tag(root, 'ConnectedTime'))
result.connected_time = iso8601_to_unixtime(_find_tag(root, 'ConnectedTime'))

video_node = root.find('Video')
audio_node = root.find('Audio')
Expand All @@ -328,8 +329,8 @@ def parse_live_channel_history(result, body):
records = root.findall('LiveRecord')
for record in records:
tmp = LiveRecord()
tmp.start_time = _find_tag(record, 'StartTime')
tmp.end_time = _find_tag(record, 'EndTime')
tmp.start_time = iso8601_to_unixtime(_find_tag(record, 'StartTime'))
tmp.end_time = iso8601_to_unixtime(_find_tag(record, 'EndTime'))
tmp.remote_addr = _find_tag(record, 'RemoteAddr')
result.records.append(tmp)

Expand Down
91 changes: 87 additions & 4 deletions tests/test_mock_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,87 @@ def test_create_live_channel(self, do_request):

self.assertRequest(req_info, request_text)

@patch('oss2.Session.do_request')
def test_list_live_channel(self, do_request):
from oss2.utils import iso8601_to_unixtime

request_text = '''GET /?live= HTTP/1.1
Host: ming-oss-share.oss-cn-hangzhou.aliyuncs.com
Accept-Encoding: identity
Connection: keep-alive
Accept: */*
User-Agent: aliyun-sdk-python/2.1.1(Windows/7/AMD64;2.7.10)
date: Tue, 09 Aug 2016 11:51:30 GMT
authorization: OSS 2NeLUvmJFYbrj2Eb:BQCNOYdGglcAbhdHhqTfVNtLBow='''

response_text = '''HTTP/1.1 200 OK
Server: AliyunOSS
Date: Tue, 09 Aug 2016 11:51:30 GMT
Content-Type: application/xml
Content-Length: 100
Connection: keep-alive
x-oss-request-id: 57A9C3C27FBF67E9BE686908
x-oss-server-time: 1

<?xml version="1.0" encoding="UTF-8"?>
<ListLiveChannelResult>
<Prefix>test</Prefix>
<Marker></Marker>
<MaxKeys>2</MaxKeys>
<IsTruncated>true</IsTruncated>
<NextMarker>test3</NextMarker>
<LiveChannel>
<Name>test1</Name>
<Description>test1</Description>
<Status>enabled</Status>
<LastModified>2016-04-01T07:04:00.000Z</LastModified>
<PublishUrls>
<Url>rtmp://ming-oss-share.oss-cn-hangzhou.aliyuncs.com/live/test1</Url>
</PublishUrls>
<PlayUrls>
<Url>http://ming-oss-share.oss-cn-hangzhou.aliyuncs.com/test1/playlist.m3u8</Url>
</PlayUrls>
</LiveChannel>
<LiveChannel>
<Name>test2</Name>
<Description>test2</Description>
<Status>disabled</Status>
<LastModified>2016-04-01T08:04:50.000Z</LastModified>
<PublishUrls>
<Url>rtmp://ming-oss-share.oss-cn-hangzhou.aliyuncs.com/live/test2</Url>
</PublishUrls>
<PlayUrls>
<Url>http://ming-oss-share.oss-cn-hangzhou.aliyuncs.com/test2/playlist.m3u8</Url>
</PlayUrls>
</LiveChannel>
</ListLiveChannelResult>'''

req_info = unittests.common.mock_response(do_request, response_text)
result = unittests.common.bucket().list_live_channel('test', '', 2)
self.assertRequest(req_info, request_text)

self.assertEqual(result.prefix, 'test')
self.assertEqual(result.marker, '')
self.assertEqual(result.max_keys, 2)
self.assertEqual(result.is_truncated, True)
self.assertEqual(result.next_marker, 'test3')
self.assertEqual(len(result.channels), 2)
self.assertEqual(result.channels[0].name, 'test1')
self.assertEqual(result.channels[0].description, 'test1')
self.assertEqual(result.channels[0].status, 'enabled')
self.assertEqual(result.channels[0].last_modified, iso8601_to_unixtime('2016-04-01T07:04:00.000Z'))
self.assertEqual(result.channels[0].publish_url, 'rtmp://ming-oss-share.oss-cn-hangzhou.aliyuncs.com/live/test1')
self.assertEqual(result.channels[0].play_url, 'http://ming-oss-share.oss-cn-hangzhou.aliyuncs.com/test1/playlist.m3u8')
self.assertEqual(result.channels[1].name, 'test2')
self.assertEqual(result.channels[1].description, 'test2')
self.assertEqual(result.channels[1].status, 'disabled')
self.assertEqual(result.channels[1].last_modified, iso8601_to_unixtime('2016-04-01T08:04:50.000Z'))
self.assertEqual(result.channels[1].publish_url, 'rtmp://ming-oss-share.oss-cn-hangzhou.aliyuncs.com/live/test2')
self.assertEqual(result.channels[1].play_url, 'http://ming-oss-share.oss-cn-hangzhou.aliyuncs.com/test2/playlist.m3u8')

@patch('oss2.Session.do_request')
def test_get_live_channel_stat(self, do_request):
from oss2.utils import iso8601_to_date
from oss2.utils import iso8601_to_unixtime
from oss2.models import LiveChannelAudioStat, LiveChannelVideoStat

request_text = '''GET /lc?comp=stat&live= HTTP/1.1
Expand Down Expand Up @@ -791,7 +869,7 @@ def test_get_live_channel_stat(self, do_request):

self.assertRequest(req_info, request_text)
self.assertEqual(result.status, 'Live')
self.assertEqual(result.connected_time, iso8601_to_date('2016-08-08T05:59:28.000Z'))
self.assertEqual(result.connected_time, iso8601_to_unixtime('2016-08-08T05:59:28.000Z'))
self.assertEqual(result.remote_addr, '8.8.8.8:57186')
video = LiveChannelVideoStat(1280, 536, 24, 'H264', 214146)
self.assertEqual(result.video.bandwidth, video.bandwidth)
Expand All @@ -807,6 +885,7 @@ def test_get_live_channel_stat(self, do_request):
@patch('oss2.Session.do_request')
def test_get_live_channel_history(self, do_request):
from oss2.models import LiveRecord
from oss2.utils import iso8601_to_unixtime

request_text = '''GET /lc?comp=history&live= HTTP/1.1
Host: ming-oss-share.oss-cn-hangzhou.aliyuncs.com
Expand Down Expand Up @@ -847,11 +926,15 @@ def test_get_live_channel_history(self, do_request):

self.assertRequest(req_info, request_text)
self.assertEqual(len(result.records), 2)
lr = LiveRecord('2016-08-06T05:59:28.000Z', '2016-08-06T06:02:43.000Z', '8.8.8.8:57186')
lr = LiveRecord(iso8601_to_unixtime('2016-08-06T05:59:28.000Z'),
iso8601_to_unixtime('2016-08-06T06:02:43.000Z'),
'8.8.8.8:57186')
self.assertEqual(result.records[0].start_time, lr.start_time)
self.assertEqual(result.records[0].end_time, lr.end_time)
self.assertEqual(result.records[0].remote_addr, lr.remote_addr)
lr = LiveRecord('2016-08-06T06:16:20.000Z', '2016-08-06T06:16:25.000Z', '1.1.1.1:57365')
lr = LiveRecord(iso8601_to_unixtime('2016-08-06T06:16:20.000Z'),
iso8601_to_unixtime('2016-08-06T06:16:25.000Z'),
'1.1.1.1:57365')
self.assertEqual(result.records[1].start_time, lr.start_time)
self.assertEqual(result.records[1].end_time, lr.end_time)
self.assertEqual(result.records[1].remote_addr, lr.remote_addr)
Expand Down
Loading