Saturday, December 11, 2010

Updates to my bread and butter.

I just updated my YouTube library to incorporate a suggestion to allow direct uploading from your server to the YouTube servers. The new method is called "directUpload" and takes 4 parameters. The first is the path to the file to upload from your server. The second is the mime-type of the video (video/mp4, etc.). The third is the XML meta data that goes with this video, you can learn what this is here but it is essentially the same as what you would do for a form upload token. The final parameter is optional and defines the user whose account this belongs to, if you leave it blank it will go to the currently authenticated user.

Here is a sample call with the video to upload in the CI root directory:

$xml = '<?xml version="1.0"?><entry xmlns="" xmlns:media="" xmlns:yt=""><media:group><media:title type="plain">Test Video</media:title><media:description type="plain">This is a direct upload test</media:description><media:category scheme="">People</media:category><media:keywords>test, upload</media:keywords></media:group></entry>';

$this->youtube->directUpload("test.3gp", 'video/3gp', $xml);

You may wish to note that uploading a large file could take awhile and this library doesn't currently support resumable uploads so you just have to wait it out if things are taking awhile. As always you can turn on the DEBUG flag at the top and watch your error log for more info on what is going on.

While I was in there I took the liberty to fix a bug where only a response of 200 was deemed success by the library now any 200 level response is considered successful as it should be.

Here is the updated library:

If you are new here consult my other posts for more information.