forked from tamw-wnet/PBS_Media_Manager_Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-PBS-Media-Manager-API-Client.php
1241 lines (1163 loc) · 33 KB
/
class-PBS-Media-Manager-API-Client.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
// @codingStandardsIgnoreFile
/**
* @file
* PBS Media Manager API Client.
*
* Authors: William Tam ([email protected]), Augustus Mayo ([email protected]),
* Aaron Crosman ([email protected]), Jess Snyder ([email protected])
* version 2.0.5 2021-04-13
*/
/**
* Class PBS_Media_Manager_API_Client.
*/
class PBS_Media_Manager_API_Client {
private $client_id;
private $client_secret;
private $base_endpoint;
private $auth_string;
public $valid_endpoints;
public $passport_windows;
public $asset_types;
public $episode_asset_types;
public $video_profiles;
public $file_types;
/**
* PBS_Media_Manager_API_Client constructor.
*
* @param string $client_id
* Client ID.
* @param string $client_secret
* Client Secret.
* @param string $base_endpoint
* Base Endpoint.
*/
public function __construct($client_id = '', $client_secret = '', $base_endpoint = '') {
$this->client_id = $client_id;
$this->client_secret = $client_secret;
$this->base_endpoint = $base_endpoint;
$this->auth_string = $this->client_id . ":" . $this->client_secret;
// Constants.
$this->valid_endpoints = array(
'assets',
'episodes',
'specials',
'collections',
'seasons',
'remote-assets',
'shows',
'franchises',
'stations',
'changelog',
);
$this->passport_windows = array(
'public',
'all_members',
'station_members',
'unavailable',
);
$this->asset_types = array('preview', 'clip', 'extra');
$this->episode_asset_types = array(
'preview',
'clip',
'extra',
'full_length',
);
$this->video_profiles = array(
'hd-1080p-mezzanine-16x9',
'hd-1080p-mezzanine-4x3',
'hd-mezzanine-16x9',
'hd-mezzanine-4x3',
);
$this->file_types = array('video', 'caption');
// 'image' will be added when the api can handle it properly.
}
/**
* Build the curl handle.
*
* @param string $url
* The URL.
*
* @return resource
* The curl resource.
*/
private function build_curl_handle($url) {
if (!function_exists('curl_init')) {
die('the curl library is required for this client to work');
}
$ch = curl_init();
if (!$ch) {
die('could not initialize curl');
}
curl_setopt($ch, CURLOPT_URL, $url);
// Method and headers can be different, but these are always the same.
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $this->auth_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
return $ch;
}
/**
* Reformat API responses as an array.
*
* @param string $response
* The response from the API.
*
* @return array
* The response formatted as an array.
*/
private function make_response_array($response) {
$myarray = array();
$data = explode("\n", $response);
if (strpos($data[0], 'HTTP') === 0) {
// the first line is a status code
$myarray['status'] = $data[0];
array_shift($data);
}
foreach ($data as $part) {
if (empty(trim($part))) {
continue;
}
if (json_decode($part)) {
$myarray[] = json_decode($part);
continue;
}
$middle = explode(": ", $part, 2);
if (isset($middle[1])) {
$myarray[trim($middle[0])] = trim($middle[1]);
} else {
$myarray[] = trim($middle[0]);
}
}
return $myarray;
}
/**
* Get request.
*
* @param string $query
* The querystring.
*
* @return array|mixed
* The result from the API.
*/
public function get_request($query) {
$request_url = $this->base_endpoint . $query;
$ch = $this->build_curl_handle($request_url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
$errors = curl_error($ch);
curl_close($ch);
$json = json_decode($result, TRUE);
if (empty($json)) {
$result = $this->make_response_array($result);
return array(
'errors' => array(
'info' => $info,
'errors' => $errors,
'response' => $result,
),
);
}
if ($info['http_code'] != 200) {
return array(
'errors' => array(
'info' => $info,
'errors' => $errors,
'response' => $json,
),
);
}
return $json;
}
/**
* Main constructor for creating elements.
*
* Asset, episode, special, collection, season.
*
* @param string $parent_id
* The parent id. Can also be a slug.
* @param string $parent_type
* The parent type.
* @param string $type
* The type.
* @param array $attribs
* The attributes.
*
* @return array
* On success returns the url path of the editable asset.
*/
public function create_child($parent_id, $parent_type, $type, $attribs = array()) {
$endpoint = "/" . $parent_type . "s/" . $parent_id . "/" . $type . "s/";
$data = array(
"data" => array(
"type" => $type,
"attributes" => $attribs,
),
);
/* in the MM API, create is a POST */
$payload_json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$request_url = $this->base_endpoint . $endpoint;
$ch = $this->build_curl_handle($request_url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload_json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($payload_json)));
$result = curl_exec($ch);
$info = curl_getinfo($ch);
$errors = curl_error($ch);
curl_close($ch);
if (!in_array($info['http_code'], array(200, 201, 202, 204))) {
$result = $this->make_response_array($result);
return array(
'errors' => array(
'info' => $info,
'errors' => $errors,
'result' => $result,
),
);
}
/*
* A successful request will return a 20x and the location of the created
* object.
* We'll follow that location and parse the resulting JSON to return the
* cid.
*/
// Get just the URI.
$matches = array();
preg_match("/(Location|URI): .*?\/([a-f0-9\-]+)\/(edit\/)?(\r|\n|\r\n)/i", $result, $matches);
// TODO: Unsafe indexing, how should errors be handled?
return $matches[2];
}
/**
* Get update endpoint.
*
* @param string $id
* The ID.
* @param string $type
* The type.
*
* @return string
* The update endpoint.
*/
private function _get_update_endpoint($id, $type) {
$endpoint = "/" . $type . "s/" . $id . "/";
if ($type == 'asset') {
$endpoint .= "edit/";
}
return $endpoint;
}
/**
* Get updatable object.
*
* @param string $id
* The ID.
* @param string $type
* The type.
*
* @return array|mixed
* The updatable object.
*/
public function get_updatable_object($id, $type) {
return $this->get_request(
$this->_get_update_endpoint($id, $type)
);
}
/**
* Modify query strings for submission to the API.
*
* @param array $args
* The arguments for the query.
*
* @return mixed|string
* The modified query.
*/
public function build_pbs_querystring($args) {
$querystring = !empty($args) ? "?" . http_build_query($args) : "";
// PBS's endpoints don't like encoded entities.
$querystring = str_replace("%3A", ":", $querystring);
$querystring = str_replace("%3D", "=", $querystring);
$querystring = str_replace("%26", "&", $querystring);
$querystring = str_replace("%2C", ",", $querystring);
$querystring = str_replace("%28", "(", $querystring);
$querystring = str_replace("%29", ")", $querystring);
// special case for audience-scope[x], platform-slug[x], etc
$querystring = preg_replace("/(%5B\d+%5D)/", "", $querystring);
return $querystring;
}
/**
* Main constructor for updating objects.
*
* Asset, episode, special, collection, season.
*
* @param string $id
* The ID.
* @param string $type
* The type.
* @param array $attribs
* The attributes.
*
* @return array|bool
* A successful request will return a 20x and nothing else.
*/
public function update_object($id, $type, $attribs = array()) {
/* In the MM API, update is a PATCH. */
$endpoint = $this->_get_update_endpoint($id, $type);
$data = array(
"data" => array(
"type" => $type,
"id" => $id,
"attributes" => $attribs,
),
);
$payload_json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$request_url = $this->base_endpoint . $endpoint;
$ch = $this->build_curl_handle($request_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload_json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($payload_json)));
$result = curl_exec($ch);
$info = curl_getinfo($ch);
$errors = curl_error($ch);
curl_close($ch);
if (!in_array($info['http_code'], array(200, 201, 202, 204))) {
$result = $this->make_response_array($result);
return array(
'errors' => array(
'info' => $info,
'errors' => $errors,
'result' => $result,
),
);
}
/* successful request will return a 20x and nothing else */
return TRUE;
}
/**
* Delete an object.
*
* @param string $id
* The ID.
* @param string $type
* The type.
*
* @return array|bool
* A successful request will return a 20x and nothing else.
*/
public function delete_object($id, $type) {
$endpoint = "/" . $type . "/" . $id . "/";
$request_url = $this->base_endpoint . $endpoint;
$ch = $this->build_curl_handle($request_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
$result = curl_exec($ch);
$info = curl_getinfo($ch);
$errors = curl_error($ch);
curl_close($ch);
if (!in_array($info['http_code'], array(200, 201, 202, 204))) {
$result = $this->make_response_array($result);
return array(
'errors' => array(
'info' => $info,
'errors' => $errors,
'result' => $result,
),
);
}
/* successful request will return a 20x and nothing else */
return TRUE;
}
/**
* Main constructor for getting single items.
*
* Asset, episode, special, collection, season, show, franchise, station.
*
* @param string $id
* The ID. Can also be a slug.
* @param string $type
* The type.
* @param bool $private
* Whether the item is private.
* @param array $queryargs
* The arguments for the query.
*
* @return array|mixed
* The items.
*/
public function get_item_of_type($id, $type, $private = FALSE, $queryargs = array()) {
$endpoint = "/" . $type . "s/" . $id . "/";
// Unpublished, 'private' items have to do a GET on the update endpoint.
if ($private === TRUE) {
$endpoint = $this->_get_update_endpoint($id, $type);
}
if (empty($queryargs) && is_array($private)) {
$queryargs = $private;
}
$querystring = $this->build_pbs_querystring($queryargs);
return $this->get_request($endpoint . $querystring);
}
/**
* Main constructor for lists.
*
* @param string $endpoint
* The endpoint.
* @param array $args
* The arguments. If a value is given for $args['page'], only the
* page number will be returned.
* @param bool $include_metadata
* Option to include metadata in the results.
*
* @return array
* An array of list of items.
*/
public function get_list_data($endpoint, $args = array(), $include_metadata
= FALSE) {
/* By default only return the actual data, stripping meta and pagination
* data including all results. If a value is given for page
* only return page number. If include_metadata is true, return fields from
* the first page of results.
*/
$result_data = array();
$meta_data = array();
$limit_pages = FALSE;
$page = 1;
/* NULL args are interpreted as strings, throwing errors. Force it to be
* an array.
*/
if (empty($args)) {
$args = array();
}
if (empty($args['page'])) {
/* If we get no specific page
* start with page 1 and keep going. */
$args['page'] = $page;
}
else {
$limit_pages = TRUE;
}
while ($page) {
$querystring = $this->build_pbs_querystring($args);
$rawdata = $this->get_request($endpoint . $querystring);
if (empty($rawdata['data'])) {
return $rawdata;
}
$this_set = $rawdata['data'];
foreach ($this_set as $entry) {
$result_data[] = $entry;
}
if ($include_metadata && empty($meta_data)) {
$meta_data = array(
'links' => $rawdata['links'],
'meta' => $rawdata['meta'],
'jsonapi' => $rawdata['jsonapi'],
);
}
if (!empty($rawdata['links']['next']) && !$limit_pages) {
$page++;
$args['page'] = $page;
}
else {
$page = 0;
}
}
if ($include_metadata) {
$meta_data['data'] = $result_data;
return $meta_data;
}
return $result_data;
}
/**
* Main constructor for child items.
*
* @param string $parent_id
* Parent ID. Can also be a slug, but generally won't be.
* @param string $parent_type
* Parent type.
* @param string $type
* Type.
* @param array $queryargs
* The arguments for the query.
* @param bool $include_metadata
* Option to include metadata in the results.
*
* @return array
* An array of items.
*/
public function get_child_items_of_type($parent_id, $parent_type, $type, $queryargs = array(), $include_metadata = FALSE) {
$query = "/" . $parent_type . "s/" . $parent_id . "/" . $type . "s/";
return $this->get_list_data($query, $queryargs, $include_metadata);
}
/**
* Helper function for cleaning up arguments.
*
* @param string $asset_type_list
* A comma-delimited list of asset types.
* @param string $container_type
* The type of container. Defaults to episode.
*
* @return array|bool
* An array of asset types.
*/
public function validate_asset_type_list($asset_type_list, $container_type = 'episode') {
$valid_asset_types = $this->asset_types;
if ($container_type == 'episode' || $container_type == 'special') {
$valid_asset_types = $this->episode_asset_types;
}
if ($asset_type_list == 'all') {
return $valid_asset_types;
}
$typelist = explode(',', $asset_type_list);
foreach ($typelist as $type) {
if (!in_array($type, $valid_asset_types)) {
return FALSE;
}
}
return $typelist;
}
/**
* Main constructor for getting child assets.
*
* @param string $parent_id
* Parent ID.
* @param string $parent_type
* Parent type.
* @param string $asset_type
* Asset type.
* @param string $window
* The availability window.
* @param array $queryargs
* The arguments for the query.
*
* @return array|bool
* Returns an array of child assets.
*/
public function get_child_assets($parent_id, $parent_type = 'episode', $asset_type = 'all', $window = 'all', $queryargs = array()) {
$asset_types = $this->validate_asset_type_list($asset_type, $parent_type);
if (!$asset_types) {
return FALSE;
}
$windows = $this->passport_windows;
if ($window !== 'all') {
// Validate and construct the window arg.
$requested_windows = explode(',', $window);
foreach ($requested_windows as $req_window) {
if (!in_array($req_window, $windows)) {
return array('errors' => 'invalid window');
}
}
$windows = $requested_windows;
}
$result_data = array();
$raw_result = $this->get_child_items_of_type($parent_id, $parent_type, 'asset', $queryargs);
if (!empty($raw_result['errors'])) {
return $raw_result;
}
foreach ($raw_result as $result) {
// Ignore non-list data.
if (empty($result['attributes'])) {
continue;
}
// Only include the right asset_types.
if (!in_array($result['attributes']['object_type'], $asset_types)) {
continue;
}
// Only include the right windows.
/* Not yet implemented in API.
* if (!in_array($result['attributes']['mvod_window'], $windows) ) {
* continue;
* }
*/
$result_data[] = $result;
}
$result_data = empty($result_data) ? FALSE : $result_data;
return $result_data;
}
/**
* Images are handled very differently from 'assets'.
*
* @param string $parent_id
* Parent ID.
* @param string $parent_type
* Parent type.
* @param string $image_profile
* A single image to extract.
*
* @return array
* Returns an array of images, or the single image profile requested.
*/
public function get_images($parent_id, $parent_type, $image_profile = '') {
$returnary = array();
$parent = $this->get_item_of_type($parent_id, $parent_type);
if (empty($parent['data']['attributes']['images'])) {
return $returnary;
}
foreach ($parent['data']['attributes']['images'] as $image) {
if (!empty($image_profile)) {
if (stristr($image['profile'], $image_profile)) {
return $image;
}
}
else {
$returnary[] = $image;
}
}
return $returnary;
}
/* Special functions */
/**
* Extract a specific image from an object.
*
* Similar to get_images above, but instead of returning a list of images via
* a new request, it extracts a specific image from a previous request.
*
* @param array $response_object
* The response object provided by a previous request.
* @param string $image_profile
* The name of a specific image profile to retreive.
*
* @return array|bool
* The image array for the provided profile.
*/
public static function extract_image($response_object, $image_profile) {
// If there are no images on the response_object bail.
if (empty($response_object['attributes']['images'])) {
return FALSE;
}
// Check the images for the one we want.
foreach ($response_object['attributes']['images'] as $image) {
if (stristr($image['profile'], $image_profile)) {
return $image;
}
}
// If we didn't find an image default to False.
return FALSE;
}
/**
* Use PBS's image server to resize, crop, and otherwise alter images.
*
* This function uses PBS's image handler service to adjust images
* automatically. It also forces HTTPS on all URLs. Note that the resize
* function maintains aspect ratios and so generated images may not conform
* to the exact sizes provided to this function.
*
* @param string $image_url
* The initial URL for the image from PBS's image service.
* @param string $operation
* Crop or Resize to adjust the images.
* @param int $width
* The desired width of the image.
* @param int $height
* The desired height of the image.
* @param string $type
* The image type to convert the image to, maintains default if not set.
*/
public static function alter_pbs_image($image_url, $operation, $width, $height, $type = '') {
if ($type == '') {
$list = explode('.', $image_url);
$extension = end($list);
}
else {
$extension = $type;
}
// PBS supports HTTPS, so use it.
$image_url = str_replace("http://", "https://", $image_url);
$new_url = $image_url . '.' . $operation . '.' . $width . "x" . $height . '.' . $extension;
return $new_url;
}
/**
* Legacy function to get assets by TP Media Object ID.
*
* @param string $tp_media_id
* TP Media Object ID.
*
* @return array|mixed
* Returns an asset.
*/
public function get_asset_by_tp_media_id($tp_media_id) {
/* Returns the corresponding asset if it exists. Note that they're
* calling it tp_media_id, NOT tp_media_object_id */
$query = "/assets/legacy/?tp_media_id=" . $tp_media_id;
$response = $this->get_request($query);
if (!empty($response["errors"]["info"]["http_code"]) && $response["errors"]["info"]["http_code"] == 404) {
// If this video is private/unpublished, retry the edit endpoint.
$output_array = array();
preg_match("/.*?(\/assets\/.*)\/$/", $response["errors"]["info"]["url"], $output_array);
if (!empty($output_array[1])) {
$response = $this->get_request($output_array[1] . "/edit/");
}
}
return $response;
}
/**
* Legacy function to get a show by program ID.
*
* @param string $program_id
* Program ID.
*
* @return array|mixed
* Returns the corresponding show if it exists.
*/
public function get_show_by_program_id($program_id) {
/* Note that they're calling it content_channel_id, NOT program_id */
$query = "/shows/legacy/?content_channel_id=" . $program_id;
return $this->get_request($query);
}
/**
* Get the changelog.
*
* @param array $args
* Possible elements are type (episode|asset|etc), action
* (updated|deleted), id, since (timestamp in %Y-%m-%dT%H:%M:%S format).
* All can be combined and multiple except 'since'.
*
* @return array
* Returns the changelog.
*/
public function get_changelog($args = array()) {
if (empty($args['since'])) {
// Default 'since' to be in the last 8hrs.
$timezone = new DateTimeZone('UTC');
$datetime = new DateTime("-24 hour", $timezone);
$since = $datetime->format('Y-m-d\TH:i:s.u\Z');
$args['since'] = $since;
}
$query = "/changelog/";
return $this->get_list_data($query, $args);
}
/* SHORTCUT FUNCTIONS */
/* Shortcut functions for single items. */
/**
* Get a single asset.
*
* @param string $id
* The ID.
* @param bool $private
* Whether the asset is private.
* @param array $queryargs
* The query arguments.
*
* @return array|mixed
* Returns the asset.
*/
public function get_asset($id, $private = FALSE, $queryargs = array()) {
return $this->get_item_of_type($id, 'asset', $private, $queryargs);
}
/**
* Get a single episode.
*
* @param string $id
* The ID.
* @param array $queryargs
* The query arguments.
*
* @return array|mixed
* Returns the episode.
*/
public function get_episode($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'episode', $queryargs);
}
/**
* Get a single special.
*
* @param string $id
* The ID.
* @param array $queryargs
* The query arguments.
*
* @return array|mixed
* Returns the special.
*/
public function get_special($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'special', $queryargs);
}
/**
* Get a single collection.
*
* @param string $id
* The ID.
* @param array $queryargs
* The query arguments.
*
* @return array|mixed
* Returns the collection.
*/
public function get_collection($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'collection', $queryargs);
}
/**
* Get a single season.
*
* @param string $id
* The ID.
* @param array $queryargs
* The query arguments.
*
* @return array|mixed
* Returns the season.
*/
public function get_season($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'season', $queryargs);
}
/**
* Get a single show.
*
* @param string $id
* The ID.
* @param array $queryargs
* The query arguments.
*
* @return array|mixed
* Returns the show.
*/
public function get_show($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'show', $queryargs);
}
/**
* Get a single remote asset.
*
* @param string $id
* The ID.
* @param array $queryargs
* The query arguments.
*
* @return array|mixed
* Returns the asset.
*/
public function get_remote_asset($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'remote-asset', $queryargs);
}
/**
* Get a single franchise.
*
* @param string $id
* The ID.
* @param array $queryargs
* The query arguments.
*
* @return array|mixed
* Returns the asset.
*/
public function get_franchise($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'franchise', $queryargs);
}
/**
* Get a single station.
*
* @param string $id
* The ID.
* @param array $queryargs
* The query arguments.
*
* @return array|mixed
* Returns the station.
*/
public function get_station($id, $queryargs = array()) {
return $this->get_item_of_type($id, 'station', $queryargs);
}
/* Shortcut functions for lists. */
/* Special cases -- franchises and shows. */
/**
* Get a list of franchises.
*
* NOTE: Franchises have no parent object.
*
* @param array $queryargs
* The query arguments.
*
* @return array
* Returns a list of franchises.
*/
public function get_franchises($queryargs = array()) {
$query = "/franchises/";
return $this->get_list_data($query, $queryargs);
}
/**
* Get a list of shows.
*
* NOTE: Shows do not have to have a parent object.
*
* @param array $queryargs
* The query arguments.
*
* @return array
* Returns a list of shows.
*/
public function get_shows($queryargs = array()) {
$query = "/shows/";
return $this->get_list_data($query, $queryargs);
}
/**
* Get a list of assets.
*
* @param array $queryargs
* The query arguments. For example, show-id or type.
*
* @return array
* Returns a list of assets.
*/
public function get_assets($queryargs = array()) {
$query = "/assets/";
return $this->get_list_data($query, $queryargs);
}
/* Shortcut functions for lists of child objects. */
/**
* Get the shows that belong to a specific franchise.
*
* @param string $franchise_id
* The franchise ID.
* @param array $queryargs
* The query arguments.
*
* @return array
* Returns a list of shows.
*/
public function get_franchise_shows($franchise_id, $queryargs = array()) {
return $this->get_child_items_of_type($franchise_id, 'franchise', 'show', $queryargs);
}
/**
* Get the seasons for a specific show.
*
* @param string $show_id
* The show ID.
* @param array $queryargs
* The query arguments.
*
* @return array
* Returns a list of seasons.
*/
public function get_show_seasons($show_id, $queryargs = array()) {
return $this->get_child_items_of_type($show_id, 'show', 'season', $queryargs);
}
/**
* Get the specials for a specific show.
*
* @param string $show_id
* The show ID.
* @param array $queryargs
* The query arguments.
*
* @return array
* Returns a list of specials.
*/
public function get_show_specials($show_id, $queryargs = array()) {