<option value="22">People & Blogs</option> <!-- <option value="40">SciFi & Fantasy</option> --> <option value="28">Science & Technology</option> <!-- <option value="18">Short Movies</option> <option value="42">Shorts</option> --> <option value="43">Shows</option> <option value="17">Sports</option> <option value="44">Trailers</option> <option value="19">Travel & Events</option> <!-- <option value="41">Thriller</option> <option value="21">Videoblogging</option> --> </select> <label for='txtFromDate'>Publish Date:</label> <input type='text' name='txtFromDate' id='txtFromDate' class="form-control" value='<?php echo htmlspecialchars(getPublishAfterDate("Y-m-d"), ENT_QUOTES); ?> ' /> <label for='txtToDate'>To:</label> <input type='text' name='txtToDate' id='txtToDate' class="form-control" value='<?php echo htmlspecialchars(getPublishBeforeDate("Y-m-d"), ENT_QUOTES); ?> ' /> <button type='submit' class="btn btn-primary">Search</button> </div> </form> </div> <!--header-->
function loadNextVideo($category = null) { $nextPage = @$_GET['nextPage']; $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : ''; if (is_array($category)) { foreach ($category as $cat) { loadNextVideo($cat); return; } } $response = file_get_contents("https://www.googleapis.com/youtube/v3/search?part=snippet&videoCategoryId={$category}&safeSearch=none&publishedAfter=" . urlencode(getPublishAfterDate()) . "&publishedBefore=" . urlencode(getPublishBeforeDate()) . "&maxResults=48&order=viewCount&type=video&key=AIzaSyBRxS0JS_JD_FTarF784exuKNuCgCnJIy0&pageToken={$nextPage}"); $searchResponse = json_decode($response, true); foreach ($searchResponse['items'] as $searchResult) { $a = $searchResult['id']['videoId']; $b = preg_replace('/[^a-zA-Z0-9]/', '_', $searchResult['snippet']['title']); ?> <div id="<?php echo $a; ?> " draggable="true" ondragstart="drag(event)" class="videoItemContainer" onClick="playThis('<?php echo $a; ?> ', '<?php echo $b; ?> ')"> <div class="videoItemImage"> <img src="<?php echo $searchResult['snippet']['thumbnails']['default']['url']; ?> " alt="Youtube Video"> </div> <div class="videoItemCaption"> <?php echo $searchResult['snippet']['title']; ?> </div> </div> <?php } $nextPage = $searchResponse['nextPageToken']; ?> <nav> <ul class="pager"> <!-- <li class="previous"><a href="#"><span aria-hidden="true">←</span> Older</a></li> --> <li onClick="nextPage('<?php echo @$keyword; ?> ', '<?php echo $nextPage; ?> ')" class="next"><a href="#">Next Page<span aria-hidden="true">→</span></a></li> </ul> </nav> <?php }
function loadNextVideo($category = null) { $nextPage = @$_GET['nextPage']; $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : ''; if (is_array($category)) { foreach ($category as $cat) { loadNextVideo($cat); return; } } $response = file_get_contents("https://www.googleapis.com/youtube/v3/search?part=snippet&videoCategoryId={$category}&safeSearch=none&publishedAfter=" . urlencode(getPublishAfterDate()) . "&publishedBefore=" . urlencode(getPublishBeforeDate()) . "&maxResults=50&order=viewCount&type=video&key=xyz&pageToken={$nextPage}"); $searchResponse = json_decode($response, true); /* ** Get all ID's, fetch video statistics from youtube API in single connection, assign view and like count to $youtube_data array */ $youtube_data = array(); $video_ids = array(); foreach ($searchResponse['items'] as $searchResult) { $video_ids[] = $searchResult['id']['videoId']; } //Make request to youtube api $youtube_response = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/videos?part=statistics&key=AIzaSyBRxS0JS_JD_FTarF784exuKNuCgCnJIy0&id=' . implode(",", $video_ids))); //Assign needed data to youtube_data array if (isset($youtube_response->items)) { foreach ($youtube_response->items as $item) { $video_id = $item->id; $youtube_data[$item->id] = array(); $youtube_data[$item->id]['viewCount'] = isset($item->statistics->viewCount) ? $item->statistics->viewCount : 0; $youtube_data[$item->id]['likeCount'] = isset($item->statistics->likeCount) ? $item->statistics->likeCount : 0; } } //end if foreach ($searchResponse['items'] as $searchResult) { $video_id = $a = $searchResult['id']['videoId']; $b = preg_replace('/[^a-zA-Z0-9]/', '_', $searchResult['snippet']['title']); ?> <div class="ytTextList"> <li> <span class="textTitle" onClick="playThis('<?php echo $a; ?> ', '<?php echo $b; ?> ')"><?php echo $searchResult['snippet']['title']; ?> </span> <span class='youtube_views'>▪ Views: <?php echo number_format((int) $youtube_data[$video_id]['viewCount']); ?> </span> <span class='youtube_likes'>▪ Likes: <?php echo number_format((int) $youtube_data[$video_id]['likeCount']); ?> </span> <a href="https://www.youtube.com/watch?v=<?php echo $searchResult['id']['videoId']; ?> "target="_blank">View on Youtube</a> </li> </div> <?php } $nextPage = $searchResponse['nextPageToken']; ?> <nav> <ul class="pager"> <li onClick="nextPageText('<?php echo @$keyword; ?> ', '<?php echo $nextPage; ?> ') ; add2()" class="next"><a href="#">Next Page<span aria-hidden="true">→</span></a></li> </ul> </nav> <?php }