/**
  * media 객체로 반환
  *
  * @param File  $file    file instance
  * @param array $addInfo additional information
  * @return Image
  * @throws NotAvailableException
  */
 public function make(File $file, array $addInfo = [])
 {
     if ($this->isAvailable($file->getMime()) !== true) {
         throw new NotAvailableException();
     }
     if (!($meta = $this->repo->find($file->getId()))) {
         $meta = $this->extractInformation($file);
         foreach ($addInfo as $key => $value) {
             $meta->{$key} = $value;
         }
         $meta = $this->repo->insert($meta);
     }
     return $this->createModel($file, $meta);
 }
 /**
  * Extract file meta data
  *
  * @param File $file file instance
  * @return Meta
  */
 protected function extractInformation(File $file)
 {
     $meta = new Meta();
     $meta->id = $file->getId();
     $meta->originId = $file->getOriginId(false);
     $tmpPathname = $this->temp->getTempPathname();
     $this->temp->createFile($tmpPathname, $this->storage->read($file));
     $info = $this->reader->analyze($tmpPathname);
     $this->temp->remove($tmpPathname);
     if (isset($info['audio']['streams'])) {
         unset($info['audio']['streams']);
     }
     $meta->audio = $info['audio'];
     $meta->video = $info['video'];
     $meta->playtime = $info['playtime_seconds'];
     $meta->bitrate = $info['bitrate'];
     return $meta;
 }
Example #3
0
 /**
  * set files
  *
  * @param File $file file entity
  * @return void
  */
 public function setFile(File $file)
 {
     $this->files[$file->getId()] = $file;
 }