From 293e2d3203d4f473f3239571b5d0237cea26a46b Mon Sep 17 00:00:00 2001 From: root Date: Sun, 23 Mar 2014 00:04:34 +0100 Subject: Completed youtube history for the browser. --- www/.index.php.swp | Bin 0 -> 12288 bytes www/func_youtube.php | 111 ----------------------------------------- www/functions/func_puush.php | 34 +++++++++++++ www/functions/func_youtube.php | 111 +++++++++++++++++++++++++++++++++++++++++ www/header.php | 6 ++- www/include.php | 6 +++ www/index.php | 5 +- www/print_index.php | 62 +++++++++++++++++++++++ www/puush.php | 41 +++------------ www/youtube.php | 6 ++- 10 files changed, 233 insertions(+), 149 deletions(-) create mode 100644 www/.index.php.swp delete mode 100644 www/func_youtube.php create mode 100644 www/functions/func_puush.php create mode 100644 www/functions/func_youtube.php create mode 100644 www/include.php create mode 100644 www/print_index.php (limited to 'www') diff --git a/www/.index.php.swp b/www/.index.php.swp new file mode 100644 index 0000000..61c46e1 Binary files /dev/null and b/www/.index.php.swp differ diff --git a/www/func_youtube.php b/www/func_youtube.php deleted file mode 100644 index 74aa679..0000000 --- a/www/func_youtube.php +++ /dev/null @@ -1,111 +0,0 @@ -setMajorProtocolVersion(2); - - -function error(){ - header("Refresh: 0; /youtube"); - exit; -} - -function searchterm(){ - $db = new SQLite3("../database/dict.db"); - - $table_array = array("english", "german"); - - $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 . ";"); - if(empty($search_word_db)){ - error(); - } - $search_word_ar = $search_word_db->fetchArray(); - $search_word = $search_word_ar["word"]; - - return $search_word; -} - -function getAndPrintVideoFeed($location, $yt) -{ - - $videoFeed = $yt->getVideoFeed($location); - if(empty($videoFeed)){ - error(); - } - $videoID = printVideoFeed($videoFeed); - if(empty($videoID)){ - error(); - } - return $videoID; -} - -function printVideoFeed($videoFeed) -{ - - $res_quant = count($videoFeed); - - $video = mt_rand(0, $res_quant-1); - - if(empty($video)){ - error(); - } - - $videoId = printVideoEntry($videoFeed[$video]); - if(empty($videoId)){ - error(); - } - - return $videoId; - -} - -function printVideoEntry($videoEntry) -{ - $videoId = $videoEntry->getVideoId(); - if(empty($videoId)){ - error(); - } - return $videoId; -} - -function start($yt){ - - $searchstring = searchterm(); - - $location = $yt->newVideoQuery(); - if(empty($location)){ - error(); - } -// $location->setOrderBy('viewCount'); - $location->setSafeSearch('none'); - $location->setVideoQuery($searchstring); - if(empty($location)){ - error(); - } - - $videoID = getAndPrintVideoFeed($location, $yt); - if(empty($videoID)){ - error(); - } - - if(fopen("https://gdata.youtube.com/feeds/api/videos/" . $videoID , "r")){ - return $videoID; - } else { - start($yt); - } - -} - diff --git a/www/functions/func_puush.php b/www/functions/func_puush.php new file mode 100644 index 0000000..472bd7b --- /dev/null +++ b/www/functions/func_puush.php @@ -0,0 +1,34 @@ +" . $id .""; + return $count; + } else { + $count = $count + 1; + if($count < 100){ + $count = get_image($count); + } else { + echo "We tried for " . $count . " times. Now is enough.

"; + echo "Try again"; + exit; + } + } + return $count; +} + diff --git a/www/functions/func_youtube.php b/www/functions/func_youtube.php new file mode 100644 index 0000000..74aa679 --- /dev/null +++ b/www/functions/func_youtube.php @@ -0,0 +1,111 @@ +setMajorProtocolVersion(2); + + +function error(){ + header("Refresh: 0; /youtube"); + exit; +} + +function searchterm(){ + $db = new SQLite3("../database/dict.db"); + + $table_array = array("english", "german"); + + $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 . ";"); + if(empty($search_word_db)){ + error(); + } + $search_word_ar = $search_word_db->fetchArray(); + $search_word = $search_word_ar["word"]; + + return $search_word; +} + +function getAndPrintVideoFeed($location, $yt) +{ + + $videoFeed = $yt->getVideoFeed($location); + if(empty($videoFeed)){ + error(); + } + $videoID = printVideoFeed($videoFeed); + if(empty($videoID)){ + error(); + } + return $videoID; +} + +function printVideoFeed($videoFeed) +{ + + $res_quant = count($videoFeed); + + $video = mt_rand(0, $res_quant-1); + + if(empty($video)){ + error(); + } + + $videoId = printVideoEntry($videoFeed[$video]); + if(empty($videoId)){ + error(); + } + + return $videoId; + +} + +function printVideoEntry($videoEntry) +{ + $videoId = $videoEntry->getVideoId(); + if(empty($videoId)){ + error(); + } + return $videoId; +} + +function start($yt){ + + $searchstring = searchterm(); + + $location = $yt->newVideoQuery(); + if(empty($location)){ + error(); + } +// $location->setOrderBy('viewCount'); + $location->setSafeSearch('none'); + $location->setVideoQuery($searchstring); + if(empty($location)){ + error(); + } + + $videoID = getAndPrintVideoFeed($location, $yt); + if(empty($videoID)){ + error(); + } + + if(fopen("https://gdata.youtube.com/feeds/api/videos/" . $videoID , "r")){ + return $videoID; + } else { + start($yt); + } + +} + diff --git a/www/header.php b/www/header.php index 4df6d9e..dff4355 100644 --- a/www/header.php +++ b/www/header.php @@ -7,7 +7,11 @@ if(isset($new_id)){ echo "Youtube"; } else { - echo "Youtube"; + if(isset($videoID)){ + echo "Youtube"; + } else { + echo "Youtube"; + } } ?> | diff --git a/www/include.php b/www/include.php new file mode 100644 index 0000000..ad9562d --- /dev/null +++ b/www/include.php @@ -0,0 +1,6 @@ + + + +Welcome + + + + + + + +
+ + + +
+

Welcome!

+ ?> + +
+On this website, you can get a random +
+
+
+ +
+
+completely free and as often as you like. +
+ +

+For comments, questions or suggestions drop a
mail. + + + + + diff --git a/www/puush.php b/www/puush.php index 58b4ee6..5757360 100644 --- a/www/puush.php +++ b/www/puush.php @@ -1,3 +1,6 @@ + Random Youtube Video @@ -8,47 +11,17 @@

A random "puu.sh" file!


-" . $id .""; - return $count; - } else { - $count = $count + 1; - if($count < 100){ - $count = get_image($count); - } else { - echo "We tried for " . $count . " times. Now is enough.

"; - echo "Try again"; - exit; - } - } - return $count; -} +$count = get_image($count); $count = get_image($count); diff --git a/www/youtube.php b/www/youtube.php index 866ffea..abf0a53 100644 --- a/www/youtube.php +++ b/www/youtube.php @@ -1,9 +1,11 @@