Esempio n. 1
0
 /**
  * @Route ("/apiway", name="apiway")
  */
 public function apiAction()
 {
     $em = $this->getDoctrine()->getManager();
     //clear table first
     $sql = "DELETE FROM video";
     $stmt = $this->getDoctrine()->getManager()->getConnection()->prepare($sql);
     $stmt->execute();
     #get artists list from yaml file as Symfony good form
     $artists = Yaml::parse(file_get_contents("artists.yml"));
     #used of Google Client is unnecessary because not used OAuth2, just only query with key
     $developer_key = $this->container->getParameter("google_api_key");
     $client = new Google_Client();
     $client->setDeveloperKey($developer_key);
     $youtube = new Google_Service_YouTube($client);
     foreach ($artists as $artist) {
         $search_response = $youtube->search->listSearch("id", ['q' => $artist, 'maxResults' => 5, 'type' => 'video']);
         #merge video IDs for getting statistic data by artists video
         $videoResults = [];
         foreach ($search_response['items'] as $searchResult) {
             array_push($videoResults, $searchResult['id']['videoId']);
         }
         $videoIds = join(',', $videoResults);
         $videosResponse = $youtube->videos->listVideos('snippet, statistics', array('id' => $videoIds));
         foreach ($videosResponse['items'] as $videoResult) {
             $video = new Video();
             $video->setAuthor($artist);
             $video->setLink($videoResult['id']);
             $video->setName($videoResult['snippet']['title']);
             $video->setViews($videoResult['statistics']['viewCount']);
             $em->persist($video);
         }
         $em->flush();
     }
     return $this->redirect($this->generateUrl("homepage"));
 }
Esempio n. 2
0
 /**
  * @Route("/json/video/add", name="video-add-ajax")
  * @return string|\Symfony\Component\HttpFoundation\Response
  * @Method("POST")
  */
 public function addNewAjaxAction(Request $request)
 {
     $video = new Video();
     $video->setHeading($request->get('title'));
     $video->setLink($request->get('link'));
     $video->setDescription($request->get('desc'));
     $video->setUserId($this->getUser());
     $catId = (int) $request->get('category');
     $video->setTags($request->get('tags'));
     if ($request->request->get('article')['privacy'] == 'internal') {
         $video->setPrivate(true);
     } else {
         $video->setPrivate(false);
     }
     $this->get('video_manager')->saveVideo($video, $catId);
     return new Response('Created video ' . $video->getHeading());
 }