diff options
| author | Horus3 | 2014-02-26 19:48:59 +0100 |
|---|---|---|
| committer | Horus3 | 2014-02-26 19:48:59 +0100 |
| commit | 71da2f74b621c838f835fd04d6f2d737bfceb6b0 (patch) | |
| tree | e9361dbd2fcdd33cedff84c73add9c6cf892373d /www/youtube.php | |
| parent | f4c30ebad16c0b72aaf122dab4fb193c780e2ac9 (diff) | |
| download | random-71da2f74b621c838f835fd04d6f2d737bfceb6b0.tar.gz | |
merged into one file
Diffstat (limited to 'www/youtube.php')
| -rw-r--r-- | www/youtube.php | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/www/youtube.php b/www/youtube.php index 062456b..311b2c4 100644 --- a/www/youtube.php +++ b/www/youtube.php @@ -1,11 +1,41 @@ <!Doctype html> +<head> +<title>Random Youtube Video</title> +</head> <body> <center> <?php -require("zend_init.php"); //generates the $yt object, API version 2 -require("youtube_functions.php"); +// generates the $youtube object with API version 2 +$clientLibraryPath = "../zend/library"; +$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath); + +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(); +$yt->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) { @@ -34,22 +64,29 @@ function printVideoEntry($videoEntry) return $videoId; } +function start($yt){ + $searchstring = searchterm(); -$searchstring = searchterm(); + $location = $yt->newVideoQuery(); + $location->setOrderBy('viewCount'); + $location->setSafeSearch('none'); + $location->setVideoQuery($searchstring); -$location = $yt->newVideoQuery(); -$location->setOrderBy('viewCount'); -$location->setSafeSearch('none'); -$location->setVideoQuery($searchstring); - -$videoID = getAndPrintVideoFeed($location, $yt); + $videoID = getAndPrintVideoFeed($location, $yt); + if(file_get_contents("https://gdata.youtube.com/feeds/api/videos/" . $videoID . "")){ + return $videoID; + } else { + start(); + } +} -echo "Your youtube Video with the search string: <font color='green'>" . $searchstring . "</font><br> <br>"; +$videoID = start($yt); ?> +A random youtube video! <br>> <iframe width="560" height="315" src="//www.youtube.com/embed/<? echo $videoID ?>" frameborder="0" allowfullscreen></iframe> <br><br> <a href="youtube.php">Get another one!</a> |
