Skip to content

Commit cf34136

Browse files
authored
Enhance Event API addTrack endpoint (#41)
* Enhance Event API: Update addTrack method to support Tags and overwriting tracks and add new VTT test files, fixes #36
1 parent 254658d commit cf34136

File tree

6 files changed

+163
-55
lines changed

6 files changed

+163
-55
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@
5858
- WorkflowApi endpoint methods got updated
5959
- `withconfigurationpaneljson` parameter has been added to `/api/workflow-definitions` endpoints. [#34]
6060
- `@deprecated` removal of OcWorkflowsApi::geAll() method!
61+
- Repair and enhance Event API `addTrack`under `/api/events/{eventId}/track` [#36]
62+
- Tags are now added, therefore it can be replaced by ingest method.
63+
- overwriteExisting flag has been fixed and works as expected now!
64+

src/OpencastApi/Rest/OcEventsApi.php

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public function __construct($restClient)
1313
## [Section 1]: General API endpoints.
1414

1515
/**
16-
* Returns a list of events.
16+
* Returns a list of events.
1717
* By setting the optional sign parameter to true, the method will pre-sign distribution urls if signing is turned on in Opencast.
1818
* Remember to consider the maximum validity of signed URLs when caching this response.
19-
*
19+
*
2020
* @param array $params (optional) The list of query params to pass which can contain the followings:
2121
* [
2222
* 'sign' => (boolean) {Whether public distribution urls should be signed.},
@@ -30,7 +30,7 @@ public function __construct($restClient)
3030
* 'offset' => (int) {the index of the first result to return},
3131
* 'filter' => (array) {an assiciative array for filtering e.g. ['is_part_of' => '{series id}']},
3232
* ]
33-
*
33+
*
3434
* @return array the response result ['code' => 200, 'body' => 'A (potentially empty) array list of events is returned.']
3535
*/
3636
public function getAll($params = [])
@@ -66,7 +66,7 @@ public function getAll($params = [])
6666

6767
/**
6868
* Returns the list of events in a series.
69-
*
69+
*
7070
* @param string $seriesId the identifier for a series
7171
* @param array $params (optional) The list of query params to pass which can contain the followings:
7272
* [
@@ -81,7 +81,7 @@ public function getAll($params = [])
8181
* 'offset' => (int) {the index of the first result to return},
8282
* 'filter' => (array) {an assiciative array for filtering e.g. ['is_part_of' => '{series id}']},
8383
* ]
84-
*
84+
*
8585
* @return array the response result ['code' => 200, 'body' => 'A (potentially empty) array list of events in a series is returned.']
8686
*/
8787
public function getBySeries($seriesId, $params = [])
@@ -92,12 +92,12 @@ public function getBySeries($seriesId, $params = [])
9292

9393
return $this->getAll($params);
9494
}
95-
95+
9696
/**
9797
* Returns a single event.
9898
* By setting the optional sign parameter to true, the method will pre-sign distribution urls if signing is turned on in Opencast.
9999
* Remember to consider the maximum validity of signed URLs when caching this response.
100-
*
100+
*
101101
* @param string $eventId the identifier of the event.
102102
* @param array $params (optional) The list of query params to pass which can contain the followings:
103103
* [
@@ -107,7 +107,7 @@ public function getBySeries($seriesId, $params = [])
107107
* 'withscheduling' => (boolean) {Whether the scheduling information should be included in the response. (version 1.1.0 and higher)},
108108
* 'withpublications' => (boolean) {Whether the publication ids and urls should be included in the response.}
109109
* ]
110-
*
110+
*
111111
* @return array the response result ['code' => 200, 'body' => 'The event (Object)']
112112
*/
113113
public function get($eventId, $params = [])
@@ -135,7 +135,7 @@ public function get($eventId, $params = [])
135135

136136
/**
137137
* Creates an event by sending metadata, access control list, processing instructions and files in a multipart request.
138-
*
138+
*
139139
* @param string|array $acls A collection of roles with their possible action
140140
* @param string|array $metadata Event metadata
141141
* @param string|array $processing Processing instructions task configuration
@@ -150,7 +150,7 @@ public function get($eventId, $params = [])
150150
* $uploadTotal: the total number of bytes expected to be uploaded,
151151
* $uploadedBytes: the number of bytes uploaded so far
152152
* )
153-
*
153+
*
154154
* @return array the response result ['code' => 201, 'body' => '{A new event is created and its identifier is returned}', 'location' => '{the url of new event'}]
155155
*/
156156
public function create($acls, $metadata, $processing, $scheduling = '', $presenterFile = null, $presentationFile = null, $audioFile = null, $progressCallable = null)
@@ -185,7 +185,7 @@ public function create($acls, $metadata, $processing, $scheduling = '', $present
185185

186186
/**
187187
* Updates an event.
188-
*
188+
*
189189
* @param string $eventId the event identifier
190190
* @param string|array $acls (optional) A collection of roles with their possible action
191191
* @param string|array $metadata (optional) Event metadata
@@ -194,7 +194,7 @@ public function create($acls, $metadata, $processing, $scheduling = '', $present
194194
* @param file $presenterFile (optional) Presenter movie track
195195
* @param file $presentationFile (optional) Presentation movie track
196196
* @param file $audioFile (optional) Audio track
197-
*
197+
*
198198
* @return array the response result ['code' => 204, 'reason' => 'NO CONTENT'] (The event has been updated)
199199
*/
200200
public function update($eventId, $acls = '', $metadata = '', $processing = '', $scheduling = '', $presenterFile = null, $presentationFile = null, $audioFile = null)
@@ -231,9 +231,9 @@ public function update($eventId, $acls = '', $metadata = '', $processing = '', $
231231
* Retracts possible publications and deletes an event.
232232
* Since version 1.6.0 published events will be retracted by this endpoint,
233233
* if you use a version previous to 1.6.0 don't call this endpoint before retracting published events.
234-
*
234+
*
235235
* @param string $eventId the event identifier
236-
*
236+
*
237237
* @return array the response result ['code' => 204, 'reason' => 'NO CONTENT'] (The event has been deleted)
238238
*/
239239
public function delete($eventId)
@@ -248,9 +248,9 @@ public function delete($eventId)
248248

249249
/**
250250
* Returns an event's access policy.
251-
*
251+
*
252252
* @param string $eventId the event identifier
253-
*
253+
*
254254
* @return array the response result ['code' => 200, 'body' => '{The access control list for the specified event (Object)}']
255255
*/
256256
public function getAcl($eventId)
@@ -261,10 +261,10 @@ public function getAcl($eventId)
261261

262262
/**
263263
* Update an event's access policy.
264-
*
264+
*
265265
* @param string $eventId the event identifier
266266
* @param string|array $acl Access policy
267-
*
267+
*
268268
* @return array the response result ['code' => 204, 'reason' => 'NO CONTENT'] (The access control list for the specified event is updated)
269269
*/
270270
public function updateAcl($eventId, $acl)
@@ -278,11 +278,11 @@ public function updateAcl($eventId, $acl)
278278
/**
279279
* Grants permission to execute action on the specified event to any user with role role.
280280
* Note that this is a convenience method to avoid having to build and post a complete access control list.
281-
*
282-
* @param string $eventId the event identifier
281+
*
282+
* @param string $eventId the event identifier
283283
* @param string $action The action that is allowed to be executed
284284
* @param string $role The role that is granted permission
285-
*
285+
*
286286
* @return array the response result ['code' => 204, 'reason' => 'NO CONTENT'] (The permission has been created in the access control list of the specified event)
287287
*/
288288
public function addSingleAcl($eventId, $action, $role)
@@ -296,7 +296,7 @@ public function addSingleAcl($eventId, $action, $role)
296296
/**
297297
* Removes all ACLs for the event.
298298
* @param string $eventId the event identifier
299-
*
299+
*
300300
* @return array the response result ['code' => 204, 'reason' => 'NO CONTENT'] (The access control list for the specified event is updated)
301301
*/
302302
public function emptyAcl($eventId)
@@ -307,11 +307,11 @@ public function emptyAcl($eventId)
307307

308308
/**
309309
* Revokes permission to execute action on the specified event from any user with specified role.
310-
*
310+
*
311311
* @param string $eventId the event identifier
312312
* @param string $action The action that is no longer allowed to be executed
313313
* @param string $role The role that is no longer granted permission
314-
*
314+
*
315315
* @return array the response result ['code' => 204, 'reason' => 'NO CONTENT'] (The permission has been revoked from the access control list of the specified event)
316316
*/
317317
public function deleteSingleAcl($eventId, $action, $role)
@@ -323,7 +323,7 @@ public function deleteSingleAcl($eventId, $action, $role)
323323
## End of [Section 2]: Access Policy.
324324

325325
## [Section 3]: Media.
326-
326+
327327
/**
328328
* Returns the complete set of media tracks.
329329
* @param string $eventId the event identifier
@@ -339,18 +339,26 @@ public function getMedia($eventId)
339339
/**
340340
* Adds the given track to the given flavor in the event. It does not start a workflow.
341341
* @param string $eventId the event identifier
342-
* @param string $flavor Denotes type and subtype, e.g. 'captions/source+en'
342+
* @param string $flavor Denotes type and subtype, e.g. 'captions/source+en' or now that we have tags flavor could be 'captions/source'
343343
* @param file $track The track file
344344
* @param boolean $overwriteExisting If true, all other tracks in the specified flavor are REMOVED (Default: false)
345+
* @param mixed $tags (optional) Comma separated list of tags either as an array or a string for the given track, e.g. archive,publish. If a 'lang:LANG-CODE' tag exists and 'overwriteExisting=true' only tracks with same lang tag and flavor will be replaced. This behavior is used for captions. (Default: null) (Array | String)
345346
*
346347
* @return array the response result ['code' => 200, 'body' => '{The track was added successfully.}']
347348
*/
348-
public function addTrack($eventId, $flavor, $track, $overwriteExisting = false)
349+
public function addTrack($eventId, $flavor, $track, $overwriteExisting = false, $tags = null)
349350
{
350351
$uri = self::URI . "/{$eventId}/track";
351352
$formData['flavor'] = $flavor;
352353
$formData['track'] = $track;
353-
$formData['overwriteExisting'] = $overwriteExisting;
354+
if ($overwriteExisting) {
355+
$formData['overwriteExisting'] = 'true';
356+
}
357+
358+
if (!empty($tags)) {
359+
$tagStr = is_array($tags) ? implode(',', $tags) : $tags;
360+
$formData['tags'] = $tagStr;
361+
}
354362

355363
$options = $this->restClient->getMultiPartFormParams($formData);
356364
return $this->restClient->performPost($uri, $options);
@@ -363,10 +371,10 @@ public function addTrack($eventId, $flavor, $track, $overwriteExisting = false)
363371
/**
364372
* Returns the event's metadata (if type is defined of the specified type).
365373
* For a metadata catalog there is the flavor such as 'dublincore/episode' and this is the unique type.
366-
*
374+
*
367375
* @param string $eventId the event identifier
368376
* @param string $type (optional) The type of metadata to get
369-
*
377+
*
370378
* @return array the response result ['code' => 200, 'body' => '{The metadata collection (array)}']
371379
*/
372380
public function getMetadata($eventId, $type = '')
@@ -383,11 +391,11 @@ public function getMetadata($eventId, $type = '')
383391
/**
384392
* Update the metadata with the matching type of the specified event.
385393
* For a metadata catalog there is the flavor such as dublincore/episode and this is the unique type.
386-
*
394+
*
387395
* @param string $eventId the event identifier
388396
* @param string $type The type of metadata to update
389397
* @param string|array $metadata Event metadata
390-
*
398+
*
391399
* @return array the response result ['code' => 200, 'reason' => 'OK'] (The metadata of the given namespace has been updated)
392400
*/
393401
public function updateMetadata($eventId, $type, $metadata)
@@ -407,10 +415,10 @@ public function updateMetadata($eventId, $type, $metadata)
407415
/**
408416
* Delete the metadata namespace catalog of the specified event. This will remove all fields and values of the catalog.
409417
* Note that the metadata catalog of type dublincore/episode cannot be deleted.
410-
*
418+
*
411419
* @param string $eventId the event identifier
412420
* @param string $type The type of metadata to delete
413-
*
421+
*
414422
* @return array the response result ['code' => 204, 'reason' => 'No Content'] (The metadata of the given namespace has been delete)
415423
*/
416424
public function deleteMetadata($eventId, $type)
@@ -427,10 +435,10 @@ public function deleteMetadata($eventId, $type)
427435

428436
/**
429437
* Returns an event's list of publications.
430-
*
438+
*
431439
* @param string $eventId the event identifier
432440
* @param boolean $sign (optional) Whether publication urls (version 1.7.0 or higher) and distribution urls should be pre-signed.
433-
*
441+
*
434442
* @return array the response result ['code' => 200, 'body' => '{The list of publications}']
435443
*/
436444
public function getPublications($eventId, $sign = false)
@@ -443,11 +451,11 @@ public function getPublications($eventId, $sign = false)
443451

444452
/**
445453
* Returns a single publication.
446-
*
454+
*
447455
* @param string $eventId the event identifier
448456
* @param string $publicationId the publication id
449457
* @param boolean $sign (optional) Whether publication urls (version 1.7.0 or higher) and distribution urls should be pre-signed.
450-
*
458+
*
451459
* @return array the response result ['code' => 200, 'body' => '{The track details}']
452460
*/
453461
public function getSinglePublication($eventId, $publicationId ,$sign = false)
@@ -465,9 +473,9 @@ public function getSinglePublication($eventId, $publicationId ,$sign = false)
465473
/**
466474
* Returns an event's scheduling information.
467475
* Available since API version 1.1.0.
468-
*
476+
*
469477
* @param string $eventId the event identifier
470-
*
478+
*
471479
* @return array the response result ['code' => 200, 'body' => '{The scheduling information for the specified event}']
472480
*/
473481
public function getScheduling($eventId)
@@ -485,11 +493,11 @@ public function getScheduling($eventId)
485493
/**
486494
* Update the scheduling information of the event.
487495
* Available since API version 1.1.0.
488-
*
496+
*
489497
* @param string $eventId the event identifier
490498
* @param string|array $scheduling The scheduling information.
491499
* @param boolean $allowConflict (optional) Allow conflicts when updating scheduling.
492-
*
500+
*
493501
* @return array the response result ['code' => 204, 'reason' => 'NO CONTENT'] (The scheduling information for the specified event is updated)
494502
*/
495503
public function updateScheduling($eventId, $scheduling, $allowConflict = false)
@@ -500,7 +508,7 @@ public function updateScheduling($eventId, $scheduling, $allowConflict = false)
500508
'reason' => 'API Version (>= 1.1.0) is required'
501509
];
502510
}
503-
511+
504512
$uri = self::URI . "/{$eventId}/scheduling";
505513

506514
$formData = [
@@ -517,4 +525,4 @@ public function updateScheduling($eventId, $scheduling, $allowConflict = false)
517525

518526
## End of [Section 6]: Scheduling Information.
519527
}
520-
?>
528+
?>

tests/DataProvider/EventsDataProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ public static function getAudioFile()
6464
return Psr7\Utils::tryFopen(__DIR__ . '/test_files/audio_test.mp3', 'r');
6565
}
6666

67-
public static function getVttFile()
67+
public static function getVttFile($lang = 'de', $overwrite = false)
6868
{
69-
return Psr7\Utils::tryFopen(__DIR__ . '/test_files/video_test_de.vtt', 'r');
69+
$lang = strtolower($lang);
70+
$overwitestr = $overwrite ? '_overwrite' : '';
71+
$filename = "/test_files/video_test{$overwitestr}_{$lang}.vtt";
72+
return Psr7\Utils::tryFopen(__DIR__ . $filename, 'r');
7073
}
7174
}
7275
?>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
WEBVTT FILE
2+
3+
1
4+
00:00:00.500 --> 00:00:01.000 D:vertical A:start
5+
Hello There
6+
7+
2
8+
00:00:01.001 --> 00:00:01.200 A:start
9+
It is a test
10+
11+
3
12+
00:00:01.200 --> 00:00:01.300 A:end
13+
It is a test.
14+
15+
4
16+
00:00:01.300 --> 00:00:01.400
17+
It is a test..
18+
19+
5
20+
00:00:01.400 --> 00:00:01.500
21+
It is a test...
22+
23+
6
24+
00:00:01.500 --> 00:00:01.900
25+
It is a test....
26+
27+
7
28+
00:00:01.900 --> 00:00:02.000
29+
DONE!

0 commit comments

Comments
 (0)