Skip to content

Commit c120376

Browse files
committed
Version 1
1 parent 0b8fc32 commit c120376

File tree

3 files changed

+1064
-637
lines changed

3 files changed

+1064
-637
lines changed

README.markdown

Lines changed: 121 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -1,216 +1,156 @@
11
Zencoder API PHP Library
22
==========================
33

4-
Author: [Steve Heffernan](http://www.steveheffernan.com) (steve (a) sevenwire () com)
5-
Company: [Sevenwire - Web Application Development](http://sevenwire.com)
6-
Version: 1.1
7-
Date: 08-31-2009
8-
Repository: <http://github.com/flixcloud/flix_cloud-php/>
9-
10-
For more details on the FlixCloud API requirements visit
11-
<http://flixcloud.com/api>
12-
13-
There are three main functions: **Job Requests**, **Notification Handling**, and **Checking Job Status**
14-
15-
16-
TRANSCODING JOB REQUEST
17-
------------------------
18-
The FlixCloudJob object uses cURL to send an XML formatted job request to
19-
https://www.flixcloud.com/jobs. It then uses the SimpleXMLElement library
20-
to parse any returned XML.
21-
22-
**API key is required and can be found at <https://flixcloud.com/settings>**
23-
**Recipe ID is required and can be found at <http://flixcloud.com/overviews/recipes>**
24-
25-
26-
### EXAMPLE 1 (using params hash)
27-
28-
require_once("FlixCloud.php");
29-
30-
$fcj = new FlixCloudJob("2j1l:kd3add:0:ivzf:2e1y", array(
31-
"recipe_id" => 99,
32-
33-
"input_url" => "http://www.example.com/videos/input.mpg",
34-
// "input_user" => "username", // Optional
35-
// "input_password" => "password", // Optional
36-
37-
"output_url" => "sftp://www.example.com/httpdocs/videos/output.flv",
38-
"output_user" => "username",
39-
"output_password" => "password",
40-
41-
// If your recipe uses a watermark
42-
"watermark_url" => "http://www.example.com/videos/watermark.png",
43-
// "watermark_user" => "username", // Optional
44-
// "watermark_password" => "password", // Optional
45-
46-
// If your recipe uses thumbnails
47-
"thumbnail_url" => "sftp://www.example.com/httpdocs/videos/thumbs/",
48-
"thumbnail_prefix" => "thumb_",
49-
"thumbnail_user" => "username",
50-
"thumbnail_password" => "password",
51-
52-
// "notification_url" => "http://www.example.com/notification.php", // Optional. Can be set in account settings.
53-
// "pass_through" => "Blah blah", // Optional. Allows you to pass back a specific value with the notification.
54-
// "insecure" => true, // Use if certificate won't verify
55-
// "send" => false, // Use if you don't want to send job immeditely.
56-
57-
));
58-
59-
if($fcj->success) {
60-
// Job was successfully requested. Store job ID and start time if needed.
61-
echo "Success. Job ID is ".$fcj->id." Submitted at ".$fcj->initialized_job_at;
4+
Author: [Steve Heffernan](http://www.steveheffernan.com) (steve (a) zencoder (.) c&#1;om)
5+
Company: [Zencoder - Online Video Encoder](http://zencoder.com)
6+
Version: 1.0
7+
Date: 2010-04-02
8+
Repository: <http://github.com/zencoder/zencoder-php/>
9+
10+
For more details on the Zencoder API requirements visit
11+
<http://zencoder.com/docs/api>
12+
13+
14+
ENCODING JOB
15+
------------
16+
The ZencoderJob object creates an encoding job using [cURL](http://zencoder.com/docs/glossary/curl/)
17+
to send [JSON](http://zencoder.com/docs/glossary/json/) formatted parameters to Zencoder's encoding API.
18+
19+
### Step 1
20+
Visit the [API builder](https://app.zencoder.com/api_builder) in your account,
21+
and execute a successful encoding job.
22+
23+
### Step 2
24+
Copy the successful JSON string, starting with the first curly brace "{",
25+
and pass it as the parameters for a new ZencoderJob object. Execute the script on your server to test that it works.
26+
27+
#### Example
28+
<pre>
29+
<?php
30+
31+
// Make sure this points to a copy of Zencoder.php on the same server as this script.
32+
require_once("zencoder-php/Zencoder.php");
33+
34+
// New Encoding Job
35+
$encoding_job = new ZencoderJob('
36+
{
37+
"api_key": "93h630j1dsyshjef620qlkavnmzui3",
38+
"input": "s3://bucket-name/file-name.avi"
39+
"outputs": [
40+
{
41+
"label": "web"
42+
}
43+
]
44+
}
45+
');
46+
47+
// Check if it worked
48+
if ($encoding_job->created) {
49+
// Success
50+
echo "w00t! \n\n";
51+
echo "Job ID: ".$encoding_job->id."\n";
52+
echo "Output '".$encoding_job->outputs["web"]->label."' ID: ".$encoding_job->outputs["web"]->id."\n";
53+
// Store Job/Output IDs to update their status when notified or to check their progress.
6254
} else {
63-
// Do something with the errors
64-
foreach($fcj->errors as $error) {
65-
echo $error;
55+
// Failed
56+
echo "Fail :(\n\n";
57+
echo "Errors:\n";
58+
foreach($encoding_job->errors as $error) {
59+
echo $error."\n";
6660
}
6761
}
6862

63+
echo "\nAll Job Attributes:\n";
64+
var_dump($encoding_job);
6965

70-
### EXAMPLE 2 (setting properties separately)
66+
?>
67+
</pre>
7168

72-
require_once("FlixCloud.php");
69+
### Step 3
70+
Modify the above script to meet your needs.
71+
Your [API Request History](https://app.zencoder.com/api_requests) may come in handy.
72+
You can revisit your [API builder](https://app.zencoder.com/api_builder) to add/update parameters of the JSON.
7373

74-
// First parameter is API key, second is Recipe ID
75-
$fcj = new FlixCloudJob("2j1l:kd3add:0:ivzf:2e1y");
76-
$fcj->recipe_id = 99;
77-
$fcj->set_input("http://www.example.com/videos/input.mpg"); // Add user/password array if needed
78-
$fcj->set_output("sftp://www.example.com/httpdocs/videos/output.flv", array("user" => "username", "password" => "password"));
79-
$fcj->set_watermark("http://www.example.com/videos/watermark.png"); // Add user/password array if needed
80-
$fcj->set_thumbnail("sftp://www.example.com/httpdocs/videos/thumbs/", array("prefix" => "thumb_", "user" => "username", "password" => "password"));
74+
You can translate the JSON string into nested associative arrays so that you can dynamically change attributes like "input".
75+
The previous JSON example would become:
8176

82-
if($fcj->send()) {
83-
// Job was successfully requested. Store job ID if needed.
84-
echo "Success. Job ID is ".$fcj->id." Submitted at ".$fcj->initialized_job_at;
85-
} else {
86-
// Do something with the errors
87-
foreach($fcj->errors as $error) {
88-
echo $error;
89-
}
90-
}
77+
$encoding_job = new ZencoderJob(array(
78+
"api_key" => "93h630j1dsyshjef620qlkavnmzui3",
79+
"input" => "s3://bucket-name/file-name.avi",
80+
"outputs" => array(
81+
array(
82+
"label" => "web"
83+
)
84+
)
85+
));
9186

9287

9388

9489
NOTIFICATION HANDLING
9590
----------------------
96-
The FlixCloudNotificationHandler class is used to capture and parse XML data sent from
97-
FlixCloud when a job has been completed.
98-
99-
The possible states of the FlixCloudJobNotification object are "successful\_job",
100-
"cancelled\_job", or "failed\_job". A callback function allows you to respond accordingly.
101-
102-
**Notification URL must be set in <https://flixcloud.com/settings>**
103-
**A file following the example below should be at that URL**
91+
The ZencoderOutputNotification class is used to capture and parse JSON data sent from
92+
Zencoder to your app when an output file has been completed.
10493

105-
### EXAMPLE
10694

107-
require_once("FlixCloud.php");
10895

109-
$job_notification = FlixCloudNotificationHandler::catch_and_parse();
96+
### Step 1
97+
Create a script to receive notifications, and upload it to a location on your server that is publicly accessible.
11098

111-
switch ($job_notification->state) {
112-
case "successful_job":
99+
#### Example
100+
<?php
113101

114-
echo $job_notification->id."\n";
102+
// Make sure this points to a copy of Zencoder.php on the same server as this script.
103+
require("Zencoder.php");
115104

116-
echo $job_notification->output->url."\n";
117-
echo $job_notification->output->cost."\n";
105+
// Catch notification
106+
$notification = ZencoderOutputNotification::catch_and_parse();
118107

119-
echo $job_notification->input->url."\n";
120-
echo $job_notification->input->cost."\n";
108+
// Check output/job state
109+
if($notification->output->state == "finished") {
110+
echo "w00t!\n";
121111

122-
// echo $job_notification->watermark->url."\n";
123-
// echo $job_notification->thumbnail->url."\n";
124-
// echo $job_notification->pass_through."\n";
125-
126-
// Other info available. See FlixCloudJobNotification code.
127-
128-
break;
129-
case "cancelled_job":
130-
// Do something else
131-
break;
132-
case "failed_job":
133-
echo $job_notification->error_message;
134-
break;
135-
default:
112+
// If you're encoding to multiple outputs and only care when all of the outputs are finished
113+
// you can check if the entire job is finished.
114+
if($notification->job->state == "finished") {
115+
echo "Dubble w00t!";
116+
}
117+
} elseif ($notification->output->state == "cancelled") {
118+
echo "Cancelled!\n";
119+
} else {
120+
echo "Fail!\n";
121+
echo $notification->output->error_message."\n";
122+
echo $notification->output->error_link;
136123
}
137124

125+
?>
138126

127+
### Step 2
128+
In the parameters for an encoding job, add the URL for your script to the notifications array of each output you want to be notified for.
129+
Then submit the job to test if it works.
139130

140-
CHECKING JOB STATUS
141-
-------------------
142-
The easiest way to check a job's overall status is to use the following function. The first argument is the API key. The second argument is the job ID that you want to check.
143-
144-
require_once("FlixCloud.php");
145-
$job_status = get_flix_cloud_job_status("2j1l:kd3add:0:ivzf:2e1y", "12345");
146-
147-
There is actually more status info you can pull from the API, like progress for certain tasks. My guess is most people will just need the overall status of the job (i.e Transcoding, Uploading Output Files, Failed Job, etc.), so I haven't built in anything to specifically handle the individual tasks yet, however all of that info is available in the hash created from the XML in the FlixCloudJobStatusChecker object used in the following example. Check the API docs to see the specific info available.
131+
**You can view the results at:**
132+
<https://app.zencoder.com/notifications>
148133

149-
require_once("FlixCloud.php");
150-
$status_checker = new FlixCloudJobStatusChecker("2j1l:kd3add:0:ivzf:2e1y", "12345");
151-
$job_status = $status_checker->get_job_status();
152-
153-
// Example of extra info
154-
$transcoding_task_state = $status_checker->$result_hash["transcoding-task"]["state"][0];
155-
$transcoding_task_progress = $status_checker->$result_hash["transcoding-task"]["state"][1];
156-
157-
$input_file_upload_task_state = $status_checker->$result_hash["input-media-file-task"]["state"][0];
158-
$input_file_upload_task_progress = $status_checker->$result_hash["input-media-file-task"]["state"][1];
134+
#### Example
135+
...
136+
"outputs" => array(
137+
array(
138+
"label" => "web",
139+
"notifications" => array("http://example.com.com/encoding/notification.php")
140+
),
141+
array(
142+
"label" => "iPhone",
143+
"notifications" => array("http://example.com.com/encoding/notification.php")
144+
)
145+
)
146+
...
159147

160148

149+
### Step 3
150+
Modify the above script to meet your needs.
151+
Your [notifications page](https://app.zencoder.com/notifications) will come in handy.
161152

162153
VERSIONS
163154
---------
164155

165-
Version 1.1.0 - 08/31/09 Added Status Checking (Class and basic function).
166-
Added Notification URL setting.
167-
Added Pass Through.
168-
Changed require() to require_once() in readme examples. Not a required update.
169-
170-
Version 1.0.8 - 07/08/09 Added thumbnail support for Job. (With help from Aaron Boushley)
171-
Added thumnail info to Notification.
172-
Removed User/Password validation on files. It blocked blank values, which could be valid.
173-
Added handling of multi-level errors from XML response (flattened array)
174-
Removed backward compatibility in Notification for $fcjn->input_media_file syntax, now must use $fcjn->input->url;
175-
176-
Version 1.0.7 - 04/17/09 Updated notification object to match new XML version
177-
178-
Version 1.0.6 - 04/14/09 Cleaned up the documentation a little.
179-
180-
Version 1.0.5 - 04/06/09 Added options for pointing to the certificate or certificate directory.
181-
182-
Version 1.0.4 - 04/06/09 Added option to connect insecurely incase SSL cert isn't working. (Like curl -k)
183-
184-
Version 1.0.3 - 04/06/09 Added backward compatability for recipe as second argument
185-
Added Curl error checking
186-
Added more detailed unknown error reporting
187-
Formatted XML a little
188-
189-
Version 1.0.2 - 04/05/09 * Now requiring API key on object creation, and added an optional params hash
190-
for setting file info and sending on creation (example 2). *
191-
* Recipe is no longer second argument *
192-
* Broke up notification handling into 2 objects (see example) *
193-
FlixCloudNotificationHandler => Catch and parse XML
194-
FlixCloudJobNotification => Holds job notification info.
195-
Added escaping of special characters when creating XML tags.
196-
Removed protocol checking for now, because may want to just let the API do that.
197-
On job->send changed status code handling to a switch statement.
198-
199-
Version 1.0.1 - 04/02/09 Fixed acceptable protocols for some of the file types.
200-
201-
202-
203-
NOTES:
204-
-------
205-
Suggestions -> (steve (a) sevenwire () c&#1;om)
206-
207-
### Windows
208-
If you're using the curl command line tool on Windows, curl will search
209-
for a CA cert file named "curl-ca-bundle.crt" in these directories and in
210-
this order:
211-
1. application's directory
212-
2. current working directory
213-
3. Windows System directory (e.g. C:\windows\system32)
214-
4. Windows Directory (e.g. C:\windows)
215-
5. all directories along %PATH%
216-
[link](http://curl.haxx.se/docs/sslcerts.html)
156+
Version 1.0 - 2010-04-02 Jobs and Notifications.

0 commit comments

Comments
 (0)