views:

96

answers:

2

Hi,

is any method to validate Youtube video link with Zend-framework ?

If user inputs not valid link, for example http://www.youtube.com/watch?00zzv=nel how can I check it before inserting into site ?

+1  A: 

I don't know if it is possible, however, I would take a different approach and try and see if the link has comments on it.

Take this for example. From here: http://framework.zend.com/manual/en/zend.gdata.youtube.html

$yt = new Zend_Gdata_YouTube();
$commentFeed = $yt->getVideoCommentFeed('abc123813abc');

foreach ($commentFeed as $commentEntry) {
    echo $commentEntry->title->text . "\n";
    echo $commentEntry->content->text . "\n\n\n";
}

If you use the video id in the VideoCommentFeed argument, you will be able to get the value in $commentFeed. If you then get an error, you know that the video does not exist.

I am sure if you try other methods you will probably find example what you want.

Laykes
+1  A: 

I'm pretty sure that there is no built in validator for this, but writing custom validators is super easy:

class My_Validate_Youtube extends Zend_Validate_Abstract{

    public function isValid($value){
        // check url here
        if (no_good($value)){
            $this->_error("Explain the error here");
            return false;
        }
        return true;
    }

}

Just put whatever checks you need in that class, and run the validator on any Youtube links to be checked.

edit: From Laykes, you might want to consider using the validator to check if the video actually exists, instead of determining if it fits a pattern. Depends on your use cases though- eg how much latency do you want to introduce by making a call to the Youtube API?

Johrn
Thank you for your answers. I decided to write my own custom function for validation. But it only validates the video link with regexp.