Skip to content

Commit 575fdb1

Browse files
committed
Added support to outputMode
1 parent f44fff8 commit 575fdb1

File tree

5 files changed

+159
-16
lines changed

5 files changed

+159
-16
lines changed

opentok/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .opentok import OpenTok, Roles, MediaModes
22
from .session import Session
3-
from .archives import Archive, ArchiveList
3+
from .archives import Archive, ArchiveList, OutputModes
44
from .exceptions import OpenTokException
55
from .version import __version__

opentok/archives.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from six import iteritems, PY2, PY3, u
33
import json
44
import pytz
5+
from enum import Enum
56
if PY3:
67
from datetime import timezone
78

@@ -10,6 +11,14 @@
1011

1112
dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime) or isinstance(obj, date) else None
1213

14+
class OutputModes(Enum):
15+
"""List of valid settings for the outputMode parameter of the OpenTok.start_archive() method."""
16+
composed = u('composed')
17+
"""The archive will produce a single MP4 file composed of all streams."""
18+
individual = u('individual')
19+
"""The archive will generate a ZIP container with multiple individual WEBM files and a JSON metadata
20+
file for video synchronization."""
21+
1322
class Archive(object):
1423
"""Represents an archive of an OpenTok session.
1524
@@ -27,6 +36,12 @@ class Archive(object):
2736
Boolean value set to true when the archive contains a video track,
2837
and set to false otherwise.
2938
39+
:ivar outputMode:
40+
The output mode to be generated for this archive:
41+
The default value is composed (a single MP4 file composed of all streams).
42+
Value individual will generate a ZIP container with multiple individual WEBM files
43+
and a JSON metadata file for video synchronization.
44+
3045
:ivar id:
3146
The archive ID.
3247
@@ -80,8 +95,9 @@ def __init__(self, sdk, values):
8095
self.created_at = datetime.fromtimestamp(values.get('createdAt') // 1000, timezone.utc)
8196
self.size = values.get('size')
8297
self.duration = values.get('duration')
83-
self.hasAudio = values.get('hasAudio')
84-
self.hasVideo = values.get('hasVideo')
98+
self.has_audio = values.get('hasAudio')
99+
self.has_video = values.get('hasVideo')
100+
self.output_mode = OutputModes[values.get('outputMode', 'composed')]
85101
self.url = values.get('url')
86102

87103
def stop(self):

opentok/opentok.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from .version import __version__
1919
from .session import Session
20-
from .archives import Archive, ArchiveList
20+
from .archives import Archive, ArchiveList, OutputModes
2121
from .exceptions import OpenTokException, RequestError, AuthError, NotFoundError, ArchiveError
2222

2323
class Roles(Enum):
@@ -263,7 +263,7 @@ def archive_url(self, archive_id=None):
263263
url = url + '/' + archive_id
264264
return url
265265

266-
def start_archive(self, session_id, hasAudio=True, hasVideo=True, name=None):
266+
def start_archive(self, session_id, has_audio=True, has_video=True, name=None, output_mode=OutputModes.composed):
267267
"""
268268
Starts archiving an OpenTok 2.0 session.
269269
@@ -284,14 +284,22 @@ def start_archive(self, session_id, hasAudio=True, hasVideo=True, name=None):
284284
an error.
285285
:param Boolean hasVideo: if set to True, a video track will be inserted to the archive.
286286
hasVideo is an optional parameter that is set to True by default.
287+
:param OutputModes outputMode: if set to composed, a single MP4 file composed of all streams
288+
will be generated. If you set it to individual it will create a ZIP container with multiple
289+
individual WEBM files and a JSON metadata file for video synchronization.
290+
outputMode is an optional parameter that is set to composed by default.
287291
288292
:rtype: The Archive object, which includes properties defining the archive,
289293
including the archive ID.
290294
"""
295+
if not isinstance(output_mode, OutputModes):
296+
raise OpenTokException(u('Cannot start archive, {0} is not a valid output mode').format(output_mode))
297+
291298
payload = {'name': name,
292299
'sessionId': session_id,
293-
'hasAudio': hasAudio,
294-
'hasVideo': hasVideo
300+
'hasAudio': has_audio,
301+
'hasVideo': has_video,
302+
'outputMode': output_mode.value
295303
}
296304

297305
response = requests.post(self.archive_url(), data=json.dumps(payload), headers=self.archive_headers())

tests/test_archive.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import datetime
99
import pytz
1010

11-
from opentok import OpenTok, Archive, __version__
11+
from opentok import OpenTok, Archive, __version__, OutputModes
1212

1313
class OpenTokArchiveTest(unittest.TestCase):
1414
def setUp(self):
@@ -31,6 +31,7 @@ def test_stop_archive(self):
3131
u('status'): u('started'),
3232
u('hasAudio'): True,
3333
u('hasVideo'): True,
34+
u('outputMode'): OutputModes.composed.value,
3435
u('url'): None,
3536
})
3637
httpretty.register_uri(httpretty.POST, u('https://api.opentok.com/v2/partner/{0}/archive/{1}/stop').format(self.api_key, archive_id),
@@ -47,6 +48,7 @@ def test_stop_archive(self):
4748
"status" : "stopped",
4849
"hasAudio": true,
4950
"hasVideo": false,
51+
"outputMode": "composed",
5052
"url" : null
5153
}""")),
5254
status=200,
@@ -70,8 +72,9 @@ def test_stop_archive(self):
7072
expect(archive).to.have.property(u('created_at')).being.equal(created_at)
7173
expect(archive).to.have.property(u('size')).being.equal(0)
7274
expect(archive).to.have.property(u('duration')).being.equal(0)
73-
expect(archive).to.have.property(u('hasAudio')).being.equal(True)
74-
expect(archive).to.have.property(u('hasVideo')).being.equal(False)
75+
expect(archive).to.have.property(u('has_audio')).being.equal(True)
76+
expect(archive).to.have.property(u('has_video')).being.equal(False)
77+
expect(archive).to.have.property(u('output_mode')).being.equal(OutputModes.composed)
7578
expect(archive).to.have.property(u('url')).being.equal(None)
7679

7780
@httpretty.activate
@@ -89,6 +92,7 @@ def test_delete_archive(self):
8992
u('status'): u('available'),
9093
u('hasAudio'): True,
9194
u('hasVideo'): True,
95+
u('outputMode'): OutputModes.composed.value,
9296
u('url'): None,
9397
})
9498
httpretty.register_uri(httpretty.DELETE, u('https://api.opentok.com/v2/partner/{0}/archive/{1}').format(self.api_key, archive_id),

0 commit comments

Comments
 (0)