Skip to content

Commit 1affdac

Browse files
authored
Merge pull request #120 from ToshY/feature/116
Implement Stream API `Transcribe Video` post endpoint
2 parents 66e6ae5 + 58fd1ae commit 1affdac

File tree

3 files changed

+92
-5
lines changed

3 files changed

+92
-5
lines changed

Diff for: docs/stream-api.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ $streamApi->fetchVideo(
356356
$streamApi->addCaption(
357357
libraryId: 1,
358358
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
359-
sourceLanguage: 'jp',
359+
sourceLanguage: 'ja',
360360
body: [
361-
'srclang' => 'jp',
361+
'srclang' => 'ja',
362362
'label' => 'Subtitles (Japanese)',
363363
'captionsFile' => 'MQowMDowMDowMCwwMDAgLS0+IDAwOjAxOjAwLDAwMApOZXZlciBnb25uYSBnaXZlIHlvdSB1cC4K',
364364
],
@@ -367,7 +367,7 @@ $streamApi->addCaption(
367367

368368
!!! note
369369

370-
- The `sourceLanguage` / `srclang` is the [language shortcode](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) for the caption.
370+
- The `sourceLanguage` / `srclang` is a [two-letter (set 1) language abbreviation](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) for the caption.
371371
- The `captionsFile` requires the file contents to be sent as a base64 encoded string.
372372

373373
#### [Delete Caption](https://docs.bunny.net/reference/video_deletecaption)
@@ -376,13 +376,31 @@ $streamApi->addCaption(
376376
$streamApi->deleteCaption(
377377
libraryId: 1,
378378
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
379-
sourceLanguage: 'jp',
379+
sourceLanguage: 'ja',
380380
);
381381
```
382382

383383
!!! note
384384

385-
- The `sourceLanguage` is the [language shortcode](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) for the caption.
385+
- The `sourceLanguage` is a [two-letter (set 1) language abbreviation](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) for the caption.
386+
387+
#### [Transcribe Video](https://docs.bunny.net/reference/video_transcribevideo)
388+
389+
```php
390+
$streamApi->transcribeVideo(
391+
libraryId: 1,
392+
videoId: 'e7e9b99a-ea2a-434a-b200-f6615e7b6abd',
393+
query: [
394+
'language' => 'fi',
395+
'force' => true,
396+
],
397+
);
398+
```
399+
400+
!!! note
401+
402+
- 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.
403+
- Once a video has transcribed you need to set `force` to `true` in order to force a new transcription to be added.
386404

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

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ToshY\BunnyNet\Model\API\Stream\ManageVideos;
6+
7+
use ToshY\BunnyNet\Enum\Header;
8+
use ToshY\BunnyNet\Enum\Method;
9+
use ToshY\BunnyNet\Enum\Type;
10+
use ToshY\BunnyNet\Model\AbstractParameter;
11+
use ToshY\BunnyNet\Model\EndpointInterface;
12+
use ToshY\BunnyNet\Model\EndpointQueryInterface;
13+
14+
class TranscribeVideo implements EndpointInterface, EndpointQueryInterface
15+
{
16+
public function getMethod(): Method
17+
{
18+
return Method::POST;
19+
}
20+
21+
public function getPath(): string
22+
{
23+
return 'library/%d/videos/%s/transcribe';
24+
}
25+
26+
public function getHeaders(): array
27+
{
28+
return [
29+
Header::ACCEPT_JSON,
30+
];
31+
}
32+
33+
public function getQuery(): array
34+
{
35+
return [
36+
new AbstractParameter(name: 'language', type: Type::STRING_TYPE, required: true),
37+
new AbstractParameter(name: 'force', type: Type::BOOLEAN_TYPE),
38+
];
39+
}
40+
}

Diff for: src/StreamAPI.php

+29
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\RepackageVideo;
3333
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\SetThumbnail;
3434
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\SetThumbnailByBody;
35+
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\TranscribeVideo;
3536
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\UpdateVideo;
3637
use ToshY\BunnyNet\Model\API\Stream\ManageVideos\UploadVideo;
3738
use ToshY\BunnyNet\Model\API\Stream\OEmbed\GetOEmbed;
@@ -590,6 +591,34 @@ public function deleteCaption(
590591
);
591592
}
592593

594+
/**
595+
* @throws ClientExceptionInterface
596+
* @throws Exception\BunnyClientResponseException
597+
* @throws Exception\JSONException
598+
* @throws Exception\InvalidTypeForKeyValueException
599+
* @throws Exception\InvalidTypeForListValueException
600+
* @throws Exception\ParameterIsRequiredException
601+
* @param int $libraryId
602+
* @param string $videoId
603+
* @param array<string,mixed> $query
604+
* @return BunnyClientResponseInterface
605+
*/
606+
public function transcribeVideo(
607+
int $libraryId,
608+
string $videoId,
609+
array $query,
610+
): BunnyClientResponseInterface {
611+
$endpoint = new TranscribeVideo();
612+
613+
ParameterValidator::validate($query, $endpoint->getQuery());
614+
615+
return $this->client->request(
616+
endpoint: $endpoint,
617+
parameters: [$libraryId, $videoId],
618+
query: $query,
619+
);
620+
}
621+
593622
/**
594623
* @throws ClientExceptionInterface
595624
* @throws Exception\BunnyClientResponseException

0 commit comments

Comments
 (0)