google_and_youtube_api.php
<?php
class VideoListGenerator {
public function youtube_video_api_search($file_handle,$phrase){
$encoded_phrase = urlencode($phrase);
// Access the Youtube REST API - Maximum allowable results is 50
$url = "http://gdata.youtube.com/feeds/api/videos?vq=%22$encoded_phrase%22&max-results=50";
$library = new simpleXMLElement($url,NULL,TRUE);
foreach ($library->entry as $child)
{
// echo $child->getName()."<br />";
$video_unit = $child->title."\t";
$video_unit .= $child->link['href']."\t";
$video_unit .= $phrase."\n";
//echo $video_unit;
fwrite($file_handle,$video_unit);
}
}//end func
public function google_video_api_search($file_handle,$phrase){
$encoded_phrase = urlencode($phrase);
// Access Google Video RSS FEED - search 150 results
$google_url = "http://video.google.com/videosearch?q=$encoded_phrase&output=rss&num=150";
$google_library = new simpleXMLElement($google_url,NULL,TRUE);
$google_array = array();
$skip = TRUE;
foreach ($google_library->children() as $child)
{
foreach ($child->children() as $subchild){
foreach ($subchild->title as $it){
if ($skip){
$skip = FALSE;
} else {
//echo $it;
fwrite($file_handle,$it."\t");
}
}
foreach ($subchild->guid as $guid){
//echo $guid."<br />";
fwrite($file_handle,$guid."\t".$phrase."\n");
}
}
}
}//end func
} //end class
# MAIN
if (isset($_POST['keyword_phrase']) && isset($_POST['submit'])){
//////////////////////////////////////////////////////////
date_default_timezone_set('UTC');
$file = 'VLG_'.date('Y_m_d_h_i_s').'.csv';
$file_handle = fopen($file,"a+");
$vlg = new VideoListGenerator();
$vlg->youtube_video_api_search($file_handle,$_POST['keyword_phrase']);
$vlg->google_video_api_search($file_handle,$_POST['keyword_phrase']);
fclose($file_handle);
echo "<br /><br />Completed Successfully<br /><br />Generated File: $file<br /><br />Using Keyword/Phrase: $_POST[keyword_phrase]";
echo '<br /><br /><a href="'.$file.'">Download File</a>';
///////////////////////////////////////////////////////////
}
?>
<div align="center">
<table cellpadding="3" cellspacing="3" style="border:1px solid #e0e0e0;padding:3em;margin-top:3em">
<tr>
<td><span style="font-weight:bold;font-family:verdana,ariel,sans-sherif">Enter your keywords or keyphrase to generate csv file</span></td>
</tr>
<tr>
<td>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="keyword_phrase" size="40" />
<input type="submit" value="Generate" name="submit" />
</form>
</td>
</tr>
</table>
</div>
Paul's Code Library
Categories
HomeAJAX
classes
database_functions
date_functions
file_functions
googlevideo_and_youtube_api
htaccess
image_functions
string_functions