public function execute(InputInterface $input, OutputInterface $output) { $logger = $this->getContainer()->get('logger'); $logger->info('--------START CRON SCRIPT' . date('Y-m-d H:i:s') . '------'); $em = $this->getContainer()->get('doctrine.orm.entity_manager'); $context = $this->getContainer()->get('router')->getContext(); $basePath = $context->getScheme() . '://' . $context->getHost(); $videos = $em->getRepository('AppBundle:Video')->findBy(array('withBumper' => Video::WITHOUT_BUMPER)); $coshiManager = $this->getContainer()->get('media.media_manager'); foreach ($em->getRepository('AppBundle:Category')->findAll() as $category) { if ($category->getBumper()) { $logger->info('--------CONCATE VIDEO FROM CATEGORY' . date('Y-m-d H:i:s') . '------'); $this->getContainer()->get('app.concat_videos')->concatenateFromConcole($category->getBumper(), $category); } } $videos = $em->getRepository('AppBundle:Video')->findBy(array('withBumper' => Video::WITH_BUMPER, 'status' => Video::STATUS_PROCESSING, 'uploadedOnAmazon' => false)); $count = 0; foreach ($videos as $video) { $fixedfile = basename($video->getFileName()); $fixedfile = preg_replace('/\\s+/', '_', $fixedfile); $count += 1; if ($video) { $logger->info('--------START VIDEO UPLOADING TO ZENCODER' . date('Y-m-d H:i:s') . '------'); $zencodeClient = new ZenCoderClient($basePath . $video->getMedia()->getWebPath(), $video->getFileName(), $this->getContainer()->get('router')->generate('callback_from_zencoder', array('id' => $video->getId()), true)); $zencoderJobs = $zencodeClient->getIntervalFor100Thumbnails(new IntervalMaker($video))->sendRequest($this->getContainer()->getParameter('zencoder_secret_key'), $zencodeClient->getInerval(), $this->getContainer()->getParameter('credentials'), $this->getContainer()->getParameter('custometUrl')); $video->setZencoderJobId($zencoderJobs->outputs[0]->id)->setUploadedOnAmazon(true)->setThumbnailsInJSONfromZencoder(sprintf("https://app.zencoder.com/api/v2/outputs/%s.xml?api_key=%s", $zencoderJobs->outputs[0]->id, $this->getContainer()->getParameter('zencoder_secret_key')))->setVideoForSmallMobile(sprintf('%s/%s/mobile-480x360.mp4', $this->getContainer()->getParameter('zencoder_address'), $fixedfile))->setVideoForLargeMobile(sprintf('%s/%s/mobile-1280x720.mp4', $this->getContainer()->getParameter('zencoder_address'), $fixedfile))->setStandartVideoFromZencoder(sprintf('%s/%s/web.mp4', $this->getContainer()->getParameter('zencoder_address'), $fixedfile))->setStatus(Video::STATUS_UPLOAD_TO_AMAZON); $em->persist($video); $this->getContainer()->get('logger')->info(sprintf('One video with name %s was uploaded to zencoder', $video->getFileName())); } } $em->flush(); $count == 1 ? $output->writeln("1 video was uploaded to amazon cloud") : $output->writeln($count . " videos were uploaded to amazon cloud"); }
public function uploadToZenCoderAPIAction(Request $request, $id) { $video = $this->getRepository("AppBundle:Video")->find($id); $fixedfile = basename($video->getFileName()); $fixedfile = preg_replace('/\\s+/', '_', $fixedfile); if ($video->getUploadedOnAmazon()) { $this->addFlash('notice', 'This video was allready loaded to Zencoder'); return $this->redirect($this->generateurl("user_set_video_data", array('id' => $id))); } elseif (!$video->getFileName()) { $this->addFlash('notice', 'You mast set video Name property, before load it to Zencoder'); return $this->redirect($this->generateurl("user_set_video_data", array('id' => $id))); } $zencodeClient = new ZenCoderClient($request->getSchemeAndHttpHost() . $video->getMedia()->getWebPath(), $video->getFileName(), $this->generateUrl('callback_from_zencoder', array('id' => $video->getId()), true)); $zencoderJobs = $zencodeClient->getIntervalFor100Thumbnails(new IntervalMaker($video), $video->getCategory()->getBumper()->getMedia()->getWebPath())->sendRequest($this->container->getParameter('zencoder_secret_key'), $zencodeClient->getInerval(), $this->getContainer()->getParameter('credentials'), $this->getContainer()->getParameter('custometUrl')); $video->setZencoderJobId($zencoderJobs->outputs[0]->id)->setUploadedOnAmazon(true)->setThumbnailsInJSONfromZencoder(sprintf("https://app.zencoder.com/api/v2/outputs/%s.xml?api_key=%s", $zencoderJobs->outputs[0]->id, $this->container->getParameter('zencoder_secret_key')))->setStatus(Video::STATUS_UPLOAD_TO_AMAZON)->setVideoForSmallMobile(sprintf('%s/%s/mobile-480x360.mp4', $this->getParameter('zencoder_address'), $fixedfile))->setVideoForLargeMobile(sprintf('%s/%s/mobile-1280x720.mp4', $this->getParameter('zencoder_address'), $fixedfile))->setStandartVideoFromZencoder(sprintf('%s/%s/web.mp4', $this->getParameter('zencoder_address'), $fixedfile)); $em = $this->getEm(); $em->persist($video); $em->flush(); return $this->render('Frontend/User/Upload/Process/zencoderResult.html.twig', array('zencoderJobs' => $zencoderJobs)); }