From bccfb1ccc8e07ac714f361b3a2d08ef4fd277f5f Mon Sep 17 00:00:00 2001 From: cp6 Date: Sat, 25 Sep 2021 11:18:58 +1000 Subject: [PATCH 1/9] Added some video stream call examples Added some video stream call examples --- example.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/example.php b/example.php index e1f8b2f..f1f5ff9 100644 --- a/example.php +++ b/example.php @@ -108,4 +108,28 @@ //Delete folders (only works if folder empty) echo $bunny->deleteFolder('pets/puppy_fluffy/'); -echo $bunny->deleteFolder('pets/'); \ No newline at end of file +echo $bunny->deleteFolder('pets/'); + + +/* + * + * Video stream API examples + * + */ + +//List collections for library 1234 +echo json_encode($bunny->getStreamCollections(1234)); + +//List videos for library 1234 and collection 886gce58-1482-416f-b908-fca0b60f49ba +$bunny->setStreamLibraryId(1234); +$bunny->setStreamCollectionGuid('886gce58-1482-416f-b908-fca0b60f49ba'); +echo json_encode($bunny->listVideosForCollectionId()); + +//List video information individually +echo json_encode($bunny->getVideo(1234,'e6410005-d591-4a7e-a83d-6c1eef0fdc78')); + +//Get array of resolutions for video +echo json_encode($bunny->videoResolutionsArray('e6410005-d591-4a7e-a83d-6c1eef0fdc78')); + +//Get size of video +echo json_encode($bunny->videoSize('e6410005-d591-4a7e-a83d-6c1eef0fdc78', 'MB')); \ No newline at end of file From c94ee2ceb0c4de0cead0df2a71ffba2befd4583e Mon Sep 17 00:00:00 2001 From: cp6 Date: Sat, 25 Sep 2021 11:20:04 +1000 Subject: [PATCH 2/9] Added 3 video stream functions getVideoCollections() gets the video collection information videoResolutionsArray returns video resolutions array videoSize returns video size MB|GB --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 71cfd69..bebec89 100644 --- a/README.md +++ b/README.md @@ -609,6 +609,16 @@ $bunny->setStreamLibraryId($library_id); --- +Get video collections + +Requires ```setStreamLibraryId()``` to be set. + +```php +$bunny->getVideoCollections(); +``` + +--- + Set video collection guid ```php @@ -751,7 +761,7 @@ $bunny->createVideo($library_id, $video_title, $collection_guid); Upload video -Need to use createVideo() first to get video guid +Need to use ```createVideo()``` first to get video guid ```php $bunny->uploadVideo($library_id, $collection_guid, $video_to_upload); @@ -779,6 +789,26 @@ $bunny->setThumbnail($library_id, $video_guid, $thumbnail_url); --- +Get video resolutions + +Requires ```setStreamLibraryId()``` to be set. + +```php +$bunny->videoResolutionsArray($video_guid); +``` + +--- + +Get video size + +Requires ```setStreamLibraryId()``` to be set. + +```php +$bunny->videoSize($video_guid); +``` + +--- + Add captions ```php From 4c4fb285738770a2fd129be9ed19e904d7c6765b Mon Sep 17 00:00:00 2001 From: cp6 Date: Sat, 25 Sep 2021 11:22:09 +1000 Subject: [PATCH 3/9] Added new function & exceptions for video stream calls Added exceptions for checking library id and collection guid have been set. Added 3 new functions for video streams --- src/BunnyAPI.php | 55 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/src/BunnyAPI.php b/src/BunnyAPI.php index 8a539a0..facd9ce 100644 --- a/src/BunnyAPI.php +++ b/src/BunnyAPI.php @@ -768,10 +768,16 @@ public function createCollection(int $library_id, string $video_library_id, int public function listVideos(int $page = 1, int $items_pp = 100, string $order_by = 'date'): array { - if (!isset($this->stream_library_id)) { - return array('response' => 'fail', 'action' => __FUNCTION__, 'message' => 'You must set library id with: setStreamLibraryId()'); + if ($this->isStreamLibraryIdSet()) { + return $this->APIcall('GET', "library/{$this->stream_library_id}/videos?page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); + } + } + + public function listVideosForCollectionId(int $page = 1, int $items_pp = 100, string $order_by = 'date'): array + { + if ($this->isStreamLibraryIdSet() && $this->isStreamCollectionGuidSet()) { + return $this->APIcall('GET', "library/{$this->stream_library_id}/videos?collection={$this->stream_collection_guid}&page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); } - return $this->APIcall('GET', "library/{$this->stream_library_id}/videos?page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); } public function getVideo(int $library_id, string $video_guid): array @@ -813,4 +819,47 @@ public function deleteCaptions(int $library_id, string $video_guid, string $srcl return $this->APIcall('DELETE', "library/$library_id/videos/$video_guid/captions/$srclang", [], false, true); } + public function videoResolutionsArray(string $video_guid): array + { + if ($this->isStreamLibraryIdSet()) { + $data = $this->APIcall('GET', "library/{$this->stream_library_id}/videos/$video_guid", [], false, true); + return explode(",", $data['availableResolutions']); + } + } + + public function videoSize(string $video_guid, string $size_type = 'MB', bool $format = false, float $decimals = 2): float + { + if ($this->isStreamLibraryIdSet()) { + $data = $this->APIcall('GET', "library/{$this->stream_library_id}/videos/$video_guid", [], false, true); + return $this->convertBytes($data['storageSize'], $size_type, $format, $decimals); + } + } + + private function isStreamLibraryIdSet(): bool + { + try { + if (!isset($this->stream_library_id)) { + throw new BunnyAPIException("You must set the stream library id first. Use setStreamLibraryId()"); + } else { + return true; + } + } catch (BunnyAPIException $e) {//display error message + echo $e->errorMessage(); + exit; + } + } + + private function isStreamCollectionGuidSet(): bool + { + try { + if (!isset($this->stream_collection_guid)) { + throw new BunnyAPIException("You must set the stream collection guid first. Use setStreamCollectionGuid()"); + } else { + return true; + } + } catch (BunnyAPIException $e) {//display error message + echo $e->errorMessage(); + exit; + } + } } \ No newline at end of file From a4643c274760d314a04232002ee63ab93b159b8a Mon Sep 17 00:00:00 2001 From: cp6 Date: Sat, 25 Sep 2021 11:42:17 +1000 Subject: [PATCH 4/9] Updated video stream functions Updated 'most' video stream functions to no longer need either the library id or collection guid as an input. Use the setters. --- README.md | 47 +++++++++++++++++++---------------------------- src/BunnyAPI.php | 38 ++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index bebec89..366bdf6 100644 --- a/README.md +++ b/README.md @@ -639,16 +639,14 @@ $bunny->setStreamVideoGuid($video_guid); --- -Get video collections for library +Get video collections for library id + +Requires ```setStreamLibraryId()``` to be set. ```php -$bunny->getStreamCollections($library_id, $page, $items_pp,$order_by); +$bunny->getStreamCollections($page, $items_pp,$order_by); ``` -`$library_id` library id `int` - -*0 = use set library id from setStreamLibraryId()* - `$page` page number `int` `$items_pp` items to show `int` @@ -659,53 +657,46 @@ $bunny->getStreamCollections($library_id, $page, $items_pp,$order_by); Get streams for a collection +Requires ```setStreamLibraryId()``` and ```setStreamCollectionGuid()``` to be set. + ```php -$bunny->getStreamForCollection($library_id, $collection_guid); +$bunny->getStreamForCollection(); ``` -`$library_id` library id `int` - -*0 = use set library id from setStreamLibraryId()* - -`$collection_guid` video collection guid `string` - -*leave empty to use set collection guid from setStreamCollectionGuid()* - --- Update stream collection +Requires ```setStreamLibraryId()``` and ```setStreamCollectionGuid()``` to be set. + + ```php -$bunny->updateCollection($library_id, $collection_guid); +$bunny->updateCollection($updated_collection_name); ``` -`$library_id` library id `int` - -`$collection_guid` video collection guid `string` +`$updated_collection_name` the name to update video collection to `string` --- Delete stream collection +Requires ```setStreamLibraryId()``` and ```setStreamCollectionGuid()``` to be set. + ```php -$bunny->deleteCollection($library_id, $collection_guid); +$bunny->deleteCollection(); ``` -`$library_id` library id `int` - -`$collection_guid` video collection guid `string` - --- Create stream collection +Requires ```setStreamLibraryId()``` to be set. + ```php -$bunny->createCollection($library_id, $collection_guid); +$bunny->createCollection($new_collection_name); ``` -`$library_id` library id `int` - -`$collection_guid` video collection guid `string` +`$new_collection_name` the name for your new video collection `string` --- diff --git a/src/BunnyAPI.php b/src/BunnyAPI.php index facd9ce..2895282 100644 --- a/src/BunnyAPI.php +++ b/src/BunnyAPI.php @@ -711,7 +711,7 @@ public function costCalculator(int $bytes): array * Bunny net video stream section * */ - //Library -> collection -> video + //Stream library -> collection -> video public function setStreamLibraryId(int $library_id): void { $this->stream_library_id = $library_id; @@ -732,38 +732,39 @@ public function getVideoCollections(): array return $this->APIcall('GET', "library/{$this->stream_library_id}/collections", [], false, true); } - public function getStreamCollections(int $library_id = 0, int $page = 1, int $items_pp = 100, string $order_by = 'date'): array + public function getStreamCollections(int $page = 1, int $items_pp = 100, string $order_by = 'date'): array { - if ($library_id === 0) { - $library_id = $this->stream_library_id; + if ($this->isStreamLibraryIdSet()) { + return $this->APIcall('GET', "library/{$this->stream_library_id}/collections?page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); } - return $this->APIcall('GET', "library/$library_id/collections?page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); } - public function getStreamForCollection(int $library_id = 0, string $collection_guid = ''): array + public function getStreamForCollection(): array { - if ($library_id === 0) { - $library_id = $this->stream_library_id; - } - if (empty($collection_guid)) { - $collection_guid = $this->stream_collection_guid; + if ($this->isStreamLibraryIdSet() && $this->isStreamCollectionGuidSet()) { + return $this->APIcall('GET', "library/{$this->stream_library_id}/collections/" . $this->stream_collection_guid, [], false, true); } - return $this->APIcall('GET', "library/$library_id/collections/$collection_guid", [], false, true); } - public function updateCollection(int $library_id, string $collection_guid, string $video_library_id, int $video_count, int $total_size): array + public function updateCollection(string $updated_collection_name): array { - return $this->APIcall('POST', "library/$library_id/collections/$collection_guid", array("videoLibraryId" => $video_library_id, "videoCount" => $video_count, "totalSize" => $total_size), false, true); + if ($this->isStreamLibraryIdSet()) { + return $this->APIcall('POST', "library/{$this->stream_library_id}/collections/" . $this->stream_collection_guid, array("name" => $updated_collection_name), false, true); + } } - public function deleteCollection(int $library_id, string $collection_id): array + public function deleteCollection(): array { - return $this->APIcall('DELETE', "library/$library_id/collections/$collection_id", [], false, true); + if ($this->isStreamLibraryIdSet() && $this->isStreamCollectionGuidSet()) { + return $this->APIcall('DELETE', "library/{$this->stream_library_id}/collections/" . $this->stream_collection_guid, [], false, true); + } } - public function createCollection(int $library_id, string $video_library_id, int $video_count, int $total_size): array + public function createCollection(string $new_collection_name): array { - return $this->APIcall('POST', "library/$library_id/collections", array("videoLibraryId" => $video_library_id, "videoCount" => $video_count, "totalSize" => $total_size), false, true); + if ($this->isStreamLibraryIdSet()) { + return $this->APIcall('POST', "library/{$this->stream_library_id}/collections", array("name" => $new_collection_name), false, true); + } } public function listVideos(int $page = 1, int $items_pp = 100, string $order_by = 'date'): array @@ -862,4 +863,5 @@ private function isStreamCollectionGuidSet(): bool exit; } } + } \ No newline at end of file From c1a4e6cbfdce531ee36f03613bad67df5c2d632f Mon Sep 17 00:00:00 2001 From: cp6 Date: Sat, 25 Sep 2021 11:46:47 +1000 Subject: [PATCH 5/9] Updated video stream properties Updated video stream properties to not be set as empty --- src/BunnyAPI.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BunnyAPI.php b/src/BunnyAPI.php index 2895282..90aadaa 100644 --- a/src/BunnyAPI.php +++ b/src/BunnyAPI.php @@ -23,8 +23,8 @@ class BunnyAPI private $connection; private array $data; private int $stream_library_id; - private string $stream_collection_guid = ''; - private string $stream_video_guid = ''; + private string $stream_collection_guid; + private string $stream_video_guid; public function __construct(int $execution_time = 240, bool $json_header = false) { From 68e239159c2c1d9c1575b7a97a195810fd7b1c6b Mon Sep 17 00:00:00 2001 From: cp6 Date: Sat, 25 Sep 2021 14:14:13 +1000 Subject: [PATCH 6/9] Added create and upload video stream info Added create and upload video stream info --- example.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/example.php b/example.php index f1f5ff9..5ecf9bd 100644 --- a/example.php +++ b/example.php @@ -132,4 +132,15 @@ echo json_encode($bunny->videoResolutionsArray('e6410005-d591-4a7e-a83d-6c1eef0fdc78')); //Get size of video -echo json_encode($bunny->videoSize('e6410005-d591-4a7e-a83d-6c1eef0fdc78', 'MB')); \ No newline at end of file +echo json_encode($bunny->videoSize('e6410005-d591-4a7e-a83d-6c1eef0fdc78', 'MB')); + + +//Create a video (prepare for upload) +echo json_encode($bunny->createVideo('title_for_the_video')); +//OR In collection +echo json_encode($bunny->createVideoForCollection('title_for_the_video')); +//These return information for the video. Importantly the video guid + +//Upload the video file +echo json_encode($bunny->uploadVideo('a6e8483a-7538-4eb1-bb1f-6c1eef0fdc78', 'test_video.mp4')); +//Uploads test_video.mp4 \ No newline at end of file From 5d6188d3191b71eca433ceddba0c6b202a232b69 Mon Sep 17 00:00:00 2001 From: cp6 Date: Sat, 25 Sep 2021 14:29:49 +1000 Subject: [PATCH 7/9] Fixed documentation for video stream functions Fixed documentation for video stream functions --- README.md | 67 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 366bdf6..9d54590 100644 --- a/README.md +++ b/README.md @@ -702,32 +702,34 @@ $bunny->createCollection($new_collection_name); List videos for library +Requires ```setStreamLibraryId()``` to be set. + ```php -$bunny->listVideos($library_id, $collection_guid); +$bunny->listVideos($collection_guid); ``` -`$library_id` library id `int` - `$collection_guid` video collection guid `string` --- Get video information +Requires ```setStreamLibraryId()``` to be set. + ```php -$bunny->getVideo($library_id, $collection_guid); +$bunny->getVideo($collection_guid); ``` -`$library_id` library id `int` - `$collection_guid` video collection guid `string` --- Delete video +Requires ```setStreamLibraryId()``` to be set. + ```php -$bunny->deleteVideo($library_id, $collection_guid); +$bunny->deleteVideo($collection_guid); ``` `$library_id` library id `int` @@ -738,42 +740,53 @@ $bunny->deleteVideo($library_id, $collection_guid); Create video +Requires ```setStreamLibraryId()``` to be set. + ```php -$bunny->createVideo($library_id, $video_title, $collection_guid); +$bunny->createVideo($video_title); ``` -`$library_id` library id `int` - `$video_title` video title `string` -`$collection_guid` video collection guid `string` + +--- + +Create video for collection + +Requires ```setStreamLibraryId()``` and ```setStreamCollectionGuid()``` to be set. + +```php +$bunny->createVideoForCollection($video_title); +``` + +`$video_title` video title `string` --- Upload video +Requires ```setStreamLibraryId()``` to be set. + Need to use ```createVideo()``` first to get video guid ```php -$bunny->uploadVideo($library_id, $collection_guid, $video_to_upload); +$bunny->uploadVideo($video_guid, $video_to_upload); ``` -`$library_id` library id `int` - -`$collection_guid` video collection guid `string` +`$video_guid` video guid `string` -`$video_to_upload` video file `string` +`$video_to_upload` video filename `string` --- Set thumbnail for video +Requires ```setStreamLibraryId()``` to be set. + ```php -$bunny->setThumbnail($library_id, $video_guid, $thumbnail_url); +$bunny->setThumbnail($video_guid, $thumbnail_url); ``` -`$library_id` library id `int` - `$video_guid` video guid `string` `$thumbnail_url` image url `string` @@ -802,12 +815,12 @@ $bunny->videoSize($video_guid); Add captions +Requires ```setStreamLibraryId()``` to be set. + ```php -$bunny->addCaptions($library_id, $video_guid, $collection_guid, $label, $captions_file); +$bunny->addCaptions($video_guid, $collection_guid, $label, $captions_file); ``` -`$library_id` library id `int` - `$video_guid` video guid `string` `$srclang` caption srclang `string` @@ -820,18 +833,14 @@ $bunny->addCaptions($library_id, $video_guid, $collection_guid, $label, $caption Delete captions +Requires ```setStreamLibraryId()``` to be set. + ```php $bunny->deleteCaptions($library_id, $video_guid, $srclang); ``` -`$library_id` library id `int` - `$video_guid` video guid `string` `$srclang` captions srclang `string` ---- - -## TODO - -* Proper exception handling +--- \ No newline at end of file From 508c8059cdf8de9c576e707162efd22764f2c438 Mon Sep 17 00:00:00 2001 From: cp6 Date: Sat, 25 Sep 2021 14:31:31 +1000 Subject: [PATCH 8/9] Video stream function updates and changes Changed library id and collection guid set check Added createVideoForCollection() Changed library id and collection guid functions to return void type, no longer bool. --- src/BunnyAPI.php | 108 ++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/src/BunnyAPI.php b/src/BunnyAPI.php index 90aadaa..d756eb4 100644 --- a/src/BunnyAPI.php +++ b/src/BunnyAPI.php @@ -734,115 +734,121 @@ public function getVideoCollections(): array public function getStreamCollections(int $page = 1, int $items_pp = 100, string $order_by = 'date'): array { - if ($this->isStreamLibraryIdSet()) { - return $this->APIcall('GET', "library/{$this->stream_library_id}/collections?page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); - } + $this->checkStreamLibraryIdSet(); + return $this->APIcall('GET', "library/{$this->stream_library_id}/collections?page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); } public function getStreamForCollection(): array { - if ($this->isStreamLibraryIdSet() && $this->isStreamCollectionGuidSet()) { - return $this->APIcall('GET', "library/{$this->stream_library_id}/collections/" . $this->stream_collection_guid, [], false, true); - } + $this->checkStreamLibraryIdSet(); + $this->checkStreamCollectionGuidSet(); + return $this->APIcall('GET', "library/{$this->stream_library_id}/collections/" . $this->stream_collection_guid, [], false, true); } public function updateCollection(string $updated_collection_name): array { - if ($this->isStreamLibraryIdSet()) { - return $this->APIcall('POST', "library/{$this->stream_library_id}/collections/" . $this->stream_collection_guid, array("name" => $updated_collection_name), false, true); - } + $this->checkStreamLibraryIdSet(); + return $this->APIcall('POST', "library/{$this->stream_library_id}/collections/" . $this->stream_collection_guid, array("name" => $updated_collection_name), false, true); } public function deleteCollection(): array { - if ($this->isStreamLibraryIdSet() && $this->isStreamCollectionGuidSet()) { - return $this->APIcall('DELETE', "library/{$this->stream_library_id}/collections/" . $this->stream_collection_guid, [], false, true); - } + $this->checkStreamLibraryIdSet(); + $this->checkStreamCollectionGuidSet(); + return $this->APIcall('DELETE', "library/{$this->stream_library_id}/collections/" . $this->stream_collection_guid, [], false, true); } public function createCollection(string $new_collection_name): array { - if ($this->isStreamLibraryIdSet()) { - return $this->APIcall('POST', "library/{$this->stream_library_id}/collections", array("name" => $new_collection_name), false, true); - } + $this->checkStreamLibraryIdSet(); + return $this->APIcall('POST', "library/{$this->stream_library_id}/collections", array("name" => $new_collection_name), false, true); } public function listVideos(int $page = 1, int $items_pp = 100, string $order_by = 'date'): array { - if ($this->isStreamLibraryIdSet()) { - return $this->APIcall('GET', "library/{$this->stream_library_id}/videos?page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); - } + $this->checkStreamLibraryIdSet(); + return $this->APIcall('GET', "library/{$this->stream_library_id}/videos?page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); } public function listVideosForCollectionId(int $page = 1, int $items_pp = 100, string $order_by = 'date'): array { - if ($this->isStreamLibraryIdSet() && $this->isStreamCollectionGuidSet()) { - return $this->APIcall('GET', "library/{$this->stream_library_id}/videos?collection={$this->stream_collection_guid}&page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); - } + $this->checkStreamLibraryIdSet(); + $this->checkStreamCollectionGuidSet(); + return $this->APIcall('GET', "library/{$this->stream_library_id}/videos?collection={$this->stream_collection_guid}&page=$page&itemsPerPage=$items_pp&orderBy=$order_by", [], false, true); } - public function getVideo(int $library_id, string $video_guid): array + public function getVideo(string $video_guid): array { - return $this->APIcall('GET', "library/$library_id/videos/$video_guid", [], false, true); + $this->checkStreamLibraryIdSet(); + return $this->APIcall('GET', "library/{$this->stream_library_id}/videos/$video_guid", [], false, true); } - public function deleteVideo(int $library_id, string $video_guid): array + public function deleteVideo(string $video_guid): array { - return $this->APIcall('DELETE', "library/$library_id/videos/$video_guid", [], false, true); + $this->checkStreamLibraryIdSet(); + return $this->APIcall('DELETE', "library/{$this->stream_library_id}/videos/$video_guid", [], false, true); } - public function createVideo(int $library_id, string $video_title, string $collection_guid = ''): array + public function createVideo(string $video_title): array { - if (!empty($collection_guid)) { - return $this->APIcall('POST', "library/$library_id/videos?title=$video_title&collectionId=$collection_guid", [], false, true); - } - return $this->APIcall('POST', "library/$library_id/videos?title=$video_title", [], false, true); + $this->checkStreamLibraryIdSet(); + return $this->APIcall('POST', "library/{$this->stream_library_id}/videos", array("title" => $video_title), false, true); + } + + public function createVideoForCollection(string $video_title): array + { + $this->checkStreamLibraryIdSet(); + $this->checkStreamCollectionGuidSet(); + return $this->APIcall('POST', "library/{$this->stream_library_id}/videos", array("title" => $video_title, "collectionId" => $this->stream_collection_guid), false, true); } - public function uploadVideo(int $library_id, string $video_guid, string $video_to_upload): array + public function uploadVideo(string $video_guid, string $video_to_upload): array { //Need to use createVideo() first to get video guid - return $this->APIcall('PUT', "library/$library_id/videos/$video_guid", array('file' => $video_to_upload), false, true); + $this->checkStreamLibraryIdSet(); + return $this->APIcall('PUT', "library/{$this->stream_library_id}/videos/" . $video_guid, array('file' => $video_to_upload), false, true); + } - public function setThumbnail(int $library_id, string $video_guid, string $thumbnail_url): array + public function setThumbnail(string $video_guid, string $thumbnail_url): array { - return $this->APIcall('POST', "library/$library_id/videos/$video_guid/thumbnail?$thumbnail_url", [], false, true); + $this->checkStreamLibraryIdSet(); + return $this->APIcall('POST', "library/{$this->stream_library_id}/videos/$video_guid/thumbnail?$thumbnail_url", [], false, true); + } - public function addCaptions(int $library_id, string $video_guid, string $srclang, string $label, string $captions_file): array + public function addCaptions(string $video_guid, string $srclang, string $label, string $captions_file): array { - return $this->APIcall('POST', "library/$library_id/videos/$video_guid/captions/$srclang?label=$label&captionsFile=$captions_file", [], false, true); + $this->checkStreamLibraryIdSet(); + return $this->APIcall('POST', "library/{$this->stream_library_id}/videos/$video_guid/captions/$srclang?label=$label&captionsFile=$captions_file", [], false, true); } - public function deleteCaptions(int $library_id, string $video_guid, string $srclang): array + public function deleteCaptions(string $video_guid, string $srclang): array { - return $this->APIcall('DELETE', "library/$library_id/videos/$video_guid/captions/$srclang", [], false, true); + $this->checkStreamLibraryIdSet(); + return $this->APIcall('DELETE', "library/{$this->stream_library_id}/videos/$video_guid/captions/$srclang", [], false, true); } public function videoResolutionsArray(string $video_guid): array { - if ($this->isStreamLibraryIdSet()) { - $data = $this->APIcall('GET', "library/{$this->stream_library_id}/videos/$video_guid", [], false, true); - return explode(",", $data['availableResolutions']); - } + $this->checkStreamLibraryIdSet(); + $data = $this->APIcall('GET', "library/{$this->stream_library_id}/videos/$video_guid", [], false, true); + return explode(",", $data['availableResolutions']); } + public function videoSize(string $video_guid, string $size_type = 'MB', bool $format = false, float $decimals = 2): float { - if ($this->isStreamLibraryIdSet()) { - $data = $this->APIcall('GET', "library/{$this->stream_library_id}/videos/$video_guid", [], false, true); - return $this->convertBytes($data['storageSize'], $size_type, $format, $decimals); - } + $this->checkStreamLibraryIdSet(); + $data = $this->APIcall('GET', "library/{$this->stream_library_id}/videos/$video_guid", [], false, true); + return $this->convertBytes($data['storageSize'], $size_type, $format, $decimals); } - private function isStreamLibraryIdSet(): bool + private function checkStreamLibraryIdSet(): void { try { if (!isset($this->stream_library_id)) { throw new BunnyAPIException("You must set the stream library id first. Use setStreamLibraryId()"); - } else { - return true; } } catch (BunnyAPIException $e) {//display error message echo $e->errorMessage(); @@ -850,13 +856,11 @@ private function isStreamLibraryIdSet(): bool } } - private function isStreamCollectionGuidSet(): bool + private function checkStreamCollectionGuidSet(): void { try { if (!isset($this->stream_collection_guid)) { throw new BunnyAPIException("You must set the stream collection guid first. Use setStreamCollectionGuid()"); - } else { - return true; } } catch (BunnyAPIException $e) {//display error message echo $e->errorMessage(); From 87c2e734086035eacb81459187a86f2ef02b1682 Mon Sep 17 00:00:00 2001 From: cp6 Date: Sat, 25 Sep 2021 14:40:13 +1000 Subject: [PATCH 9/9] Updated readme Set version to 1.6 Added PHP 8 badge Fixed bunny.net API link Added aff link --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9d54590..75ddc0f 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ # BunnyCDN API Class -The most comprehensive, feature packed and easy to use PHP class for the BunnyCDN pull, video streaming and storage -zones [API](https://bunnycdn.docs.apiary.io/). +The most comprehensive, feature packed and easy to use PHP class for [bunny.net](https://bunny.net?ref=qxdxfxutxf) ( +BunnyCDN) pull, video streaming and storage zones [API](https://docs.bunny.net/reference/bunnynet-api-overview). This class whilst having a main focus on storage zone interaction includes pull zone features. Combining API with FTP, managing and using BunnyCDN storage zones just got easier. -[![Generic badge](https://img.shields.io/badge/version-1.5-blue.svg)](https://shields.io/) +[![Generic badge](https://img.shields.io/badge/version-1.6-blue.svg)]() +[![Generic badge](https://img.shields.io/badge/PHP-8-purple.svg)]() **Note video streaming API is seemingly not finalized and is changing** @@ -599,6 +600,8 @@ $bunny->closeConnection(); ## Video streaming +**You can only get the video library id from your bunny.net stream library page** + Set video stream library id ```php @@ -669,7 +672,6 @@ Update stream collection Requires ```setStreamLibraryId()``` and ```setStreamCollectionGuid()``` to be set. - ```php $bunny->updateCollection($updated_collection_name); ```