示例#1
0
文件: CliTest.php 项目: cargomedia/cm
 public function testImportVideoThumbnail()
 {
     $testFile1 = CM_File::create('test1.png', 'foo1', CM_Service_Manager::getInstance()->getFilesystems()->getTmp());
     $testFile2 = CM_File::create('test2.png', 'foo2', CM_Service_Manager::getInstance()->getFilesystems()->getTmp());
     $cli = new CM_MediaStreams_Cli();
     // streamchannel exists
     /** @var CM_Model_StreamChannel_Media $streamChannel */
     $streamChannel = CMTest_TH::createStreamChannel(null, null, 'foobar');
     $this->assertCount(0, $streamChannel->getThumbnails());
     $cli->importVideoThumbnail('foobar', $testFile1, 1234);
     $this->assertCount(1, $streamChannel->getThumbnails());
     /** @var CM_StreamChannel_Thumbnail $thumbnail */
     $thumbnail = $streamChannel->getThumbnails()->getItem(0);
     $this->assertSame(1234, $thumbnail->getCreateStamp());
     $this->assertSame('foo1', $thumbnail->getFile()->read());
     // archive exists
     $archive = CM_Model_StreamChannelArchive_Media::createStatic(['streamChannel' => $streamChannel]);
     $streamChannel->delete();
     $cli->importVideoThumbnail('foobar', $testFile2, 1235);
     $this->assertCount(2, $streamChannel->getThumbnails());
     /** @var CM_StreamChannel_Thumbnail $thumbnail */
     $thumbnail = $archive->getThumbnails()->getItem(1);
     $this->assertSame(1235, $thumbnail->getCreateStamp());
     $this->assertSame('foo2', $thumbnail->getFile()->read());
 }
示例#2
0
文件: Media.php 项目: cargomedia/cm
 protected function _onDeleteBefore()
 {
     parent::_onDeleteBefore();
     if (!CM_Model_StreamChannelArchive_Media::findById($this->getId())) {
         CM_Model_StreamChannelArchive_Media::createStatic(array('streamChannel' => $this));
     }
 }
示例#3
0
 public function testFindByMediaId()
 {
     $this->assertNull(CM_Model_StreamChannelArchive_Media::findByMediaId('foo'));
     /** @var CM_Model_StreamChannel_Media $streamChannel */
     $streamChannel = $streamChannel = CMTest_TH::createStreamChannel(null, null, 'foo');
     $this->assertEquals($streamChannel, CM_Model_StreamChannel_Media::findByMediaId($streamChannel->getMediaId()));
 }
示例#4
0
 /**
  * @param string      $streamName
  * @param int         $streamChannelType
  * @param int         $serverId
  * @param string|null $mediaId
  * @return CM_Model_StreamChannel_Abstract
  * @throws CM_Exception_Invalid
  */
 public function createStreamChannel($streamName, $streamChannelType, $serverId, $mediaId = null)
 {
     if (null !== $mediaId) {
         $mediaId = (string) $mediaId;
         if (null !== CM_Model_StreamChannelArchive_Media::findByMediaId($mediaId)) {
             throw new CM_Exception_Invalid('Channel archive with this mediaId already exists', null, ['mediaId' => $mediaId]);
         }
     }
     return CM_Model_StreamChannel_Abstract::createType($streamChannelType, ['key' => $streamName, 'adapterType' => $this->_adapterType, 'serverId' => (int) $serverId, 'mediaId' => $mediaId]);
 }
示例#5
0
 public function testCreateStreamChannel()
 {
     $repository = new CM_MediaStreams_StreamRepository(1);
     $mediaId = '444-bar';
     $channel = $repository->createStreamChannel('foo', CM_Model_StreamChannel_Media::getTypeStatic(), 2, $mediaId);
     $this->assertInstanceOf('CM_Model_StreamChannel_Media', $channel);
     CM_Model_StreamChannelArchive_Media::createStatic(['streamChannel' => $channel]);
     $exception = $this->catchException(function () use($repository, $mediaId) {
         $repository->createStreamChannel('bar', CM_Model_StreamChannel_Media::getTypeStatic(), 2, $mediaId);
     });
     $this->assertInstanceOf('CM_Exception_Invalid', $exception);
     /** @var CM_Exception_Invalid $exception */
     $this->assertSame('Channel archive with this mediaId already exists', $exception->getMessage());
     $this->assertSame(['mediaId' => $mediaId], $exception->getMetaInfo());
 }
示例#6
0
文件: Cli.php 项目: cargomedia/cm
 /**
  * @param string  $streamChannelMediaId
  * @param CM_File $archiveSource
  * @throws CM_Exception_Invalid
  */
 public function importArchive($streamChannelMediaId, CM_File $archiveSource)
 {
     $streamChannelMediaId = (string) $streamChannelMediaId;
     $streamChannelArchive = CM_Model_StreamChannelArchive_Media::findByMediaId($streamChannelMediaId);
     if (!$streamChannelArchive) {
         $streamChannel = CM_Model_StreamChannel_Media::findByMediaId($streamChannelMediaId);
         if ($streamChannel) {
             throw new CM_Exception_Invalid('Archive not created, please try again later', null, ['streamChannelMediaId' => $streamChannelMediaId]);
         }
         $exception = new CM_Exception_Invalid('Archive not found, stream channel not found, skipping', CM_Exception::WARN, ['streamChannelMediaId' => $streamChannelMediaId]);
         $context = new CM_Log_Context();
         $context->setException($exception);
         $this->getServiceManager()->getLogger()->warning('Archive creating error', $context);
         return;
     }
     $filename = $streamChannelArchive->getId() . '-' . $streamChannelArchive->getHash() . '-original.' . $archiveSource->getExtension();
     $archiveDestination = new CM_File_UserContent('streamChannels', $filename, $streamChannelArchive->getId());
     $archiveDestination->ensureParentDirectory();
     $archiveSource->copyToFile($archiveDestination);
     $streamChannelArchive->setFile($archiveDestination);
 }
示例#7
0
文件: TH.php 项目: cargomedia/cm
 /**
  * @param CM_Model_StreamChannel_Media|null $streamChannel
  * @param CM_Model_User|null                $user
  * @param string|null                       $filename
  * @return CM_Model_StreamChannelArchive_Media
  */
 public static function createStreamChannelVideoArchive(CM_Model_StreamChannel_Media $streamChannel = null, CM_Model_User $user = null, $filename = null)
 {
     if (is_null($streamChannel)) {
         $streamChannel = static::createStreamChannel();
         static::createStreamPublish($user, $streamChannel);
     }
     if (!$streamChannel->hasStreamPublish()) {
         static::createStreamPublish($user, $streamChannel);
     }
     if (null !== $filename) {
         $filename = (string) $filename;
     }
     return CM_Model_StreamChannelArchive_Media::createStatic(array('streamChannel' => $streamChannel, 'file' => $filename));
 }
示例#8
0
 /**
  * @param CM_Model_StreamChannelArchive_Media $archive
  */
 private function _createArchiveFiles(CM_Model_StreamChannelArchive_Media $archive)
 {
     $files = array();
     /** @var CM_StreamChannel_Thumbnail $thumbnail */
     foreach ($archive->getThumbnails() as $index => $thumbnail) {
         if ($index === 0) {
             $thumbnail->getFile()->ensureParentDirectory();
         }
         $thumbnail->getFile()->write('');
     }
     if ($archive->hasFile()) {
         $video = $archive->getFile();
         $video->ensureParentDirectory();
         $video->write('');
         $files[] = $video;
     }
 }