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 +++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 47 insertions(+), 10 deletions(-)
(limited to 'www/youtube.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!
--
cgit v1.2.3