From 71da2f74b621c838f835fd04d6f2d737bfceb6b0 Mon Sep 17 00:00:00 2001 From: Horus3 Date: Wed, 26 Feb 2014 19:48:59 +0100 Subject: merged into one file --- www/youtube.php | 57 ++++++++++++++++++++++++++++++++++++++--------- www/youtube_functions.php | 40 --------------------------------- www/zend_init.php | 8 ------- 3 files changed, 47 insertions(+), 58 deletions(-) delete mode 100644 www/youtube_functions.php delete mode 100644 www/zend_init.php 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 @@ + +Random Youtube Video +
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: " . $searchstring . "

"; +$videoID = start($yt); ?> +A random youtube video!
>

Get another one! diff --git a/www/youtube_functions.php b/www/youtube_functions.php deleted file mode 100644 index 17a8964..0000000 --- a/www/youtube_functions.php +++ /dev/null @@ -1,40 +0,0 @@ -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; -} diff --git a/www/zend_init.php b/www/zend_init.php deleted file mode 100644 index abfad93..0000000 --- a/www/zend_init.php +++ /dev/null @@ -1,8 +0,0 @@ -setMajorProtocolVersion(2); -- cgit v1.2.3