Skip to content

Commit 0b8fc32

Browse files
committed
First commit.
0 parents  commit 0b8fc32

File tree

3 files changed

+766
-0
lines changed

3 files changed

+766
-0
lines changed

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2010 Zencoder
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.markdown

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
Zencoder API PHP Library
2+
==========================
3+
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;
62+
} else {
63+
// Do something with the errors
64+
foreach($fcj->errors as $error) {
65+
echo $error;
66+
}
67+
}
68+
69+
70+
### EXAMPLE 2 (setting properties separately)
71+
72+
require_once("FlixCloud.php");
73+
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"));
81+
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+
}
91+
92+
93+
94+
NOTIFICATION HANDLING
95+
----------------------
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**
104+
105+
### EXAMPLE
106+
107+
require_once("FlixCloud.php");
108+
109+
$job_notification = FlixCloudNotificationHandler::catch_and_parse();
110+
111+
switch ($job_notification->state) {
112+
case "successful_job":
113+
114+
echo $job_notification->id."\n";
115+
116+
echo $job_notification->output->url."\n";
117+
echo $job_notification->output->cost."\n";
118+
119+
echo $job_notification->input->url."\n";
120+
echo $job_notification->input->cost."\n";
121+
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:
136+
}
137+
138+
139+
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.
148+
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];
159+
160+
161+
162+
VERSIONS
163+
---------
164+
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)

0 commit comments

Comments
 (0)