public function testUploadLargeFileFromResource()
 {
     // Setup
     $assetName = TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix();
     $assetOptions = Asset::OPTIONS_NONE;
     $accessPolicyName = TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix();
     $accessPolicyNameRead = TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix();
     $accessPolicyDuration = 30;
     $accessPolicyDurationRead = 300;
     $accessPolicyPermission = AccessPolicy::PERMISSIONS_WRITE;
     $accessPolicyPermissionRead = AccessPolicy::PERMISSIONS_READ;
     $locatorStartTime = new \DateTime('now -5 minutes');
     $locatorType = Locator::TYPE_SAS;
     $locatorStartTimeRead = new \DateTime('now -5 minutes');
     $locatorTypeRead = Locator::TYPE_SAS;
     $fileName = TestResources::MEDIA_SERVICES_DUMMY_FILE_NAME;
     $fileContent = $this->createLargeFile();
     $resource = fopen(VirtualFileSystem::newFile($fileContent), 'r');
     // Test
     $asset = new Asset($assetOptions);
     $asset->setName($assetName);
     $asset = $this->createAsset($asset);
     $access = new AccessPolicy($accessPolicyName);
     $access->setDurationInMinutes($accessPolicyDuration);
     $access->setPermissions($accessPolicyPermission);
     $access = $this->createAccessPolicy($access);
     $locator = new Locator($asset, $access, $locatorType);
     $locator->setStartTime($locatorStartTime);
     $locator = $this->createLocator($locator);
     $this->restProxy->uploadAssetFile($locator, $fileName, $resource);
     $this->restProxy->createFileInfos($asset);
     $assetFiles = $this->restProxy->getAssetFileList();
     $accessRead = new AccessPolicy($accessPolicyNameRead);
     $accessRead->setDurationInMinutes($accessPolicyDurationRead);
     $accessRead->setPermissions($accessPolicyPermissionRead);
     $accessRead = $this->createAccessPolicy($accessRead);
     $locatorRead = new Locator($asset, $accessRead, $locatorTypeRead);
     $locatorRead->setStartTime($locatorStartTimeRead);
     $locatorRead = $this->createLocator($locatorRead);
     // without sleep() Locator hasn't enough time to create URL, so that's why we have to use at least sleep(30)
     sleep(40);
     $method = Resources::HTTP_GET;
     $url = new Url($locatorRead->getBaseUri() . '/' . $fileName . $locatorRead->getContentAccessComponent());
     $filters = array();
     $statusCode = Resources::STATUS_OK;
     $httpClient = new HttpClient();
     $httpClient->setMethod($method);
     $httpClient->setExpectedStatusCode($statusCode);
     $downloadedFileContent = $httpClient->send($filters, $url);
     // Assert
     $this->assertEquals($assetName, $asset->getName());
     $this->assertEquals($assetOptions, $asset->getOptions());
     $this->assertNotNull($asset->getId());
     $this->assertNotNull($asset->getCreated());
     $this->assertEquals($accessPolicyName, $access->getName());
     $this->assertEquals($accessPolicyDuration, $access->getDurationInMinutes());
     $this->assertEquals($accessPolicyPermission, $access->getPermissions());
     $this->assertEquals($accessPolicyNameRead, $accessRead->getName());
     $this->assertEquals($accessPolicyDurationRead, $accessRead->getDurationInMinutes());
     $this->assertEquals($accessPolicyPermissionRead, $accessRead->getPermissions());
     $this->assertNotNull($asset->getId());
     $this->assertNotNull($asset->getCreated());
     $this->assertEquals($locatorType, $locator->getType());
     $this->assertEquals($locatorStartTime->getTimestamp(), $locator->getStartTime()->getTimestamp());
     $this->assertEquals($locatorTypeRead, $locatorRead->getType());
     $this->assertEquals($locatorStartTimeRead->getTimestamp(), $locatorRead->getStartTime()->getTimestamp());
     $this->assertEquals($asset->getId(), $locator->getAssetId());
     $this->assertEquals($access->getId(), $locator->getAccessPolicyId());
     $this->assertEquals($asset->getId(), $locatorRead->getAssetId());
     $this->assertEquals($accessRead->getId(), $locatorRead->getAccessPolicyId());
     $this->assertEquals(1, count($assetFiles));
     $this->assertEquals($asset->getId(), $assetFiles[0]->getParentAssetId());
     $this->assertEquals($fileName, $assetFiles[0]->getName());
     $this->assertEquals($fileContent, $downloadedFileContent);
 }
 /**
  * Get list of Locators.
  *
  * @return array of Models\Locator
  */
 public function getLocatorList()
 {
     $propertyList = $this->_getEntityList('Locators');
     $result = array();
     foreach ($propertyList as $properties) {
         $result[] = Locator::createFromOptions($properties);
     }
     return $result;
 }
