Skip to content

Commit

Permalink
Implement Stream API Repackage Video post endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ToshY committed Apr 9, 2024
1 parent 37cb0e5 commit 7daa55c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/stream-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ $streamApi->reEncodeVideo(
);
```

#### [Repackage Video](https://docs.bunny.net/reference/video_repackage)

```php
$streamApi->repackageVideo(
libraryId: 1,
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
query: [
'keepOriginalFiles' => true,
],
);
```

!!! note

- This method allows repackiging of videos for libraries that have [Enterprise DRM](https://docs.bunny.net/docs/stream-drm#mediacage-enterprise-drm) enabled.

#### [List Videos](https://docs.bunny.net/reference/video_list)

```php
Expand Down
39 changes: 39 additions & 0 deletions src/Model/API/Stream/ManageVideos/RepackageVideo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace ToshY\BunnyNet\Model\API\Stream\ManageVideos;

use ToshY\BunnyNet\Enum\Header;
use ToshY\BunnyNet\Enum\Method;
use ToshY\BunnyNet\Enum\Type;
use ToshY\BunnyNet\Model\AbstractParameter;
use ToshY\BunnyNet\Model\EndpointInterface;
use ToshY\BunnyNet\Model\EndpointQueryInterface;

class RepackageVideo implements EndpointInterface, EndpointQueryInterface
{
public function getMethod(): Method
{
return Method::POST;
}

public function getPath(): string
{
return 'library/%d/videos/%s/repackage';
}

public function getHeaders(): array
{
return [
Header::ACCEPT_JSON,
];
}

public function getQuery(): array
{
return [
new AbstractParameter(name: 'keepOriginalFiles', type: Type::BOOLEAN_TYPE),
];
}
}
29 changes: 29 additions & 0 deletions src/StreamAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\ListVideos;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\ListVideoStatistics;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\ReEncodeVideo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\RepackageVideo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\SetThumbnail;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\SetThumbnailByBody;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\UpdateVideo;
Expand Down Expand Up @@ -399,6 +400,34 @@ public function reEncodeVideo(
);
}

/**
* @throws BunnyClientResponseException
* @throws ClientExceptionInterface
* @throws InvalidTypeForKeyValueException
* @throws InvalidTypeForListValueException
* @throws JSONException
* @throws ParameterIsRequiredException
* @param int $libraryId
* @param string $videoId
* @param array<string,mixed> $query
* @return BunnyClientResponseInterface
*/
public function repackageVideo(
int $libraryId,
string $videoId,
array $query = [],
): BunnyClientResponseInterface {
$endpoint = new RepackageVideo();

ParameterValidator::validate($query, $endpoint->getQuery());

return $this->client->request(
endpoint: $endpoint,
parameters: [$libraryId, $videoId],
query: $query,
);
}

/**
* @throws ClientExceptionInterface
* @throws Exception\BunnyClientResponseException
Expand Down

0 comments on commit 7daa55c

Please sign in to comment.