/**
  * TODO add doc
  */
 private function generateJobs(MultimediaObject $multimediaObject, $pubChannelCod)
 {
     $jobs = array();
     foreach ($this->profiles as $targetProfile => $profile) {
         $targets = $this->getTargets($profile['target']);
         if (in_array($pubChannelCod, $targets['standard']) && $multimediaObject->isOnlyAudio() == $profile['audio']) {
             if (!$multimediaObject->isOnlyAudio() && 0 != $profile['resolution_ver']) {
                 $profileAspectRatio = $profile['resolution_hor'] / $profile['resolution_ver'];
                 $multimediaObjectAspectRatio = $multimediaObject->getTrackWithTag("master")->getAspectRatio();
                 if (1.5 > $profileAspectRatio !== 1.5 > $multimediaObjectAspectRatio) {
                     $this->logger->info(sprintf("JobGeneratorListener can't create a new job (%s) for multimedia object %s using standard target, " . "because a video profile aspect ratio(%f) is diferent to video aspect ratio (%f)", $targetProfile, $multimediaObject->getId(), $profileAspectRatio, $multimediaObjectAspectRatio));
                     continue;
                 }
             }
             $master = $multimediaObject->getTrackWithTag("master");
             $this->logger->info(sprintf("JobGeneratorListener creates new job (%s) for multimedia object %s using standard target", $targetProfile, $multimediaObject->getId()));
             $jobs[] = $this->jobService->addUniqueJob($master->getPath(), $targetProfile, 2, $multimediaObject, $master->getLanguage());
         }
         if (in_array($pubChannelCod, $targets['force'])) {
             if ($multimediaObject->isOnlyAudio() && !$profile['audio']) {
                 $this->logger->info(sprintf("JobGeneratorListener can't create a new job (%s) for multimedia object %s using forced target, because a video profile can't be created from an audio", $targetProfile, $multimediaObject->getId()));
                 continue;
             }
             $master = $multimediaObject->getTrackWithTag("master");
             $this->logger->info(sprintf("JobGeneratorListener creates new job (%s) for multimedia object %s using forced target", $targetProfile, $multimediaObject->getId()));
             $jobs[] = $this->jobService->addUniqueJob($master->getPath(), $targetProfile, 2, $multimediaObject, $master->getLanguage());
         }
     }
     return $jobs;
 }
 /**
  * @Route("/info/{id}", name="pumukit_opencast_mm_info")
  * @Template
  */
 public function infoAction(MultimediaObject $multimediaObject, Request $request)
 {
     $presenterDeliveryUrl = '';
     $presentationDeliveryUrl = '';
     $presenterDeliveryTrack = $multimediaObject->getTrackWithTag('presenter/delivery');
     $presentationDeliveryTrack = $multimediaObject->getTrackWithTag('presentation/delivery');
     if (null !== $presenterDeliveryTrack) {
         $presenterDeliveryUrl = $presenterDeliveryTrack->getUrl();
     }
     if (null !== $presentationDeliveryTrack) {
         $presentationDeliveryUrl = $presentationDeliveryTrack->getUrl();
     }
     return array('presenter_delivery_url' => $presenterDeliveryUrl, 'presentation_delivery_url' => $presentationDeliveryUrl);
 }
 private function checkMultimediaObject(MultimediaObject $multimediaObject)
 {
     if (!isset($this->profiles[$this->targetProfile])) {
         $this->logger->warning(sprintf('CMAR JobGeneratorListener profile "%s" doesn\'t exist', $this->targetProfile));
         return;
     }
     $sbs = $multimediaObject->getTrackWithTag('sbs');
     $publicTracks = $multimediaObject->getTracksWithTag('profile:' . $this->targetProfile);
     if ($sbs && !$publicTracks) {
         $this->logger->info(sprintf("CMAR JobGeneratorListener creates new job (%s) for SbS in multimedia object %s", $this->targetProfile, $multimediaObject->getId()));
         $jobs[] = $this->jobService->addUniqueJob($sbs->getPath(), $this->targetProfile, 2, $multimediaObject, $sbs->getLanguage());
     }
 }
 /**
  * Render iframe
  */
 private function renderIframe(MultimediaObject $multimediaObject, Request $request)
 {
     if ($multimediaObject->getProperty('opencast')) {
         /* $this->incNumView($multimediaObject); */
         /* $this->dispatch($multimediaObject); */
         $userAgent = $this->getRequest()->headers->get('user-agent');
         $mobileDetectorService = $this->get('mobile_detect.mobile_detector');
         $mobileDevice = $mobileDetectorService->isMobile($userAgent) || $mobileDetectorService->isTablet($userAgent);
         $isOldBrowser = $this->getIsOldBrowser($userAgent);
         $track = $multimediaObject->getTrackWithTag('sbs');
         return $this->render("PumukitMoodleBundle:Moodle:opencastiframe.html.twig", array("multimediaObject" => $multimediaObject, "track" => $track, "is_old_browser" => $isOldBrowser, "mobile_device" => $mobileDevice));
     } else {
         $track = $request->query->has('track_id') ? $multimediaObject->getTrackById($request->query->get('track_id')) : $multimediaObject->getFilteredTrackWithTags(array('display'));
     }
     if (!$track) {
         throw $this->createNotFoundException();
     }
     //$this->incNumView($multimediaObject, $track);
     //$this->dispatch($multimediaObject, $track);
     return $this->render("PumukitMoodleBundle:Moodle:iframe.html.twig", array('autostart' => $request->query->get('autostart', 'false'), 'intro' => false, 'multimediaObject' => $multimediaObject, 'track' => $track));
 }
 public function testGetTracksWithTag()
 {
     $mm = new MultimediaObject();
     $t1 = new Track();
     $t1->setTags(array('master'));
     $t2 = new Track();
     $t2->setTags(array('mosca', 'master', 'old'));
     $t3 = new Track();
     $t3->setTags(array('master', 'mosca'));
     $t4 = new Track();
     $t4->setTags(array('flv', 'itunes', 'hide'));
     $t5 = new Track();
     $t5->setTags(array('flv', 'webtv'));
     $mm->addTrack($t3);
     $mm->addTrack($t2);
     $mm->addTrack($t1);
     $mm->addTrack($t4);
     $mm->addTrack($t5);
     $this->assertEquals(array($t3, $t2, $t1), $mm->getTracksWithTag('master'));
     $this->assertEquals($t3, $mm->getTrackWithTag('master'));
     $this->assertEquals(null, $mm->getTrackWithTag('del_universo'));
     $this->assertEquals($t3, $mm->getTrackWithAnyTag(array('master', 'pr')));
     $this->assertEquals(array($t2), $mm->getTracksWithAllTags(array('master', 'mosca', 'old')));
     $this->assertTrue(in_array($mm->getTrackWithAllTags(array('mosca', 'master')), array($t3, $t2)));
     $this->assertEquals(null, $mm->getTrackWithAllTags(array('mosca', 'master', 'del_universo')));
     $this->assertEquals(4, count($mm->getTracksWithAnyTag(array('master', 'webtv'))));
     $this->assertEquals(1, count($mm->getTrackWithAnyTag(array('master'))));
     $this->assertEquals(null, $mm->getTrackWithAnyTag(array('del_universo')));
     $this->assertEquals(5, count($mm->getFilteredTracksWithTags()));
     $this->assertEquals(3, count($mm->getFilteredTracksWithTags(array('master'))));
     $this->assertEquals(1, count($mm->getFilteredTracksWithTags(array('master'), array('mosca', 'old'))));
     $this->assertEquals(0, count($mm->getFilteredTracksWithTags(array(), array('mosca', 'old'), array('master'))));
     $this->assertEquals(3, count($mm->getFilteredTracksWithTags(array(), array(), array('flv'))));
     $this->assertEquals(0, count($mm->getFilteredTracksWithTags(array(), array(), array('flv', 'master'))));
     $this->assertEquals(5, count($mm->getFilteredTracksWithTags(array(), array(), array(), array('flv', 'master'))));
     $this->assertEquals(1, count($mm->getFilteredTracksWithTags(array('mosca', 'old'), array(), array(), array('old'))));
     $this->assertEquals(1, count($mm->getFilteredTrackWithTags()));
     $this->assertEquals(1, count($mm->getFilteredTrackWithTags(array('master'))));
     $this->assertEquals(1, count($mm->getFilteredTrackWithTags(array('master'), array('mosca', 'old'))));
     $this->assertEquals(0, count($mm->getFilteredTrackWithTags(array(), array('mosca', 'old'), array('master'))));
     $this->assertEquals(1, count($mm->getFilteredTrackWithTags(array(), array(), array('flv'))));
     $this->assertEquals(0, count($mm->getFilteredTrackWithTags(array(), array(), array('flv', 'master'))));
     $this->assertEquals(1, count($mm->getFilteredTrackWithTags(array(), array(), array(), array('flv', 'master'))));
     $this->assertEquals(1, count($mm->getFilteredTrackWithTags(array('mosca', 'old'), array(), array(), array('old'))));
 }
 public function syncTrack(MultimediaObject $mmobj, $parsedTerena)
 {
     $url = $parsedTerena['track_url'];
     $urlParsed = parse_url($url);
     //TODO if track_url add a error.
     $urlExtension = isset($urlParsed['path']) ? pathinfo($urlParsed['path'], PATHINFO_EXTENSION) : null;
     $track = $mmobj->getTrackWithTag('geant_track');
     if (!isset($track)) {
         $track = new Track();
         $mmobj->addTrack($track);
     }
     $track->addTag('geant_track');
     $track->setLanguage($parsedTerena['language']);
     $track->setDuration($parsedTerena['duration']);
     $track->setVcodec($parsedTerena['track_format']);
     $track->setPath($url);
     $track->setUrl($url);
     $format = explode('/', $parsedTerena['track_format']);
     $formatType = isset($format[0]) ? $format[0] : null;
     $formatExtension = isset($format[1]) ? $format[1] : null;
     if ($formatType == 'video' && in_array($formatExtension, $this->VIDEO_EXTENSIONS) || in_array($urlExtension, $this->VIDEO_EXTENSIONS)) {
         $track->addTag('display');
         $track->setOnlyAudio(false);
         $mmobj->setProperty('redirect', false);
         $mmobj->setProperty('iframeable', false);
     } elseif ($formatType == 'audio' && in_array($formatExtension, $this->AUDIO_EXTENSIONS) || in_array($urlExtension, $this->AUDIO_EXTENSIONS)) {
         $track->addTag('display');
         $track->setOnlyAudio(true);
         $mmobj->setProperty('redirect', false);
         $mmobj->setProperty('iframeable', false);
     } else {
         //We try to create an embed Url. If we can't, it returns false and we'll redirect instead. (When other repositories provides more embedded urls we will change this)
         $embedUrl = $this->feedProcesser->getEmbedUrl($url);
         if ($embedUrl) {
             $mmobj->setProperty('opencast', true);
             //Workaround to prevent editing the Schema Filter for now.
             $mmobj->setProperty('iframeable', true);
             $mmobj->setProperty('redirect', false);
             $mmobj->setProperty('iframe_url', $embedUrl);
         } else {
             $mmobj->setProperty('opencast', true);
             //Workaround to prevent editing the Schema Filter for now.
             $mmobj->setProperty('redirect', true);
             $mmobj->setProperty('iframeable', false);
             $mmobj->setProperty('redirect_url', $url);
         }
     }
     $this->dm->persist($track);
     $track->addTag('geant_track');
 }