/** * @param Video $video * @param $categoryId */ public function saveVideo(Video $video, $categoryId) { $category = $this->categoryManager->getCategoryById($categoryId); $video->setCategoryId($category); $category->addVideo($video); $this->repository->saveVideo($video); }
public function uploadUserThumbnail(Video $video, $thumbnailUrl) { if ($video->getThumbnail() == null) { $thumbnail = new Thumbnail(); $media = new Media(); $media->setFileName(basename($thumbnailUrl)); $media->setOriginal(basename($thumbnailUrl)); $media->setPath($thumbnailUrl); $media->setType(Media::EXTERNAL_MEDIA); $media->setWebPath($thumbnailUrl); $media->setSize(sizeof($thumbnailUrl)); $media->setThumbnail($thumbnail); $video->setThumbnail($thumbnail); $thumbnail->setVideo($video); $thumbnail->setMedia($media); $this->em->persist($thumbnail); $this->em->persist($video); } else { $media = $video->getThumbnail()->getMedia(); $media->setWebPath($thumbnailUrl); } $this->em->persist($media); $this->em->flush(); return true; }
/** * @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()); }
/** * @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")); }
/** * @Security("has_role('ROLE_USER')") */ public function addAction(Request $request) { if (($url = $request->request->get("url", null)) === null) { return new JsonResponse(array("type" => "alert", "message" => "Le lien de la vidéo n'a pas été fourni."), 200); } if (preg_match('#^https?://\\w{0,3}.?youtube+\\.\\w{2,3}/watch\\?v=([\\w-]{11})#', $url, $matches) == false) { return new JsonResponse(array("type" => "alert", "message" => "Le lien de la video Youtube n'est pas valide."), 200); } $content = file_get_contents("http://youtube.com/get_video_info?video_id=" . $matches[1]); parse_str($content, $videoYoutubeData); if ($videoYoutubeData["status"] == "fail") { return new JsonResponse(array("type" => "alert", "message" => "La vidéo Youtube n'existe pas. Soit parce qu'elle ... n'existe effectivement pas, soit parce que l'exportation n'est pas autorisée par Youtube."), 200); } if (!$this->get('security.context')->isGranted("ROLE_SUPER_ADMIN")) { if ($videoYoutubeData["length_seconds"] > 330) { return new JsonResponse(array("type" => "alert", "message" => "La vidéo Youtube dépasse les 3m 30s"), 200); } /** * @var $videos Video[] * @var $videoRepository EntityRepository */ $videoRepository = $this->getDoctrine()->getManager()->getRepository("AppBundle:Video"); $videos = $videoRepository->createQueryBuilder("v")->andWhere("v.user = :user")->setParameter(":user", $this->getUser())->addOrderBy("v.creationDate", "ASC")->getQuery()->getResult(); if (count($videos) > 0) { return new JsonResponse(array("type" => "alert", "message" => "Vous avez déjà une vidéo en file d'attente. Veuillez attendre sa lecture avant d'en soumettre une autre."), 200); } foreach ($videos as $video) { $youtube = $video->getYoutube(); if ($youtube["video_id"] == $matches[1]) { return new JsonResponse(array("type" => "alert", "message" => "Cette vidéo est déjà présente dans la liste d'attente. Veuillez attendre sa lecture avant de la soumettre à nouveau."), 200); } } } $video = new Video(); $video->setUser($this->getUser()); $video->setYoutube($videoYoutubeData); $this->getDoctrine()->getManager()->persist($video); $this->getDoctrine()->getManager()->flush(); return new JsonResponse(array("type" => "success", "message" => "Votre vidéo Youtube a été ajoutée"), 201); }
public function load(ObjectManager $manager) { for ($i = 0; $i < 2; $i++) { $new = new Video(); $new->setTitle('Видео 1'); $new->setBody('Мерило нравственности и блюститель духовных скреп российских граждан, Елена Борисовна Мизулина возвращается на законодательное поле боя с новой инициативой — оградить российских детей от «плохих» онлайн видеоигр'); $new->setCreated(new \DateTime('20.03.1016')); $new->setEnabled(true); $new->setVideo(array('path' => 'd')); $manager->persist($new); $manager->flush(); } }
public function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); $tubeManipulator = $container->get('velikan_tube_crawler.tube_manipulator'); $tubes = []; if ($tubeId = $input->hasArgument('tube-id')) { $tubes[] = $tubeManipulator->find($tubeId); } else { $tubes = $tubeManipulator->findAll(); } $uriFetchAdapter = $container->get('velikan_tube_crawler.uri_fetch_adapter'); $parsedVideoCounter = 0; $videoParser = $container->get('velikan_tube_crawler.video_parser'); /** @var Tube $tube */ $tube = null; $fetchAdapterFunction = function ($responseBody, $pageIndex) use(&$tube, $tubeManipulator, $videoParser, $output, &$parsedVideoCounter) { $videos = $videoParser->parse($responseBody, $tube->getVideoBlockSelector(), $tube->getVideoUriSelector(), $tube->getVideoImageSelector(), $tube->getVideoTitleSelector()); foreach ($videos as $parsedVideo) { $video = new Video(); $video->setTube($tube); $video->setVideoUri($parsedVideo['uri']); $video->setImageUri($parsedVideo['image']); $video->setTitle($parsedVideo['title']); $tubeManipulator->testAndCreateVideo($video); } $parsedVideoCounter += count($videos); $output->writeln(sprintf('Parsed %d videos for page %d (%d overall)', count($videos), $pageIndex, $parsedVideoCounter)); }; /** @var Tube $tube */ foreach ($tubes as $tube) { $output->writeln('Fetching videos for <info>' . $tube->getName() . '</info>'); $routeCollection = new RouteCollection(); $routeCollection->add('uri', new Route($tube->getUrn())); $requestContext = new RequestContext(Tube::$schemeList[$tube->getScheme()] . '://' . $tube->getHost()); $generator = new UrlGenerator($routeCollection, $requestContext); $startingPageNumber = $tube->getStartingPageNumber(); for ($i = $startingPageNumber; $i < $input->getOption('pages') + $startingPageNumber; $i++) { $uri = urldecode($generator->generate('uri', ['page' => $i])); $uriFetchAdapter->addUri($uri); } $uriFetchAdapter->fetch($fetchAdapterFunction, $tube->getCanFetchMultithreaded(), $tube->getThreadCount()); } }
/** * Delete video * @param Request $request * @param Video $video * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function videoDeleteAction(Request $request, Video $video) { $em = $this->getDoctrine()->getManager(); $accommodation = $video->getAccommodation(); $session = $request->getSession(); try { $em->remove($video); $em->flush(); $session->getFlashBag()->add('msgSuccess', $this->get('translator')->trans('delete_success')); } catch (\Exception $e) { $session->getFlashBag()->add('msgError', $e->getMessage()); } if ($request->get('_route') == 'app_video_step6_delete') { return $this->redirect($this->generateUrl('app_profile_step_6', array('id' => $accommodation->getId()))); } else { return $this->redirect($this->generateUrl('app_accommodation_edit', array('id' => $accommodation->getId()))); } }
/** * Add videos * * @param \AppBundle\Entity\Video $videos * @return User */ public function addVideo(\AppBundle\Entity\Video $videos) { $this->videos[] = $videos; $videos->setUser($this); return $this; }
/** * @param Video $videos * @return $this */ public function addVideo(Video $videos) { $this->videos[] = $videos; $videos->setCategoryId($this); return $this; }
/** * @param Video $video * @return $this */ public function addVideo(Video $video) { $video->setUserId($this); $this->articles[] = $video; return $this; }
public function validateVideoUrl($value, ExecutionContextInterface $context) { $this->currentVideo = null; // vimeo preg_match(Video::RE_VIMEO, $value, $m); if (sizeof($m) !== 0) { $v = new Video(); $v->setType(Video::TYPE_VIMEO); $v->setOriginalUrl($value); $v->setVideoId($m[1]); $v->setEmbedUrl("http://player.vimeo.com/video/{$m[1]}?api=1&player_id=player"); // try obtain thumbnail url try { $json = file_get_contents("http://vimeo.com/api/v2/video/{$m[1]}.json"); $desc = json_decode($json, true); $v->setThumbnailUrl($desc[0]['thumbnail_small']); } catch (Exception $e) { $msg = sprintf("FAIL fetching thumbnail for '%s'", $value); $this->logger->error($msg); $this->logger->error($e->getTraceAsString()); } $this->currentVideo = $v; return; } // youtube preg_match(Video::RE_YOUTUBE, $value, $m); if (sizeof($m) > 1) { $v = new Video(); $v->setType(Video::TYPE_YOUTUBE); $v->setOriginalUrl($value); $v->setVideoId($m[1]); $v->setEmbedUrl("https://www.youtube.com/embed/{$m[1]}"); $v->setThumbnailUrl("https://i.ytimg.com/vi/{$m[1]}/default.jpg"); $this->currentVideo = $v; return; } $context->buildViolation('This is not a valid Youtube or Vimeo url.')->atPath('videoUrl')->addViolation(); }
/** * @Template() */ public function uploadAction() { $video = new Video(); $video->setUser($this->getUser()); $form = $this->createFormBuilder($video)->add('title', 'text')->add('description', 'text')->add('status', 'choice', array('choices' => array('private' => 'Private', 'link' => 'Link', 'public' => 'Public'), 'required' => true))->add('file', 'file')->getForm(); $error = 'Something wrong has been detected !'; if ($this->getRequest()->isMethod('POST')) { $form->handleRequest($this->getRequest()); if ($form->isValid()) { $file = $video->getFile(); if ($file->getClientOriginalExtension() == 'mp4' && $file->getClientSize() <= $file->getMaxFilesize()) { $em = $this->getDoctrine()->getManager(); $em->persist($video); $em->flush(); $video->setHash(md5($video->getId())); $video->setShareUrl("/video/link/" . $video->getHash()); $isUploaded = $video->upload(); if (!$isUploaded) { $em->remove($video); $em->flush(); return array('form' => $form->createView(), 'error' => $error); } else { chdir($video->getUploadRootDir()); exec("ffmpeg -i " . $video->getPath() . " -ss 00:00:05.000 -f image2 -vframes 1 " . $video->getId() . ".png"); $em->persist($video); $em->flush(); } return $this->redirect($this->generateUrl('user_video')); } else { return array('form' => $form->createView(), 'error' => $error); } } else { return array('form' => $form->createView(), 'error' => $error); } } return array('form' => $form->createView()); }