// process import list $app->post('/concerts_testing/import_list', function ($request, $response) { if (isset($_POST['submit'])) { $queryList = $_POST['list']; $queryList = preg_replace('[\\r\\n?|\\n]', ',', trim($queryList)); $queryList = explode(",", $queryList); $keywordList = $_POST['keywords']; $keywordList = preg_replace('[\\r\\n?|\\n]', ',', trim($keywordList)); $keywordList = explode(",", $keywordList); $numResults = intval($_POST['numResults']); $tags = []; $youtube = new YouTube(); $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); foreach ($queryList as $query) { foreach ($keywordList as $keyword) { $videoList = $youtube->videoSearch($query, $keyword, $numResults); $videoList = $youtube->getVideoDetails($videoList); $stmt = $this->db->prepare("INSERT INTO `testing` (`query`, `keyword`, `video_id`, `title`, `description`, `tags`, `cat_id`, `publish_date`, `channel`, `channel_id`, `views`, `likes`, `dislikes`, `favorites`, `comments`, `iframe`) VALUES (:query, :keyword, :video_id, :title, :description, :tags, :cat_id, :publish_date, :channel, :channel_id, :views, :likes, :dislikes, :favorites, :comments, :iframe)"); $rowCount = 0; foreach ($videoList as $video) { try { if (!empty($video['tags'])) { $tags = implode(", ", $video['tags']); } $stmt->execute(['query' => $video['query'], 'keyword' => $video['keyword'], 'video_id' => $video['videoId'], 'title' => $video['title'], 'description' => $video['description'], 'tags' => $tags, 'cat_id' => $video['catId'], 'publish_date' => $video['publishDate'], 'channel' => $video['channel'], 'channel_id' => $video['channelId'], 'views' => $video['views'], 'likes' => $video['likes'], 'dislikes' => $video['dislikes'], 'favorites' => $video['favorites'], 'comments' => $video['comments'], 'iframe' => $video['iframe']]); } catch (PDOException $e) { $response->write($e->getMessage()); } $rowCount += $stmt->rowCount(); } $message = "Query: " . $query . " " . $keyword . " | Rows inserted: " . $rowCount . "<br>";
<?php // adding namespace breaks google api // use Models\Concerts\YouTube; require_once ROOT . '/app/models/concerts/youtube.php'; $app->get('/concerts_testing', function ($request, $response) { $query = ""; $videoList = []; if (isset($_GET['search']) && !empty($_GET['search'])) { $youtube = new YouTube(); $query = $_GET['search']; $videoList = $youtube->videoSearch($query, "live", 30); $videoList = $youtube->getVideoDetails($videoList); } return $this->view->render($response, 'concerts/search_testing.twig', ['query' => $query, 'videoList' => $videoList]); })->setName('concerts-testing');