diff options
| author | Horus3 | 2014-02-26 16:47:23 +0100 |
|---|---|---|
| committer | Horus3 | 2014-02-26 16:47:23 +0100 |
| commit | 01e3fb742f09593532e5db5f3c780577c1ca2dec (patch) | |
| tree | 2ba7640594d9bf7d6278f528726784310de33667 | |
| parent | 17dc93eab267a25e0620576f1ce62bf8ffc417ab (diff) | |
| download | random-01e3fb742f09593532e5db5f3c780577c1ca2dec.tar.gz | |
random search word is generated
| -rw-r--r-- | www/youtube.php | 112 | ||||
| -rw-r--r-- | www/youtube_functions.php | 35 |
2 files changed, 87 insertions, 60 deletions
diff --git a/www/youtube.php b/www/youtube.php index a035fe0..01db8d7 100644 --- a/www/youtube.php +++ b/www/youtube.php @@ -1,86 +1,78 @@ <?php require("zend_init.php"); //generates the $yt object, API version 2 +require("youtube_functions.php"); function getAndPrintVideoFeed($location, $yt) { -$videoFeed = $yt->getVideoFeed($location); - printVideoFeed($videoFeed); + $videoFeed = $yt->getVideoFeed($location); + printVideoFeed($videoFeed); } function printVideoFeed($videoFeed) { - $count = 1; - foreach ($videoFeed as $videoEntry) { - echo "Entry # " . $count . "\n"; - printVideoEntry($videoEntry); - echo "\n"; - $count++; - } + $count = 1; + foreach ($videoFeed as $videoEntry) { + echo "Entry # " . $count . "\n"; + printVideoEntry($videoEntry); + echo "\n"; + $count++; + } } function printVideoEntry($videoEntry) { - // the videoEntry object contains many helper functions - // that access the underlying mediaGroup object - echo 'Video: ' . $videoEntry->getVideoTitle() . "\n <br>"; -/* echo 'Video ID: ' . $videoEntry->getVideoId() . "\n"; - echo 'Updated: ' . $videoEntry->getUpdated() . "\n"; - echo 'Description: ' . $videoEntry->getVideoDescription() . "\n"; - echo 'Category: ' . $videoEntry->getVideoCategory() . "\n"; - echo 'Tags: ' . implode(", ", $videoEntry->getVideoTags()) . "\n"; - echo 'Watch page: ' . $videoEntry->getVideoWatchPageUrl() . "\n"; - echo 'Flash Player Url: ' . $videoEntry->getFlashPlayerUrl() . "\n"; - echo 'Duration: ' . $videoEntry->getVideoDuration() . "\n"; - echo 'View count: ' . $videoEntry->getVideoViewCount() . "\n"; - echo 'Rating: ' . $videoEntry->getVideoRatingInfo() . "\n"; - echo 'Geo Location: ' . $videoEntry->getVideoGeoLocation() . "\n"; - echo 'Recorded on: ' . $videoEntry->getVideoRecorded() . "\n"; - */ - - // see the paragraph above this function for more information on the - // 'mediaGroup' object. in the following code, we use the mediaGroup - // object directly to retrieve its 'Mobile RSTP link' child -/* foreach ($videoEntry->mediaGroup->content as $content) { - if ($content->type === "video/3gpp") { - echo 'Mobile RTSP link: ' . $content->url . "\n"; - } - } - - echo "Thumbnails:\n"; - $videoThumbnails = $videoEntry->getVideoThumbnails(); - - foreach($videoThumbnails as $videoThumbnail) { - echo $videoThumbnail['time'] . ' - ' . $videoThumbnail['url']; - echo ' height=' . $videoThumbnail['height']; - echo ' width=' . $videoThumbnail['width'] . "\n"; - } -*/ + // the videoEntry object contains many helper functions + // that access the underlying mediaGroup object + echo 'Video: ' . $videoEntry->getVideoTitle() . "\n <br>"; + /* echo 'Video ID: ' . $videoEntry->getVideoId() . "\n"; + echo 'Updated: ' . $videoEntry->getUpdated() . "\n"; + echo 'Description: ' . $videoEntry->getVideoDescription() . "\n"; + echo 'Category: ' . $videoEntry->getVideoCategory() . "\n"; + echo 'Tags: ' . implode(", ", $videoEntry->getVideoTags()) . "\n"; + echo 'Watch page: ' . $videoEntry->getVideoWatchPageUrl() . "\n"; + echo 'Flash Player Url: ' . $videoEntry->getFlashPlayerUrl() . "\n"; + echo 'Duration: ' . $videoEntry->getVideoDuration() . "\n"; + echo 'View count: ' . $videoEntry->getVideoViewCount() . "\n"; + echo 'Rating: ' . $videoEntry->getVideoRatingInfo() . "\n"; + echo 'Geo Location: ' . $videoEntry->getVideoGeoLocation() . "\n"; + echo 'Recorded on: ' . $videoEntry->getVideoRecorded() . "\n"; + */ + + // see the paragraph above this function for more information on the + // 'mediaGroup' object. in the following code, we use the mediaGroup + // object directly to retrieve its 'Mobile RSTP link' child + /* foreach ($videoEntry->mediaGroup->content as $content) { + if ($content->type === "video/3gpp") { + echo 'Mobile RTSP link: ' . $content->url . "\n"; + } + } + + echo "Thumbnails:\n"; + $videoThumbnails = $videoEntry->getVideoThumbnails(); + + foreach($videoThumbnails as $videoThumbnail) { + echo $videoThumbnail['time'] . ' - ' . $videoThumbnail['url']; + echo ' height=' . $videoThumbnail['height']; + echo ' width=' . $videoThumbnail['width'] . "\n"; + } + */ } -function get_video(){ - $youtube_array = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", - "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", - "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "_", "-", "0", "1", "2", "3", "4", - "5", "6", "7", "8", "9" ); - $length = count($youtube_array); +$searchstring = searchterm(); - $string = ""; +//$location = Zend_Gdata_YouTube::VIDEO_URI; +$location = $yt->newVideoQuery(); +$location->setOrderBy('viewCount'); +$location->setSafeSearch('none'); +$location->setVideoQuery($searchstring); - for ($i=0;$i<11;$i++){ - $index = mt_rand(0,$length-1); - $string = "$string".$youtube_array[$index]; - } - return $string; -} - -$location = Zend_Gdata_YouTube::VIDEO_URI; getAndPrintVideoFeed($location, $yt); -$searchstring = get_video(); + echo "<br>Searchstring: " . $searchstring; diff --git a/www/youtube_functions.php b/www/youtube_functions.php new file mode 100644 index 0000000..15153ec --- /dev/null +++ b/www/youtube_functions.php @@ -0,0 +1,35 @@ +<? + +function get_video(){ + + $youtube_array = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", + "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", + "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "_", "-", "0", "1", "2", "3", "4", + "5", "6", "7", "8", "9" ); + + $length = count($youtube_array); + + $string = ""; + + for ($i=0;$i<4;$i++){ + $index = mt_rand(0,$length-1); + $string = "$string".$youtube_array[$index]; + } + return $string; +} + +function searchterm(){ + $db = new SQLite3("../database/dict.db"); + + $table_array = array("english", "german"); + $table_count = count("$table_array"); + + $rows = $db->query("SELECT count(*) as count FROM german;"); + $row = $rows->fetchArray(); + $numRows = $row["count"]; + + + $search_word = mt_rand(1,$numRows); + + return $search_word; +} |
