Zend Framework and Youtube API

I have been messing around with the different Zend_Service components available in the framework, and in general am very pleased with the ease of use and functionality. However, Zend_Gdata seems somewhat complicated. Now I must admit that I have not spent much time with classes, and I am sure the structure is set up to accommodate the large amount of services that Google provides, but there is very little documentation and the API doesn’t seem easily comprehensible, atleast compared to the Yahoo and Technorati APIs.

It appears that Google staff wrote the code, and I guess that is why it breaks with the naming convention - i.e. all the other Services fall under Zend_Services_***, while Google’s is Zend_Gdata. I am interested in the Youtube API, and it was easy to construct the query and get the result set back, but I found the result set to contain a lot of information (most of which was extraneous from my point of view), with many classes in it. Again, I was quickly trying to get it working and not at all interested in spending a lot of time learning the ins and outs of Google’s API’s. I am sure it will all click as I learn the other parts of Zend_Gdata, but for now, it is a pain.

For example, using the code from the documentation, when you grab a result set and iterate through it, how do you grab the src for the flash movie? Digging through the code, I found it was $videoEntry->mediaGroup->content[0]->getUrl(). That’s not to difficult, but then I noticed some of the results didn’t have any data for $videoEntry->mediaGroup->content. Is that a fluke, or by design? What do the values in the content object mean? I can guess what isDefault means and most of them are obvious, but the comments in the code are completely worthless (well not completely, as it does tell me that the channels property of the MediaContent object is a integer…). What’s the deal with the array of values - is the first value in the thumbnail array the preferable image, or just the first frame from the movie? I tried looking at the Google API docs, but that surprisingly didn’t seem to shed much light either.

I guess I should get off my ass, learn the API and contribute to the documentation. But its just so much easier to complain. Anyways, here is what I have quickly worked out. Once I start playing with the other Google services and have a better understanding of how all the classes fit together, I’ll let you know…


<?php
        $yt 
= new Zend_Gdata_YouTube();
$query $yt->newVideoQuery();
$query->videoQuery ‘cat’;
$query->startIndex 10;
$query->maxResults 20;
$query->orderBy ‘viewCount’;

echo $query->queryUrl “n”;
$videoFeed $yt->getVideoFeed($query); 

foreach ($videoFeed as $videoEntry) {
  echo 
“———VIDEO———-n”;
  echo 
“Title: ” $videoEntry->mediaGroup->title->text “n”;
  echo 
“Description:” $videoEntry->mediaGroup->description->text “n”;
  echo 
“Url to the Youtube page: ” $videoEntry->mediaGroup->player[0]->getUrl() . “n”;
  echo 
“Thumbnail image of the video: ” .  $videoEntry->mediaGroup->thumbnail[0]->getUrl() . “n”;
  if(!empty(
$videoEntry->mediaGroup->content[0])) {
      echo 
“Src to the video : ” $videoEntry->mediaGroup->content[0]->getUrl() . “n”;
  }
  echo 
“nnn”;
}

?>


3 Responses to “Zend Framework and Youtube API”

  1. Jochen Says:

    Robert,

    Thanks for the blog post. I work on the PHP Client Library components at Google and am responsible for some of the code that you mention. I agree that the class structure is quite verbose.

    We also need to update our own documentation on the Zend site. In the meantime you may want to check out the PHP Developer Guide on code.google.com which details the helper methods that we have for accessing video meta-data:

    http://code.google.com/apis/youtube/developers_guide_php.html#RetrievingVideoInfo

    So you can do for example:


    print $entry->getVideoDescription();
    print $entry->getFlashPlayerUrl();

    The thumbnail array contains a value for each XML element:

    The attributes correspond to the XML attributes. Three thumbnails are automatically generated for each video during the trans-coding process.

    I hope this helps. For information about how to use the PHP Client Library to perform video uploads you can also check out our video:

    http://www.youtube.com/watch?v=iIp7OnHXBlo

    Please note that the helper methods such as ->SetVideoTitle() discussed in the video are in Zend /trunk

    We are planning to write a more high-level class that sits on top of the Zend_Gdata classes to abstract 90% of the YouTube API functionality to help developers that just want to get up and running with the YouTube API without having to dig too deeply into the class hierarchy.

    If you are interested please feel free to contribute some ideas or code for the issue linked here:

    http://framework.zend.com/issues/browse/ZF-3467

    Whew. That was long. We appreciate your feedback ! Please ping me if you have any other questions!

    Thanks
    - Jochen

  2. Jochen Says:

    Looks like the XML got cut off by Word Press’s input filter. The XML that I was referring to with regards to thumbnails can be found at the link below:

    http://code.google.com/apis/youtube/developers_guide_protocol.html#Understanding_Video_Entries

  3. Administrator Says:

    Jochen - thanks for the response. I am glad to hear of the plans to write a higher level class and I also appreciate the links to more documentation. Its great you are contributing to the Zend Framework and also listening to the community. Hopefully I can get some time to contribute, because as I mentioned in my post, it is easy to sit on the sidelines and complain than to help out!

    Again, glad you are actively working on things and I look forward to seeing what’s in the pipeline. I think an easier abstraction that provides 80% of the functionality will be appreciated by people!

Leave a Reply