How to search for vedio from the youtube and fetch the metadata

Purpose

This will help you to search the video from youtube according to your query. And you can get all the meta data for the fetch result.

Platform

-PHP

Prerequisites

php zend framework.

You can download the zend framework from the  http://framework.zend.com/downloads/latest .

Code Snippet

<?php

//path of you zend framework

set_include_path(‘C:/wamp/bin/php/zend_framework/library’ . PATH_SEPARATOR . get_include_path());

//default
require_once ‘Zend/Loader.php’;
Zend_Loader::loadClass(‘Zend_Gdata_YouTube’);

function searchAndPrint()
{

$yt = new Zend_Gdata_YouTube();
$query = $yt->newVideoQuery();

//search Key word
$query->videoQuery = ‘any thing you want to search’;

//search result start index
$query->startIndex = 1;

//number of results fetched
$query->maxResults = 8;

//order by creiteria
$query->orderBy = ‘viewCount’;

////category of your search
$query->category = ‘Trailers’;
$videoFeed = $yt->getVideoFeed($query);

?>
<?php

//print the result
foreach ($videoFeed as $videoEntry) {
echo “———VIDEO———-<br>”;
echo “Title: ” . $videoEntry->getVideoTitle() . “<br>”;
echo “\nDescription:<br>”;
echo $videoEntry->getVideoDescription();
echo “Video ID: ” . $videoEntry->getVideoId() . “<br>”;
echo ‘Updated: ‘ . $videoEntry->getUpdated() . “\n”;
echo ‘Category: ‘ . $videoEntry->getVideoCategory() . “\n”;
echo ‘Tags: ‘ . implode(“, “, $videoEntry->getVideoTags()) . “\n”;
echo ‘Watch page: ‘ . $videoEntry->getVideoWatchPageUrl() . “\n”;
echo ‘Flash Player Url: ‘ . $videoEntry->getFlashPlayerUrl() . “\n”;
echo ‘Duration: ‘ . $videoEntry->getVideoDuration() . “\n”;
echo ‘View count: ‘ . $videoEntry->getVideoViewCount() . “\n”;
echo ‘Rating: ‘ . $videoEntry->getVideoRatingInfo() . “\n”;
echo ‘Geo Location: ‘ . $videoEntry->getVideoGeoLocation() . “\n”;
echo ‘Recorded on: ‘ . $videoEntry->getVideoRecorded() . “\n”;

}

}

?>

Query Attributes Tutorials

https://developers.google.com/youtube/2.0/reference?csw=1#Searching_for_videos

https://developers.google.com/youtube/2.0/developers_guide_php?csw=1#SearchingVideos

Advertisements