Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting time length of youtube video file

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?

like image 984
theGame Avatar asked Dec 28 '22 12:12

theGame


2 Answers

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'/>

like image 129
Daren Chandisingh Avatar answered Jan 06 '23 05:01

Daren Chandisingh


Per their docs, In a video feed entry, the <yt:duration> tag specifies a video's length.

like image 43
AlienWebguy Avatar answered Jan 06 '23 04:01

AlienWebguy