Tag Archives: YouTube

Check YouTube Video Existence with Zend_Gdata_YouTube

The Video Has Been Removed?!

Have you ever seen the famous message on YouTube: “This video has been removed by the user.”, but what if you’re trying to grab that video via the Zend_Gdata_YouTube?

That can happen when you’re reading the feed for a channel or a user’s list of videos. In the feed everything’s OK – once the video is uploaded it appears into the feed. After that the user removes the video and visiting the link from the feed you’ll get the message above.

Actually what happens when you try to read this “video entry” within a Zend Framework’s application. There must be some way to catch this message?

Trying to Catch

The answer is pretty simple! Zend_Gdata_YouTube’s throwing an exception and it can be easily cached. Here’s some source code:

$apiKey = 'your_api_key';
$client = new Zend_Http_Client();
$gdata = new Zend_Gdata_YouTube($client, 'my-app', null, $apiKey);
try {
       $gdata->getVideoEntry($video_id);
} catch(Zend_Gdata_App_Exception $e) {
       echo $e->getMessage();
}

Force Zend Casting and Help the IDE Autocompletion

IDEs and Autocompletion

One of my favorite things in IDEs, in my case Eclipse for Mac, is that they offer you the option of autocompletion. No developer knows the entire set of functions of the language he uses, neither the set of parameters of them. That’s why IDEs come to help.

In many cases when casting is not obvious and method call chain is to large your IDE may refuse to help you with this brilliant functionality. To be more precise let me give you an example.

In Zend Framework I was trying to fetch a RSS via Gdata interface. Something like that:

$videoFeed = $gdata->getUserUploads('youtube_username');
foreach ($videoFeed as $entry) {
    // do something
}

The problem is that whenever I try to do $entry-> in the body of the foreach loop I don’t see what methods are supported by the Zend_Gdata_YouTube_VideoEntry class. So I tried to force the casting of $entry to this class definition and it worked like a charm for me. The thing I’ve done was to add a definition of $entry before the loop body:

$videoFeed = $gdata->getUserUploads('youtube_username');
$entry = new Zend_Gdata_YouTube_VideoEntry();
foreach  ($videoFeed as $entry) {
    // do something
}

Than whenever you try to type $entry-> you’d receive a list of methods from the class definition of Zend_Gdata_YouTube_VideoEntry.

Thanks to Roy Ganor there’s a more elegant way to do this, simply by adding @var comment:

/* @var $entry Zend_Gdata_YouTube_VideoEntry */

Video sites must use … mp4 and only mp4!

H.264

Yes it may sound strange, but now with the upcoming HTML5 features every browser again is playing its own game. Firefox and Opera support only OGG Theora, Chrome and Safari only MP4 and what about IE .. it doesn’t support anything. Than why should we convert to mp4 with h.264 codec?

Because everybody is playing flash

And that’s again very sad but at least the flash players are playing mp4 with this encoding, which is good because this file will be playable under most of the mobiles. And if you have a large video site to support why don’t you convert to mp4 and play it with a Flash Player and give the opportunity to play mp4 on mobile.

Only one file under the sky

Thus you gain to keep only one file – playable under every device?

YouTube and FLV

Now I wonder why YouTube have both FLV and MP4 formats?

Of course if you’d like to be perfect …

Convert every video to MP4, FLV and OGG, but that means 3 files for every video?!

YouTube and Vimeo goes HTML5 with video tag usage! Catch them up!

What better example than that coming both from YouTube and Vimeo. Although video tag is not supported except under Safari and Chrome, that’s the future everyone’s going to embed sooner or later.

And if these “big players” are going that way, don’t hesitate to follow them! HTML5 is really what we as web developers were waiting for so long and even all of the problems during its standardization process it’s really cool there will be tags like video.

What YouTube is doing today, perhaps will seem normal to everyone tomorrow. However there are some questions still with no answer, as where the flash possibility to add ads into the player is going?! But we’re about to see great things from these two sites!

Just check out these two links:

Youtube HTML5

Vimeo