From eecb232938a20bd33eb5928e54d7fd3cffea9b2a Mon Sep 17 00:00:00 2001 From: Horus3 Date: Wed, 12 Mar 2014 16:01:48 +0100 Subject: Bugfixed and error routine. --- www/youtube.php | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/www/youtube.php b/www/youtube.php index 37654e5..ab8a9c8 100644 --- a/www/youtube.php +++ b/www/youtube.php @@ -1,11 +1,3 @@ - - -Random Youtube Video - - - -
- setMajorProtocolVersion(2); +function error(){ + header("Refresh: 0; /youtube"); + exit; +} + function searchterm(){ $db = new SQLite3("../database/dict.db"); @@ -31,6 +28,9 @@ function searchterm(){ $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"]; @@ -41,7 +41,13 @@ function getAndPrintVideoFeed($location, $yt) { $videoFeed = $yt->getVideoFeed($location); + if(empty($videoFeed)){ + error(); + } $videoID = printVideoFeed($videoFeed); + if(empty($videoID)){ + error(); + } return $videoID; } @@ -51,8 +57,14 @@ 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; @@ -61,6 +73,9 @@ function printVideoFeed($videoFeed) function printVideoEntry($videoEntry) { $videoId = $videoEntry->getVideoId(); + if(empty($videoId)){ + error(); + } return $videoId; } @@ -69,25 +84,41 @@ 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(); + start($yt); } } $videoID = start($yt); ?> + + +Random Youtube Video + + + +

A random youtube video!


-

+

Get another one -- cgit v1.2.3