Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Stream API endpoints for resolutions, cleanup and output codec #151

Merged
merged 2 commits into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions docs/stream-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,28 @@ $streamApi->reEncodeVideo(
);
```

#### [Add output codec to video](https://docs.bunny.net/reference/video_reencodeusingcodec)

```php
$streamApi->addOutputCodecToVideo(
libraryId: 1,
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
outputCodecId: 2,
);
```

!!! note

- The argument `outputCodecId` has the following possible values:
- `0` = x264
- `1` = vp9 (premium)
- `2` = hevc (premium)
- `3` = av1 (premium)

!!! warning

This endpoint will return a `400` status code if premium encoding is not enabled (even if the `outputCodecId` value `0` is given).

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

```php
Expand Down Expand Up @@ -412,6 +434,43 @@ $streamApi->transcribeVideo(
- The `language` is a [two-letter (set 1) language abbreviation](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) for transcribing the video.
- Once a video has transcribed you need to set `force` to `true` in order to force a new transcription to be added.

#### [Video resolutions info](https://docs.bunny.net/reference/video_getvideoresolutions)

```php
$streamApi->videoResolutionsInfo(
libraryId: 1,
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
);
```

#### [Cleanup unconfigured resolutions](https://docs.bunny.net/reference/video_deleteresolutions)

```php
$streamApi->cleanupUnconfiguredResolutions(
libraryId: 1,
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
query: [
'resolutionsToDelete' => '240p,360p',
'deleteNonConfiguredResolutions' => false,
'deleteOriginal' => false,
'deleteMp4Files' => false,
'dryRun' => false,
],
);
```

!!! note

- The key `resolutionsToDelete` consists of comma separated resolutions.

!!! tip

Use the [Video Resolutions Info](#video-resolutions-info) endpoint to retrieve the resolutions for the video.

!!! warning

This endpoint will return a `400` status code if all available resolutions for the video are passed to `resolutionsToDelete`, as there must be at least one resolution available after cleanup.

#### [Get OEmbed](https://docs.bunny.net/reference/oembed_getoembed)

```php
Expand Down
29 changes: 29 additions & 0 deletions src/Model/API/Stream/ManageVideos/AddOutputCodecToVideo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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\Model\EndpointInterface;

class AddOutputCodecToVideo implements EndpointInterface
{
public function getMethod(): Method
{
return Method::PUT;
}

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

public function getHeaders(): array
{
return [
Header::ACCEPT_JSON,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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 DeleteUnconfiguredResolutions implements EndpointInterface, EndpointQueryInterface
{
public function getMethod(): Method
{
return Method::POST;
}

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

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

public function getQuery(): array
{
return [
new AbstractParameter(name: 'resolutionsToDelete', type: Type::STRING_TYPE, required: false),
new AbstractParameter(name: 'deleteNonConfiguredResolutions', type: Type::BOOLEAN_TYPE, required: false),
new AbstractParameter(name: 'deleteOriginal', type: Type::BOOLEAN_TYPE, required: false),
new AbstractParameter(name: 'deleteMp4Files', type: Type::BOOLEAN_TYPE, required: false),
new AbstractParameter(name: 'dryRun', type: Type::BOOLEAN_TYPE, required: false),
];
}
}
29 changes: 29 additions & 0 deletions src/Model/API/Stream/ManageVideos/GetVideoResolutionsInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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\Model\EndpointInterface;

class GetVideoResolutionsInfo implements EndpointInterface
{
public function getMethod(): Method
{
return Method::GET;
}

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

public function getHeaders(): array
{
return [
Header::ACCEPT_JSON,
];
}
}
73 changes: 73 additions & 0 deletions src/StreamAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
use ToshY\BunnyNet\Model\API\Stream\ManageCollections\ListCollections;
use ToshY\BunnyNet\Model\API\Stream\ManageCollections\UpdateCollection;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\AddCaption;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\AddOutputCodecToVideo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\DeleteUnconfiguredResolutions;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\CreateVideo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\DeleteCaption;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\DeleteVideo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\FetchVideo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\GetVideo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\GetVideoHeatmap;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\GetVideoPlayData;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\GetVideoResolutionsInfo;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\ListVideos;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\ListVideoStatistics;
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\ReEncodeVideo;
Expand Down Expand Up @@ -401,6 +404,28 @@ public function reEncodeVideo(
);
}

/**
* @throws ClientExceptionInterface
* @throws Exception\BunnyClientResponseException
* @throws Exception\JSONException
* @param int $libraryId
* @param string $videoId
* @param int $outputCodecId
* @return BunnyClientResponseInterface
*/
public function addOutputCodecToVideo(
int $libraryId,
string $videoId,
int $outputCodecId,
): BunnyClientResponseInterface {
$endpoint = new AddOutputCodecToVideo();

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

/**
* @throws BunnyClientResponseException
* @throws ClientExceptionInterface
Expand Down Expand Up @@ -619,6 +644,54 @@ public function transcribeVideo(
);
}

/**
* @throws ClientExceptionInterface
* @throws Exception\BunnyClientResponseException
* @throws Exception\JSONException
* @param int $libraryId
* @param string $videoId
* @return BunnyClientResponseInterface
*/
public function videoResolutionsInfo(
int $libraryId,
string $videoId,
): BunnyClientResponseInterface {
$endpoint = new GetVideoResolutionsInfo();

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

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

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

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

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