setMajorProtocolVersion(2);
function searchterm(){
$db = new SQLite3("../database/dict.db");
$table_array = array("english", "german");
$table_count = count("$table_array");
$table=$table_array[0]; // choose the language
$rows = $db->query("SELECT count(*) as count FROM ". $table . ";");
$row = $rows->fetchArray();
$numRows = $row["count"];
$random = mt_rand(1,$numRows);
$search_word_db = $db->query("SELECT word FROM " . $table . " WHERE id=" . $random . ";");
$search_word_ar = $search_word_db->fetchArray();
$search_word = $search_word_ar["word"];
return $search_word;
}
function getAndPrintVideoFeed($location, $yt)
{
$videoFeed = $yt->getVideoFeed($location);
$videoID = printVideoFeed($videoFeed);
return $videoID;
}
function printVideoFeed($videoFeed)
{
$res_quant = count($videoFeed);
$video = mt_rand(1, $res_quant);
$videoId = printVideoEntry($videoFeed[$video]);
return $videoId;
}
function printVideoEntry($videoEntry)
{
$videoId = $videoEntry->getVideoId();
return $videoId;
}
function start($yt){
$searchstring = searchterm();
$location = $yt->newVideoQuery();
$location->setOrderBy('viewCount');
$location->setSafeSearch('none');
$location->setVideoQuery($searchstring);
$videoID = getAndPrintVideoFeed($location, $yt);
if(file_get_contents("https://gdata.youtube.com/feeds/api/videos/" . $videoID . "")){
return $videoID;
} else {
start();
}
}
$videoID = start($yt);
?>
A random youtube video!
>
Get another one!