I am having a problem. how to get the time duration of youtube video? Here is the scenario.
I have a input field in this field say i enter youtube url now i want to put a validation that video should only be of 1 min, if yes then i store this in database else i show an error message.
is it possible to do this thing?
You can use the data API to get the information for a video. You might need to extract the video's identifier from the URL.
http://code.google.com/apis/youtube/2.0/developers_guide_php.html#Retrieving_Video_Entry
If you're using Zend, there's already a class to do the heavy lifting:
<?php
require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$yt = new Zend_Gdata_YouTube();
$videoEntry = $yt->getVideoEntry('the0KZLEacs');
$duration = $videoEntry->getVideoDuration();
If not, you can go to http://gdata.youtube.com/feeds/api/videos/{$videoId}
and get an XML document to process yourself.
For example, http://gdata.youtube.com/feeds/api/videos/KURI9EQV3dY returns an XML document for a video which contains information including the duration: <yt:duration seconds='153'/>
Per their docs, In a video feed entry, the <yt:duration> tag specifies a video's length.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With