Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ private function createArgumentsForXSLT()
$tagsDoc->appendChild($tagsConfiguration);
$arguments['tagsparam'] = $tagsDoc->saveXML();

$partner = $this->entry->getPartner();
if ($partner && $partner->getPluginEnabled(DrmPlugin::PLUGIN_NAME))
{
$arguments['keyManagementPolicy'] = (string)DrmPlugin::getDrmKeyManagementPolicy($this->entry);
}
return $arguments;
}

Expand Down Expand Up @@ -288,4 +293,4 @@ private function createAppendXml($tag, $tagsDoc, $xmlNodeName, $propertyName)
return $nameNode;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
<!--widevine mbr-->
<xsl:param name="widevineMbrPpvModule" select="''"/>
<xsl:param name="widevineMbrTypeName" select="'widevine_mbr Main'"/>
<!--keyManagementPolicy-->
<xsl:param name="keyManagementPolicy" select="''"/>
<!--main logic -->
<xsl:template match="/">
<xsl:element name="feed">
Expand Down Expand Up @@ -244,6 +246,9 @@
<xsl:value-of select="$geoBlockRule"/>
</xsl:element>
</xsl:element>
<xsl:element name="drm_key_management_policy">
<xsl:value-of select="$keyManagementPolicy"/>
</xsl:element>
<xsl:element name="dates">
<xsl:variable name="sunrise" select="item/distribution/sunrise"/>
<xsl:variable name="sunriseFormatted" select="php:function('date' ,string($CONST_TVM_DATE_FORMAT),string($sunrise))"/>
Expand Down
173 changes: 173 additions & 0 deletions plugins/drm/DrmBulkUploadXmlPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php
/**
* Enable DRM key management policy ingestion from XML bulk upload
* @package plugins.drm
*/
class DrmBulkUploadXmlPlugin extends KalturaPlugin implements IKalturaPending, IKalturaSchemaContributor, IKalturaBulkUploadXmlHandler
{
const PLUGIN_NAME = 'drmBulkUploadXml';
const BULK_UPLOAD_XML_PLUGIN_NAME = 'bulkUploadXml';

/* (non-PHPdoc)
* @see IKalturaPlugin::getPluginName()
*/
public static function getPluginName()
{
return self::PLUGIN_NAME;
}

/* (non-PHPdoc)
* @see IKalturaPending::dependsOn()
*/
public static function dependsOn()
{
$bulkUploadXmlDependency = new KalturaDependency(self::BULK_UPLOAD_XML_PLUGIN_NAME);
$drmDependency = new KalturaDependency(DrmPlugin::getPluginName());

return array($bulkUploadXmlDependency, $drmDependency);
}

/* (non-PHPdoc)
* @see IKalturaSchemaContributor::contributeToSchema()
*/
public static function contributeToSchema($type)
{
$coreType = kPluginableEnumsManager::apiToCore('SchemaType', $type);
if(
$coreType != BulkUploadXmlPlugin::getSchemaTypeCoreValue(XmlSchemaType::BULK_UPLOAD_XML)
&&
$coreType != BulkUploadXmlPlugin::getSchemaTypeCoreValue(XmlSchemaType::BULK_UPLOAD_RESULT_XML)
)
return null;

$xsd = '

<!-- ' . self::getPluginName() . ' -->

<xs:complexType name="T_drmConfiguration">
<xs:sequence>
<xs:element name="keyManagementPolicy" minOccurs="0" maxOccurs="1" type="xs:int">
<xs:annotation>
<xs:documentation>
The DRM key management policy to apply to this entry.<br/>
Values correspond to the DrmKeyManagementPolicy enum:<br/>
0 = UNKNOWN<br/>
1 = CLEAR<br/>
2 = SHARED_KEY<br/>
3 = ALL_VIDEO<br/>
4 = SD_HD<br/>
5 = SD_HD_UHD<br/>
6 = SD_HD_UHD1_UHD2<br/>
7 = SD_HD1_HD2_UHD1_UHD2<br/>
8 = SD_HD1_HD2_UHD<br/>
9 = SDHD1_HD2_UHD<br/>
10 = SDHD1_HD2_UHD1_UHD2<br/>
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>

<xs:element name="drmConfiguration" type="T_drmConfiguration" substitutionGroup="item-extension">
<xs:annotation>
<xs:documentation>DRM key management policy configuration for this entry</xs:documentation>
<xs:appinfo>
<example>
<drmConfiguration>
<keyManagementPolicy>3</keyManagementPolicy>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 3?

</drmConfiguration>
</example>
</xs:appinfo>
</xs:annotation>
</xs:element>
';

return $xsd;
}

/* (non-PHPdoc)
* @see IKalturaBulkUploadXmlHandler::configureBulkUploadXmlHandler()
*/
public function configureBulkUploadXmlHandler(BulkUploadEngineXml $xmlBulkUploadEngine)
{

}

/* (non-PHPdoc)
* @see IKalturaBulkUploadXmlHandler::handleItemAdded()
*/
public function handleItemAdded(KalturaObjectBase $object, SimpleXMLElement $item)
{
if(!($object instanceof KalturaBaseEntry))
return;

if(!isset($item->drmConfiguration))
return;

$this->handleDrmConfiguration($object->id, $item);
}

/* (non-PHPdoc)
* @see IKalturaBulkUploadXmlHandler::handleItemUpdated()
*/
public function handleItemUpdated(KalturaObjectBase $object, SimpleXMLElement $item)
{
if(!($object instanceof KalturaBaseEntry))
return;

if(!isset($item->drmConfiguration))
return;

$this->handleDrmConfiguration($object->id, $item);
}

/* (non-PHPdoc)
* @see IKalturaBulkUploadXmlHandler::handleItemDeleted()
*/
public function handleItemDeleted(KalturaObjectBase $object, SimpleXMLElement $item)
{
// No handling required
}

/* (non-PHPdoc)
* @see IKalturaBulkUploadXmlHandler::getContainerName()
*/
public function getContainerName()
{
return 'drmConfiguration';
}

/**
* Set the DRM key management policy on the entry via the keyManagementPolicy service.
*
* @param string $entryId
* @param SimpleXMLElement $item
*/
private function handleDrmConfiguration($entryId, SimpleXMLElement $item)
{
KalturaLog::debug("Handling DRM key management policy for entry: " . $entryId);

$policy = new KalturaKeyManagementPolicy();
$policy->keyManagementPolicy = isset($item->drmConfiguration->keyManagementPolicy)
? (int)$item->drmConfiguration->keyManagementPolicy
: null;
try
{
KBatchBase::$kClient->keyManagementPolicy->update(
KalturaKeyManagementPolicyObjectType::ENTRY,
$entryId,
$policy
);
}
catch (Exception $e)
{
if ($e->getCode() == 'ENTRY_DRM_KEY_MANAGEMENT_POLICY_ALREADY_SET')
{
KalturaLog::info('DRM key management policy already set for entry [' . $entryId . '], skipping.');
return;
}
KalturaLog::err('drmConfiguration handling failed for entry [' . $entryId . ']: ' . $e->getMessage());
throw $e;
}
}
}
1 change: 1 addition & 0 deletions plugins/drm/lib/api/exceptions/DrmErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class DrmErrors
{
const ACTIVE_PROVIDER_PROFILE_ALREADY_EXIST = "ACTIVE_PROVIDER_PROFILE_ALREADY_EXIST;PROVIDER;Active profile for provider [@PROVIDER@] already exists.";
const DRM_POLICY_DUPLICATE_SYSTEM_NAME = "DRM_POLICY_DUPLICATE_SYSTEM_NAME;SYSTEM_NAME;Drm policy with system name [@SYSTEM_NAME@] already exists.";
const ENTRY_DRM_KEY_MANAGEMENT_POLICY_ALREADY_SET = "ENTRY_DRM_KEY_MANAGEMENT_POLICY_ALREADY_SET;ENTRY_ID;DRM key management policy is already set for entry [@ENTRY_ID@] and cannot be changed.";
}
31 changes: 28 additions & 3 deletions plugins/drm/services/DrmKeyManagementPolicyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,15 @@ public function getAction($objectType, $objectId)
* @param string $objectId
* @param KalturaKeyManagementPolicy $keyManagementPolicy
* @return KalturaKeyManagementPolicy
* @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
* @throws KalturaErrors::INVALID_ENUM_VALUE
* @throws KalturaErrors::INVALID_PARTNER_ID
* @throws KalturaErrors::INVALID_OBJECT_ID
* @throws KalturaErrors::PLUGIN_NOT_AVAILABLE_FOR_PARTNER
* @throws DrmErrors::ENTRY_DRM_KEY_MANAGEMENT_POLICY_ALREADY_SET
* @ksIgnored
*/
public function updateAction($objectType, $objectId, KalturaKeyManagementPolicy $keyManagementPolicy)
{
$keyManagementPolicy->validatePropertyNotNull('keyManagementPolicy');
$this->validateObjectType($objectType);

$result = new KalturaKeyManagementPolicy();
Expand All @@ -115,10 +114,36 @@ public function updateAction($objectType, $objectId, KalturaKeyManagementPolicy
else
{
$entry = $this->getValidatedEntry($objectId);
$entry->setDrmKeyManagementPolicy($keyManagementPolicy->keyManagementPolicy);

$existingStatus = $entry->getDrmKeyManagementPolicy();
if(!is_null($existingStatus))
{
throw new KalturaAPIException(DrmErrors::ENTRY_DRM_KEY_MANAGEMENT_POLICY_ALREADY_SET, $entry->getId());
}

$this->setDrmKeyManagementPolicyForEntry($entry, $keyManagementPolicy);
$entry->save();
$result->keyManagementPolicy = DrmPlugin::getDrmKeyManagementPolicy($entry);
}
return $result;
}

protected function setDrmKeyManagementPolicyForEntry(entry $entry, KalturaKeyManagementPolicy $keyManagementPolicy)
{
$partner = $entry->getPartner();
$partnerDrmKeyManagementPolicy = $partner->getDrmKeyManagementPolicy();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add null check before refferencing the partner


if(!is_null($keyManagementPolicy->keyManagementPolicy))
{
$entry->setDrmKeyManagementPolicy($keyManagementPolicy->keyManagementPolicy);
}
elseif(!is_null($partnerDrmKeyManagementPolicy))
{
$entry->setDrmKeyManagementPolicy($partnerDrmKeyManagementPolicy);
}
else
{
$entry->setDrmKeyManagementPolicy(DrmKeyManagementPolicy::UNKNOWN);
}
}
}
Loading