Example #3
0
 /**
  * Create locator from array
  *
  * @param array $options Array containing values for object properties
  *
  * @return WindowsAzure\MediaServices\Models\Locator
  */
 public static function createFromOptions($options)
 {
     Validate::notNull($options['AssetId'], 'options[AssetId]');
     Validate::notNull($options['AccessPolicyId'], 'options[AccessPolicyId]');
     Validate::notNull($options['Type'], 'options[Type]');
     $locator = new Locator($options['AssetId'], $options['AccessPolicyId'], $options['Type']);
     $locator->fromArray($options);
     return $locator;
 }
 private function publishAsset($asset)
 {
     $accessPolicy = new AccessPolicy("read access policy");
     $accessPolicy->setDurationInMinutes(self::ACCESS_POLICY_READ_DURATION_M);
     $accessPolicy->setPermissions(AccessPolicy::PERMISSIONS_READ);
     $accessPolicy = $this->_mediaServiceProxy->createAccessPolicy($accessPolicy);
     $locator = new Locator($asset, $accessPolicy, Locator::TYPE_SAS);
     $locator->setStartTime(new \DateTime('now -5 minutes'));
     $locator = $this->_mediaServiceProxy->createLocator($locator);
     return $locator;
 }
 /**
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::updateLocator
  */
 public function testUpdateLocator()
 {
     // Setup
     $asset = new Asset(Asset::OPTIONS_NONE);
     $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix());
     $asset = $this->createAsset($asset);
     $access = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix());
     $access->setDurationInMinutes(30);
     $access->setPermissions(AccessPolicy::PERMISSIONS_READ);
     $access = $this->createAccessPolicy($access);
     $locator = new Locator($asset, $access, Locator::TYPE_ON_DEMAND_ORIGIN);
     $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix());
     $locator = $this->createLocator($locator);
     $newName = TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix();
     // Test
     $locator->setName($newName);
     $this->restProxy->updateLocator($locator);
     // Assert
     $this->assertEquals($newName, $locator->getName());
 }
 public function createAssetWithFilesForStream()
 {
     $asset = new Asset(Asset::OPTIONS_NONE);
     $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix());
     $asset = $this->createAsset($asset);
     $access = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix());
     $access->setDurationInMinutes(30);
     $access->setPermissions(AccessPolicy::PERMISSIONS_WRITE);
     $access = $this->createAccessPolicy($access);
     $locator = new Locator($asset, $access, Locator::TYPE_SAS);
     $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix());
     $locator->setStartTime(new \DateTime('now -5 minutes'));
     $locator = $this->createLocator($locator);
     $firstFile = TestResources::getSmallIsm();
     $secondFile = TestResources::getSmallIsmc();
     $this->restProxy->uploadAssetFile($locator, TestResources::MEDIA_SERVICES_ISM_FILE_NAME, $firstFile);
     $this->restProxy->uploadAssetFile($locator, TestResources::MEDIA_SERVICES_ISMC_FILE_NAME, $secondFile);
     $this->restProxy->createFileInfos($asset);
     return $asset;
 }
 /**
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::createAsset
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::createAccessPolicy
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::createLocator
  */
 public function testCreatingOriginUrlForStreamingContent()
 {
     // Setup
     $asset = $this->createAssetWithFilesForStream();
     $accessPolicy = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix());
     $accessPolicy->setDurationInMinutes(300);
     $accessPolicy->setPermissions(AccessPolicy::PERMISSIONS_READ);
     $accessPolicy = $this->createAccessPolicy($accessPolicy);
     $locator = new Locator($asset, $accessPolicy, Locator::TYPE_ON_DEMAND_ORIGIN);
     $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix());
     $locator->setStartTime(new \DateTime('now -5 minutes'));
     $locator = $this->createLocator($locator);
     $expectedFileContent = TestResources::getSmallIsmc();
     // without sleep() Locator hasn't enough time to create URL, so that's why we have to use at least sleep(30)
     sleep(40);
     // Test
     $method = Resources::HTTP_GET;
     $url = new Url($locator->getPath() . '/' . TestResources::MEDIA_SERVICES_ISM_FILE_NAME . '/' . TestResources::MEDIA_SERVICES_STREAM_APPEND);
     $filters = array();
     $statusCode = Resources::STATUS_OK;
     $httpClient = new HttpClient();
     $httpClient->setMethod($method);
     $httpClient->setExpectedStatusCode($statusCode);
     $result = $httpClient->send($filters, $url);
     // Assert
     $this->assertEquals($expectedFileContent, $result);
 }
    //print "File {$file->getName()} assetId={$file->getParentAssetId()}\r\n";
    if ($file->getParentAssetId() === $encodedAsset->getId() && endsWith(strtolower($file->getName()), '.ism')) {
        $manifestFile = $file;
    }
}
if ($manifestFile == null) {
    print "Unable to found the manifest file\r\n";
    return -1;
}
// 6.2 Create a 30-day readonly AccessPolicy
$access = new AccessPolicy("Streaming Access Policy");
$access->setDurationInMinutes(60 * 24 * 30);
$access->setPermissions(AccessPolicy::PERMISSIONS_READ);
$access = $restProxy->createAccessPolicy($access);
// 6.3 Create a Locator using the AccessPolicy and Asset
$locator = new Locator($encodedAsset, $access, Locator::TYPE_ON_DEMAND_ORIGIN);
$locator->setName("Streaming Locator");
$locator = $restProxy->createLocator($locator);
// 6.4 Create a Smooth Streaming base URL
$stremingUrl = $locator->getPath() . $manifestFile->getName() . "/manifest";
print "Done! Streaming URL: {$stremingUrl}\r\n";
// the End
//////////////////////////////////////////////////////////////////////////////////////////////////////////
/// HELPER FUNCTIONS
function endsWith($haystack, $needle)
{
    $length = strlen($needle);
    if ($length == 0) {
        return true;
    }
    return substr($haystack, -$length) === $needle;
function publishEncodedAsset($restProxy, $encodedAsset)
{
    // 6.1 Get the .ISM AssetFile
    $files = $restProxy->getAssetAssetFileList($encodedAsset);
    $manifestFile = null;
    foreach ($files as $file) {
        if (endsWith(strtolower($file->getName()), '.ism')) {
            $manifestFile = $file;
        }
    }
    if ($manifestFile == null) {
        echo "Unable to found the manifest file" . PHP_EOL;
        exit(-1);
    }
    // 6.2 Create a 30-day read-only AccessPolicy
    $access = new AccessPolicy("Streaming Access Policy");
    $access->setDurationInMinutes(60 * 24 * 30);
    $access->setPermissions(AccessPolicy::PERMISSIONS_READ);
    $access = $restProxy->createAccessPolicy($access);
    // 6.3 Create a Locator using the AccessPolicy and Asset
    $locator = new Locator($encodedAsset, $access, Locator::TYPE_ON_DEMAND_ORIGIN);
    $locator->setName("Streaming Locator");
    $locator = $restProxy->createLocator($locator);
    // 6.4 Create a Smooth Streaming base URL
    $stremingUrl = $locator->getPath() . $manifestFile->getName() . "/manifest(format=m3u8-aapl)";
    echo "Streaming URL: {$stremingUrl}" . PHP_EOL;
}
 public function uploadSingleFile($fileName, $fileContent)
 {
     $asset = new Asset(Asset::OPTIONS_NONE);
     $asset->setName($fileName);
     $asset = $this->createAsset($asset);
     $access = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix());
     $access->setDurationInMinutes(30);
     $access->setPermissions(AccessPolicy::PERMISSIONS_WRITE);
     $access = $this->createAccessPolicy($access);
     $locator = new Locator($asset, $access, Locator::TYPE_SAS);
     $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix());
     $locator->setStartTime(new \DateTime('now -5 minutes'));
     $locator = $this->createLocator($locator);
     $this->restProxy->uploadAssetFile($locator, $fileName, $fileContent);
     $this->restProxy->createFileInfos($asset);
     $list = $this->restProxy->getAssetAssetFileList($asset);
     if (isset($list[0])) {
         $list[0]->setIsPrimary(true);
         $this->restProxy->updateAssetFile($list[0]);
     } else {
         throw new Exception("unable to find the asset file");
     }
     return $asset;
 }
 public function uploadFile($fileName, $fileContent)
 {
     $asset = new Asset(Asset::OPTIONS_NONE);
     $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix());
     $asset = $this->createAsset($asset);
     $access = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix());
     $access->setDurationInMinutes(30);
     $access->setPermissions(AccessPolicy::PERMISSIONS_WRITE);
     $access = $this->createAccessPolicy($access);
     $locator = new Locator($asset, $access, Locator::TYPE_SAS);
     $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix());
     $locator->setStartTime(new \DateTime('now -5 minutes'));
     $locator = $this->createLocator($locator);
     $this->restProxy->uploadAssetFile($locator, $fileName, $fileContent);
     $this->restProxy->createFileInfos($asset);
     $accessPolicy = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix());
     $accessPolicy->setDurationInMinutes(300);
     $accessPolicy->setPermissions(AccessPolicy::PERMISSIONS_READ);
     $accessPolicy = $this->createAccessPolicy($accessPolicy);
     $locator = new Locator($asset, $accessPolicy, Locator::TYPE_SAS);
     $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix());
     $locator->setStartTime(new \DateTime('now -5 minutes'));
     $locator = $this->createLocator($locator);
     // without sleep() Locator hasn't enough time to create URL, so that's why we have to use at least sleep(30)
     sleep(40);
     $method = Resources::HTTP_GET;
     $url = new Url($locator->getBaseUri() . '/' . $fileName . $locator->getContentAccessComponent());
     $filters = array();
     $statusCode = Resources::STATUS_OK;
     $httpClient = new HttpClient();
     $httpClient->setMethod($method);
     $httpClient->setExpectedStatusCode($statusCode);
     return $httpClient->send($filters, $url);
 }
 /**
  * @covers WindowsAzure\MediaServices\Models\Locator::createFromOptions
  * @covers WindowsAzure\MediaServices\Models\Locator::fromArray
  */
 public function testLocatorFromOptions()
 {
     // Setup
     $locatorArray = array('Id' => 'kjshfs89', 'Name' => 'newLocator', 'ExpirationDateTime' => '2013-11-30', 'Type' => Locator::TYPE_NONE, 'Path' => 'http://someurl.com/gdkf76r', 'BaseUri' => 'http://someurl.com/uysfdu56y', 'ContentAccessComponent' => 'AccessComponent', 'AccessPolicyId' => 'uifygid75', 'AssetId' => 'ljhsdfl45', 'StartTime' => '2013-11-19');
     $expiration = new \Datetime($locatorArray['ExpirationDateTime']);
     $start = new \Datetime($locatorArray['StartTime']);
     // Test
     $resultLocator = Locator::createFromOptions($locatorArray);
     // Assert
     $this->assertEquals($locatorArray['Id'], $resultLocator->getId());
     $this->assertEquals($locatorArray['Name'], $resultLocator->getName());
     $this->assertEquals($expiration->getTimestamp(), $resultLocator->getExpirationDateTime()->getTimestamp());
     $this->assertEquals($locatorArray['Type'], $resultLocator->getType());
     $this->assertEquals($locatorArray['Path'], $resultLocator->getPath());
     $this->assertEquals($locatorArray['BaseUri'], $resultLocator->getBaseUri());
     $this->assertEquals($locatorArray['ContentAccessComponent'], $resultLocator->getContentAccessComponent());
     $this->assertEquals($locatorArray['AccessPolicyId'], $resultLocator->getAccessPolicyId());
     $this->assertEquals($locatorArray['AssetId'], $resultLocator->getAssetId());
     $this->assertEquals($start->getTimestamp(), $resultLocator->getStartTime()->getTimestamp());
 }
