Skip to content

Commit d347acf

Browse files
committed
Rewritten library compatible with Coconut API v2
1 parent cd0d9d6 commit d347acf

13 files changed

Lines changed: 1790 additions & 420 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
.DS_Store

README.md

Lines changed: 53 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
# PHP client library for encoding videos with Coconut
1+
# Coconut PHP Library
22

3-
## Install
3+
The Coconut PHP library provides access to the Coconut API for encoding videos, packaging media files into HLS and MPEG-Dash, generating thumbnails and GIF animation.
4+
5+
This library is only compatible with the Coconut API v2.
6+
7+
## Documentation
8+
9+
See the [full documentation](https://docs.coconut.co).
10+
11+
## Installation
412

513
To install the Coconut PHP library, you need [composer](http://getcomposer.org) first:
614

@@ -13,7 +21,7 @@ Edit `composer.json`:
1321
```javascript
1422
{
1523
"require": {
16-
"opencoconut/coconut": "2.*"
24+
"opencoconut/coconut": "3.*"
1725
}
1826
}
1927
```
@@ -24,101 +32,71 @@ Install the depencies by executing `composer`:
2432
php composer.phar install
2533
```
2634

27-
## Submitting the job
28-
29-
Use the [API Request Builder](https://app.coconut.co/job/new) to generate a config file that match your specific workflow.
30-
31-
Example of `coconut.conf`:
35+
## Usage
3236

33-
```ini
34-
var s3 = s3://accesskey:secretkey@mybucket
35-
36-
set webhook = http://mysite.com/webhook/coconut?videoID=$vid
37-
38-
-> mp4 = $s3/videos/video_$vid.mp4
39-
-> webm = $s3/videos/video_$vid.webm
40-
-> jpg:300x = $s3/previews/thumbs_#num#.jpg, number=3
41-
```
42-
43-
Here is the PHP code to submit the config file:
37+
The library needs you to set your API key which can be found in your [dashboard](https://app.coconut.co/api). Webhook URL and storage settings are optional but are very convenient because you set them only once.
4438

4539
```php
4640
<?php
4741

4842
require_once('vendor/autoload.php');
4943

50-
$job = Coconut\Job::create(array(
51-
'api_key' => 'k-api-key',
52-
'conf' => 'coconut.conf',
53-
'source' => 'http://yoursite.com/media/video.mp4',
54-
'vars' => array('vid' => 1234)
55-
));
56-
57-
if($job->{'status'} == 'processing') {
58-
echo $job->{'id'};
59-
} else {
60-
echo $job->{'error_code'};
61-
echo $job->{'error_message'};
44+
$coconut = new Coconut\Client('k-api-key');
45+
46+
$coconut.notification = [
47+
'type' => 'http',
48+
'url' => 'https://yoursite/api/coconut/webhook'
49+
];
50+
51+
$coconut.storage = [
52+
'service' => 's3',
53+
'bucket' => 'my-bucket',
54+
'region' => 'us-east-1',
55+
'credentials' => {
56+
'access_key_id' => 'access-key',
57+
'secret_access_key' => 'secret-key'
58+
}
6259
}
6360

6461
?>
6562
```
6663

67-
You can also create a job without a config file. To do that you will need to give every settings in the method parameters. Here is the exact same job but without a config file:
64+
## Creating a job
6865

6966
```php
7067
<?php
7168

72-
require_once('vendor/autoload.php');
73-
74-
$vid = 1234;
75-
$s3 = 's3://accesskey:secretkey@mybucket';
76-
77-
$job = Coconut\Job::create(array(
78-
'api_key' => 'k-api-key',
79-
'source' => 'http://yoursite.com/media/video.mp4',
80-
'webhook' => 'http://mysite.com/webhook/coconut?videoId=' . $vid,
81-
'outputs' => array(
82-
'mp4' => $s3 . '/videos/video_' . $vid . '.mp4',
83-
'webm' => $s3 . '/videos/video_' . $vid . '.webm',
84-
'jpg:300x' => $s3 . '/previews/thumbs_#num#.jpg, number=3'
85-
)
86-
));
69+
try {
70+
$job = $coconut->job->create([
71+
'input' => [ 'url' => 'https://mysite/path/file.mp4' ],
72+
'outputs' => [
73+
'jpg:300x' => [ 'path' => '/image.jpg' ],
74+
'mp4:1080p' => [ 'path' => '/1080p.mp4' ],
75+
'httpstream' => [
76+
'hls' => [ 'path' => 'hls/' ]
77+
]
78+
]
79+
]);
80+
81+
print_r($job);
82+
83+
} cacth(Exception $e) {
84+
echo $e->getMessage();
85+
}
8786

8887
?>
8988
```
9089

91-
Other example usage:
90+
## Getting information about a job
9291

9392
```php
94-
<?php
95-
// Getting info about a job
96-
$job = Coconut\Job::get(18370773);
97-
98-
// Retrieving metadata
99-
Coconut\Job::getAllMetadata(18370773);
100-
101-
// Retrieving the source file metadata only
102-
Coconut\Job::getMetadataFor(18370773, 'source');
103-
?>
93+
$job = $coconut->job->retrieve('OolQXaiU86NFki');
10494
```
10595

106-
Note that you can use the environment variable `COCONUT_API_KEY` to set your API key.
96+
## Retrieving metadata
10797

108-
## Contributing
109-
110-
1. Fork it
111-
2. Create your feature branch (`git checkout -b my-new-feature`)
112-
3. Commit your changes (`git commit -am 'Added some feature'`)
113-
4. Push to the branch (`git push origin my-new-feature`)
114-
5. Create new Pull Request
115-
116-
117-
*Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php).*
118-
119-
---
98+
```php
99+
$metadata = $coconut->metadata->retrieve('OolQXaiU86NFki');
100+
```
120101

121-
* Coconut website: http://coconut.co
122-
* API documentation: http://coconut.co/docs
123-
* Contact: [support@coconut.co](mailto:support@coconut.co)
124-
* Twitter: [@OpenCoconut](http://twitter.com/opencoconut)
102+
*Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php).*

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "opencoconut/coconut",
33
"type": "library",
4-
"version": "2.8.0",
4+
"version": "3.0.0",
55
"description": "Coconut is a Cloud Video Encoding Service built for developers",
66
"keywords": ["video", "encoding", "transcoding", "web service", "h264", "cloud"],
7-
"homepage": "http://coconut.co",
7+
"homepage": "https://coconut.co",
88
"license": "MIT",
99
"authors": [
1010
{

0 commit comments

Comments
 (0)