This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
bc-mapi.php
1569 lines (1349 loc) · 38.4 KB
/
bc-mapi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Brightcove PHP MAPI Wrapper 2.0.4 (18 FEBRUARY 2011)
* (Formerly known as Echove)
*
* REFERENCES:
* Website: http://opensource.brightcove.com
* Source: http://github.com/brightcoveos
*
* AUTHORS:
* Matthew Congrove <mcongrove@brightcove.com>
* Brian Franklin <bfranklin@brightcove.com>
*
* CONTRIBUTORS:
* Luke Weber, Brandon Aaskov
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the “Software”),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, alter, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, subject to the following conditions:
*
* 1. The permission granted herein does not extend to commercial use of
* the Software by entities primarily engaged in providing online video and
* related services.
*
* 2. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, SUITABILITY, TITLE,
* NONINFRINGEMENT, OR THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
* SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
* THE SOFTWARE OR THE USE, INABILITY TO USE, OR OTHER DEALINGS IN THE SOFTWARE.
*
* 3. NONE OF THE AUTHORS, CONTRIBUTORS, NOR BRIGHTCOVE SHALL BE RESPONSIBLE
* IN ANY MANNER FOR USE OF THE SOFTWARE. THE SOFTWARE IS PROVIDED FOR YOUR
* CONVENIENCE AND ANY USE IS SOLELY AT YOUR OWN RISK. NO MAINTENANCE AND/OR
* SUPPORT OF ANY KIND IS PROVIDED FOR THE SOFTWARE.
*/
class BCMAPI
{
const ERROR_API_ERROR = 1;
const ERROR_DEPRECATED = 99;
const ERROR_DTO_DOES_NOT_EXIST = 12;
const ERROR_ID_NOT_PROVIDED = 2;
const ERROR_INVALID_FILE_TYPE = 5;
const ERROR_INVALID_METHOD = 3;
const ERROR_INVALID_PROPERTY = 4;
const ERROR_INVALID_TYPE = 6;
const ERROR_INVALID_UPLOAD_OPTION = 7;
const ERROR_READ_API_TRANSACTION_FAILED = 8;
const ERROR_READ_TOKEN_NOT_PROVIDED = 9;
const ERROR_SEARCH_TERMS_NOT_PROVIDED = 13;
const ERROR_WRITE_API_TRANSACTION_FAILED = 10;
const ERROR_WRITE_TOKEN_NOT_PROVIDED = 11;
public $page_number = NULL;
public $page_size = NULL;
public $total_count = NULL;
protected $api_calls = 0;
protected $bit32 = FALSE;
protected $media_delivery = 'default';
protected $secure = FALSE;
protected $show_notices = FALSE;
protected $timeout_attempts = 100;
protected $timeout_current = 0;
protected $timeout_delay = 1;
protected $timeout_retry = FALSE;
protected $token_read = NULL;
protected $token_write = NULL;
protected $url_read = 'api.brightcove.com/services/library?';
protected $url_write = 'api.brightcove.com/services/post';
protected $valid_types = array(
'playlist',
'video'
);
/**
* The constructor for the BCMAPI class.
* @access Public
* @since 0.1.0
* @param string [$token_read] The read API token for the Brightcove account
* @param string [$token_write] The write API token for the Brightcove account
*/
public function __construct($token_read = NULL, $token_write = NULL)
{
$this->token_read = $token_read;
$this->token_write = $token_write;
$this->bit32 = ((string)'99999999999999' == (int)'99999999999999') ? FALSE : TRUE;
}
/**
* Sets a property of the BCMAPI class.
* @access Public
* @since 1.0.0
* @param string [$key] The property to set
* @param mixed [$value] The new value for the property
* @return mixed The new value of the property
*/
public function __set($key, $value)
{
if(isset($this->$key) || is_null($this->$key))
{
$this->$key = $value;
} else {
throw new BCMAPIInvalidProperty($this, self::ERROR_INVALID_PROPERTY);
}
}
/**
* Retrieves a property of the BCMAPI class.
* @access Public
* @since 1.0.0
* @param string [$key] The property to retrieve
* @return mixed The value of the property
*/
public function __get($key)
{
if(isset($this->$key) || is_null($this->$key))
{
return $this->$key;
} else {
throw new BCMAPIInvalidProperty($this, self::ERROR_INVALID_PROPERTY);
}
}
/**
* Formats the request for any API 'Find' methods and retrieves the data.
* @access Public
* @since 0.1.0
* @param string [$call] The requested API method
* @param mixed [$params] A key-value array of API parameters, or a single value that matches the default
* @return object An object containing all API return data
*/
public function find($call, $params = NULL)
{
$call = strtolower(preg_replace('/(?:find|_)+/i', '', $call));
switch($call)
{
case 'allvideos':
$method = 'find_all_videos';
$get_item_count = TRUE;
break;
case 'videobyid':
$method = 'find_video_by_id';
$default = 'video_id';
$get_item_count = FALSE;
break;
case 'videobyidunfiltered':
$method = 'find_video_by_id_unfiltered';
$default = 'video_id';
$get_item_count = FALSE;
break;
case 'videosbyids':
$method = 'find_videos_by_ids';
$default = 'video_ids';
$get_item_count = FALSE;
break;
case 'videosbyidsunfiltered':
$method = 'find_videos_by_ids_unfiltered';
$default = 'video_ids';
$get_item_count = FALSE;
break;
case 'videobyreferenceid':
$method = 'find_video_by_reference_id';
$default = 'reference_id';
$get_item_count = FALSE;
break;
case 'videobyreferenceidunfiltered':
$method = 'find_video_by_reference_id_unfiltered';
$default = 'reference_id';
$get_item_count = FALSE;
break;
case 'videosbyreferenceids':
$method = 'find_videos_by_reference_ids';
$default = 'reference_ids';
$get_item_count = FALSE;
break;
case 'videosbyreferenceidsunfiltered':
$method = 'find_videos_by_reference_ids_unfiltered';
$default = 'reference_ids';
$get_item_count = FALSE;
break;
case 'videosbycampaignid':
$method = 'find_videos_by_campaign_id';
$default = 'campaign_id';
$get_item_count = TRUE;
break;
case 'videosbytags':
$method = 'find_videos_by_tags';
$default = 'or_tags';
$get_item_count = TRUE;
break;
case 'videosbytext':
$method = 'find_videos_by_text';
$default = 'text';
$get_item_count = TRUE;
break;
case 'videosbyuserid':
$method = 'find_videos_by_user_id';
$default = 'user_id';
$get_item_count = TRUE;
break;
case 'modifiedvideos':
$method = 'find_modified_videos';
$default = 'from_date';
$get_item_count = TRUE;
break;
case 'relatedvideos':
$method = 'find_related_videos';
$default = 'video_id';
$get_item_count = TRUE;
break;
case 'allplaylists':
$method = 'find_all_playlists';
$get_item_count = TRUE;
break;
case 'playlistbyid':
$method = 'find_playlist_by_id';
$default = 'playlist_id';
$get_item_count = FALSE;
break;
case 'playlistsbyids':
$method = 'find_playlists_by_ids';
$default = 'playlist_ids';
$get_item_count = FALSE;
break;
case 'playlistbyreferenceid':
$method = 'find_playlist_by_reference_id';
$default = 'reference_id';
$get_item_count = FALSE;
break;
case 'playlistsbyreferenceids':
$method = 'find_playlists_by_reference_ids';
$default = 'reference_ids';
$get_item_count = FALSE;
break;
case 'playlistsforplayerid':
$method = 'find_playlists_for_player_id';
$default = 'player_id';
$get_item_count = TRUE;
break;
default:
throw new BCMAPIInvalidMethod($this, self::ERROR_INVALID_METHOD);
break;
}
if(!isset($params))
{
$params = array();
} else {
if(!is_array($params))
{
$temp = $params;
$params = array();
$params[$default] = $temp;
}
}
if(isset($params['from_date']))
{
$params['from_date'] = (string)$params['from_date'];
if(strlen($params['from_date']) > 9)
{
$params['from_date'] = floor((int)$params['from_date'] / 60);
}
}
if(!isset($params['get_item_count']) && $get_item_count)
{
$params['get_item_count'] = 'TRUE';
}
if(!isset($params['media_delivery']) && $this->media_delivery != 'default')
{
$params['media_delivery'] = $this->media_delivery;
}
$url = $this->appendParams($method, $params);
$this->timeout_current = 0;
return $this->getData($url);
}
/**
* Finds all media assets in account, ignoring pagination.
* @access Public
* @since 0.3.6
* @param string [$type] The type of object to retrieve
* @param array [$params] A key-value array of API parameters
* @return object An object containing all API return data
*/
public function findAll($type = 'video', $params = NULL)
{
$this->timeout_current = 0;
$this->validType($type);
if(!isset($params))
{
$params = array();
}
$params['get_item_count'] = 'TRUE';
$params['page_number'] = 0;
if(!isset($params['page_size']) || $params['page_size'] > 100)
{
$params['page_size'] = 100;
}
if(!isset($params['media_delivery']) && $this->media_delivery != 'default')
{
$params['media_delivery'] = $this->media_delivery;
}
$assets = array();
$current_page = 0;
$total_count = 0;
$total_page = 1;
while($current_page < $total_page)
{
$params['page_number'] = $current_page;
$url = $this->appendParams(strtolower('find_all_' . $type . 's'), $params);
$result = $this->getData($url);
if($total_count < 1)
{
$total_count = $this->total_count;
$total_page = ceil($total_count / $params['page_size']);
}
if(is_array($result))
{
foreach($result as $asset)
{
$assets[] = $asset;
}
}
$current_page++;
}
$this->timeout_current = 0;
return $assets;
}
/**
* Performs a search of video meta data
* @access Public
* @since 1.1.1
* @param string [$type] The type of objects to retrieve
* @param array [$terms] The terms to use for the search
* @param mixed [$params] A key-value array of API parameters
* @return object An object containing all API return data
*/
public function search($type = 'video', $terms = NULL, $params = NULL)
{
if(!isset($terms) || !is_array($terms))
{
throw new BCMAPISearchTermsNotProvided($this, self::ERROR_SEARCH_TERMS_NOT_PROVIDED);
}
if(!isset($params))
{
$params = array();
} else {
if(!is_array($params))
{
$temp = $params;
$params = array();
$params[$default] = $temp;
}
}
if(!isset($params['get_item_count']))
{
$params['get_item_count'] = 'TRUE';
}
foreach($terms as $key => $value)
{
if(strpos($value, ',') !== FALSE)
{
$i = 0;
$parts = explode(',', $value);
foreach($parts as $part)
{
if($i == 0)
{
$params[$key] = $part;
$i++;
} else {
$params[$key] .= '%26' . $key . '%3D' . $part;
}
}
} else {
$params[$key] = $value;
}
}
if (isset($params['sort_by']) && isset($params['sort_order'])) {
$params['sort_by'] .= (':'.$params['sort_order']);
unset($params['sort_order']);
}
$url = str_replace(array('%2526', '%253D'), array('&', '='), $this->appendParams('search_' . $type . 's', $params));
$this->timeout_current = 0;
return $this->getData($url);
}
/**
* Uploads a media asset file to Brightcove.
* @access Public
* @since 1.0.0
* @param string [$type] The type of object to upload
* @param string [$file] The location of the temporary file
* @param array [$meta] The media asset information
* @param array [$options] Optional upload values
* @return string The media asset ID
*/
public function createMedia($type = 'video', $file = NULL, $meta, $options = NULL)
{
if(strtolower($type) == 'video')
{
if(isset($file))
{
preg_match('/(\.f4a|\.f4b|\.f4v|\.f4p|\.flv)*$/i', $file, $invalid_extensions);
if(isset($invalid_extensions[1]))
{
if(isset($options['encode_to']))
{
unset($options['encode_to']);
throw new BCMAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION);
}
if(isset($options['create_multiple_renditions']))
{
$options['create_multiple_renditions'] = 'FALSE';
throw new BCMAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION);
}
if(isset($options['preserve_source_rendition']))
{
unset($options['preserve_source_rendition']);
throw new BCMAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION);
}
}
if((isset($options['create_multiple_renditions']) && $options['create_multiple_renditions'] === TRUE) && (isset($options['H264NoProcessing']) && $options['H264NoProcessing'] === TRUE))
{
unset($options['H264NoProcessing']);
throw new BCMAPIInvalidUploadOption($this, self::ERROR_INVALID_UPLOAD_OPTION);
}
}
} else {
throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE);
}
$request = array();
$post = array();
$params = array();
$media = array();
foreach($meta as $key => $value)
{
$media[$key] = $value;
}
if(!isset($media['name']) || is_null($media['name']) || $media['name'] == '')
{
$media['name'] = time();
}
if(!isset($media['shortDescription']) || is_null($media['shortDescription']) || $media['shortDescription'] == '')
{
$media['shortDescription'] = time();
}
if(isset($options))
{
foreach($options as $key => $value)
{
$params[$key] = $value;
}
}
$params['token'] = $this->token_write;
$params[strtolower($type)] = $media;
$post['method'] = strtolower('create_' . $type);
$post['params'] = $params;
$request['json'] = json_encode($post);
if(isset($file))
{
// Added for PHP 5.5+ support.
if (is_string($file) && function_exists('curl_file_create')) {
$file = curl_file_create($file);
} else {
$file = '@' . $file;
}
$request['file'] = $file;
}
return (string)$this->putData($request)->result;
}
/**
* Creates a playlist.
* @access Public
* @since 0.3.0
* @param string [$type] The type of playlist to create
* @param array [$meta] The playlist information
* @return string The playlist ID
*/
public function createPlaylist($type = 'video', $meta)
{
$request = array();
$post = array();
$params = array();
$media = array();
foreach($meta as $key => $value)
{
$media[$key] = $value;
}
if(strtolower($type) == 'video')
{
if(isset($media['videoIds']))
{
foreach($media['videoIds'] as $key => $value)
{
$media['videoIds'][$key] = $value;
}
}
$params['playlist'] = $media;
$post['method'] = 'create_playlist';
} else {
throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE);
}
$params['token'] = $this->token_write;
$post['params'] = $params;
$request['json'] = json_encode($post);
return (string)$this->putData($request)->result;
}
/**
* Uploads a media image file to Brightcove.
* @access Public
* @since 0.3.4
* @param string [$type] The type of object to upload image for
* @param mixed [$file] The location of the temporary file or a CURLFile object
* @param array [$meta] The image information
* @param int [$id] The ID of the media asset to assign the image to
* @param string [$ref_id] The reference ID of the media asset to assign the image to
* @param bool [$resize] Whether or not to resize the image on upload
* @return mixed The image asset
*/
public function createImage($type = 'video', $file = NULL, $meta, $id = NULL, $ref_id = NULL, $resize = TRUE)
{
$request = array();
$post = array();
$params = array();
$media = array();
if(strtolower($type) == 'video')
{
$post['method'] = 'add_image';
} else {
throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE);
}
foreach($meta as $key => $value)
{
$media[$key] = $value;
}
if(isset($id))
{
$params[strtolower($type) . '_id'] = $id;
} elseif(isset($ref_id)) {
$params[strtolower($type) . '_reference_id'] = $ref_id;
} else {
throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED);
}
if($resize)
{
$params['resize'] = 'TRUE';
} else {
$params['resize'] = 'FALSE';
}
$params['token'] = $this->token_write;
$params['image'] = $media;
$post['params'] = $params;
$request['json'] = json_encode($post) . "\n";
if(isset($file))
{
$request['file'] = is_string($file) ? '@' . $file : $file;
}
return $this->putData($request)->result;
}
/**
* Uploads a logo overlay file to Brightcove.
* @access Public
* @since 1.1.0
* @param string [$file] The location of the temporary file
* @param array [$meta] The logo overlay information
* @param int [$id] The ID of the media asset to assign the logo overlay to
* @param string [$ref_id] The reference ID of the media asset to assign the logo overlay to
* @return mixed The logo overlay asset
*/
public function createOverlay($file = NULL, $meta, $id = NULL, $ref_id = NULL)
{
$request = array();
$post = array();
$params = array();
$media = array();
$post['method'] = 'add_logo_overlay';
foreach($meta as $key => $value)
{
$media[$key] = $value;
}
if(isset($id))
{
$params['video_id'] = $id;
} elseif(isset($ref_id)) {
$params['video_reference_id'] = $ref_id;
} else {
throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED);
}
$params['token'] = $this->token_write;
$params['logooverlay'] = $media;
$post['params'] = $params;
$request['json'] = json_encode($post) . "\n";
if(isset($file))
{
$request['file'] = '@' . $file;
}
return $this->putData($request)->result;
}
/**
* Deletes a logo overlay.
* @access Public
* @since 1.1.0
* @param int [$id] The ID of the media asset
* @param string [$ref_id] The reference ID of the media asset
* @param array [$options] Optional values
*/
public function deleteOverlay($id = NULL, $ref_id = NULL, $options = NULL)
{
$request = array();
$post = array();
$params = array();
$params['token'] = $this->token_write;
if(isset($options))
{
foreach($options as $key => $value)
{
$params[$key] = $value;
}
}
if(isset($id))
{
$params['video_id'] = $id;
} elseif(isset($ref_id)) {
$params['video_reference_id'] = $ref_id;
} else {
throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED);
}
$post['method'] = strtolower('remove_logo_overlay');
$post['params'] = $params;
$request['json'] = json_encode($post) . "\n";
return $this->putData($request, FALSE);
}
/**
* Updates a media asset.
* @access Public
* @since 0.3.0
* @param string [$type] The type of object to update
* @param array [$meta] The information for the media asset
* @return object The new DTO
*/
public function update($type = 'video', $meta)
{
$this->validType($type);
$request = array();
$post = array();
$media = array();
$params = array();
foreach($meta as $key => $value)
{
$media[$key] = $value;
}
$params['token'] = $this->token_write;
$params[strtolower($type)] = $media;
$post['method'] = strtolower('update_' . $type);
$post['params'] = $params;
$request['json'] = json_encode($post) . "\n";
return $this->putData($request)->result;
}
/**
* Deletes a media asset.
* @access Public
* @since 0.3.0
* @param string [$type] The type of item to delete
* @param int [$id] The ID of the media asset
* @param string [$ref_id] The reference ID of the media asset
* @param array [$options] Optional values
*/
public function delete($type = 'video', $id = NULL, $ref_id = NULL, $options = NULL)
{
$this->validType($type);
$request = array();
$post = array();
$params = array();
$params['token'] = $this->token_write;
if(isset($options))
{
foreach($options as $key => $value)
{
$params[$key] = $value;
}
}
if(isset($id))
{
$params[strtolower($type . '_id')] = $id;
} elseif(isset($ref_id)) {
$params['reference_id'] = $ref_id;
} else {
throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED);
}
$post['method'] = strtolower('delete_' . $type);
$post['params'] = $params;
$request['json'] = json_encode($post) . "\n";
return $this->putData($request, FALSE);
}
/**
* Retrieves the status of a media asset upload.
* @access Public
* @since 0.3.9
* @param string [$type] The type of object to check
* @param int [$id] The ID of the media asset
* @param string [$ref_id] The reference ID of the media asset
* @return string The upload status
*/
public function getStatus($type = 'video', $id = NULL, $ref_id = TRUE)
{
if(!isset($id) && !isset($ref_id))
{
throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED);
}
$request = array();
$post = array();
$params = array();
$params['token'] = $this->token_write;
if(isset($id))
{
$params[strtolower($type) . '_id'] = $id;
}
if(isset($ref_id))
{
$params['reference_id'] = $ref_id;
}
if(strtolower($type) == 'video')
{
$post['method'] = 'get_upload_status';
} else {
throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE);
}
$post['params'] = $params;
$request['json'] = json_encode($post) . "\n";
return $this->putData($request)->result;
}
/**
* Shares a media asset with the selected accounts.
* @access Public
* @since 1.0.0
* @param string [$type] The type of object to check
* @param int [$id] The ID of the media asset
* @param array [$account_ids] An array of account IDs
* @param bool [$accept] Whether the share should be auto accepted
* @param bool [$force] Whether the share should overwrite existing copies of the media
* @return array The new media asset IDs
*/
public function shareMedia($type = 'video', $id, $account_ids, $accept = FALSE, $force = FALSE)
{
if(!isset($id))
{
throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED);
}
if(!is_array($account_ids))
{
$account_ids = array($account_ids);
}
$request = array();
$post = array();
$params = array();
$params['token'] = $this->token_write;
$params['sharee_account_ids'] = $account_ids;
if($accept)
{
$params['auto_accept'] = 'TRUE';
} else {
$params['auto_accept'] = 'FALSE';
}
if($force)
{
$params['force_reshare'] = 'TRUE';
} else {
$params['force_reshare'] = 'FALSE';
}
if(strtolower($type) == 'video')
{
$params['video_id'] = $id;
$post['method'] = 'share_video';
} else {
throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE);
}
$post['params'] = $params;
$request['json'] = json_encode($post) . "\n";
return $this->putData($request)->result;
}
/**
* Removes assets from a playlist
* @access Public
* @since 1.0.8
* @param int [$playlist_id] The ID of the playlist to modify
* @param array [$video_ids] An array of video IDs to delete from the playlist
* @return object The new playlist DTO
*/
public function removeFromPlaylist($playlist_id, $video_ids)
{
if(!isset($playlist_id))
{
throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED);
}
if(!is_array($video_ids))
{
$video_ids = array($video_ids);
}
$safe_videos = array();
$meta = array(
'playlist_id' => $playlist_id,
'fields' => 'videoIds'
);
$playlist = $this->find('playlistById', $meta);
if(!isset($playlist))
{
throw new BCMAPIDtoDoesNotExist($this, self::ERROR_DTO_DOES_NOT_EXIST);
}
foreach($playlist->videoIds as $video)
{
if(!in_array($video, $video_ids))
{
$safe_videos[] = $video;
}
}
$new_meta = array(
'id' => $playlist_id,
'videoIds' => $safe_videos
);
return $this->update('playlist', $new_meta);
}
/**
* Adds assets to a playlist
* @access Public
* @since 1.0.8
* @param int [$playlist_id] The ID of the playlist to modify
* @param array [$video_ids] An array of video IDs to add to the playlist
* @return object The new playlist DTO
*/
public function addToPlaylist($playlist_id, $video_ids)
{
if(!isset($playlist_id))
{
throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED);
}
if(!is_array($video_ids))
{
$video_ids = array($video_ids);
}
$meta = array(
'playlist_id' => $playlist_id,
'fields' => 'videoIds'
);
$playlist = $this->find('playlistById', $meta);
if(!isset($playlist))
{
throw new BCMAPIDtoDoesNotExist($this, self::ERROR_DTO_DOES_NOT_EXIST);
}
foreach($video_ids as $video)
{
$playlist->videoIds[] = $video;
}
$new_meta = array(
'id' => $playlist_id,
'videoIds' => $playlist->videoIds
);