function downloadAssetFiles($restProxy, $asset, $destinationPath)
{
    // Create destination directory if does not exist
    if (!file_exists($destinationPath)) {
        mkdir($destinationPath);
    }
    // Create an Access Policy with Read permissions
    $accessPolicy = new AccessPolicy('DownloadAccessPolicy');
    $accessPolicy->setDurationInMinutes(60.0);
    $accessPolicy->setPermissions(AccessPolicy::PERMISSIONS_READ);
    $accessPolicy = $restProxy->createAccessPolicy($accessPolicy);
    // Create a SAS Locator for the Asset
    $sasLocator = new Locator($asset, $accessPolicy, Locator::TYPE_SAS);
    $sasLocator->setStartTime(new \DateTime('now -5 minutes'));
    $sasLocator = $restProxy->createLocator($sasLocator);
    $files = $restProxy->getAssetAssetFileList($asset);
    // Download Asset Files
    foreach ($files as $file) {
        echo "Downloading {$file->getName()} output file...";
        $restProxy->downloadAssetFile($file, $sasLocator, $destinationPath);
        echo "Done!" . PHP_EOL;
    }
    // Clean up Locator and Access Policy
    $restProxy->deleteLocator($sasLocator);
    $restProxy->deleteAccessPolicy($accessPolicy);
}
function publishLiveAsset($restProxy, $asset)
{
    // 1 Get the .ISM AssetFile
    echo "Publishing Asset...";
    $files = $restProxy->getAssetAssetFileList($asset);
    $manifestFile = null;
    foreach ($files as $file) {
        if (endsWith(strtolower($file->getName()), '.ism')) {
            $manifestFile = $file;
        }
    }
    if ($manifestFile == null) {
        echo "Unable to found the manifest file" . PHP_EOL;
        exit(-1);
    }
    // 2 Create a 30-day read-only AccessPolicy
    $access = new AccessPolicy('Live Access Policy');
    $access->setDurationInMinutes(60 * 24 * 30);
    $access->setPermissions(AccessPolicy::PERMISSIONS_READ);
    $access = $restProxy->createAccessPolicy($access);
    // 3 Create a Locator using the AccessPolicy and Asset
    $locator = new Locator($asset, $access, Locator::TYPE_ON_DEMAND_ORIGIN);
    $locator->setName('Live Locator');
    $locator = $restProxy->createLocator($locator);
    echo "Done!" . PHP_EOL;
    // 4 Return the Smooth Streaming base URL
    return $locator->getPath() . $manifestFile->getName() . '/manifest';
}