# Code Sample on Integrating Bitmovin Encoder with PallyCon Multi-DRM

**URL:** <https://community.bitmovin.com/t/code-sample-on-integrating-bitmovin-encoder-with-pallycon-multi-drm/961>\
**Category:** Resources\
**Tags:** bitmovin-encoding, code-example\
**Created:** [July 1, 2022, 9:19am UTC](https://community.bitmovin.com/t/code-sample-on-integrating-bitmovin-encoder-with-pallycon-multi-drm/961 "2022-07-01T09:19:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![seven](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@seven](https://community.bitmovin.com/u/seven)\
**Post date:** [July 1, 2022, 9:19am UTC](https://community.bitmovin.com/t/code-sample-on-integrating-bitmovin-encoder-with-pallycon-multi-drm/961/1 "2022-07-01T09:19:38Z")

</div>

## Overview

This tutorial walks through integrating Bitmovin CENC Encoding with PallyCon CPIX DRM in TWO simple steps. 🙌

For a full working sample refer to the [Appendix](#Appendix)

## Pre-requisites

1. `CONTENT-ID` ; your script can generate this id to uniquely identify each content
2. `KMS version` ; this tutorial uses PallyCon KMS version 2 as it supports multi-key encryption
3. `PallyCon KMS URL` ; most of the time it looks like this _[https://kms.pallycon.com/v2/cpix/pallycon/getKey/](https://kms.pallycon.com/v2/cpix/pallycon/getKey/)_
4. `KMS token` ; to uniquely identify and protect your request to the PallyCon KMS  
Screenshot from the `PALLYCON` portal  
 ![pallycon-token](https://us1.discourse-cdn.com/flex015/uploads/bitmovin/original/1X/87f442f5e132aebafa04b19053e580509c62ef71.jpeg)

## Applicable Use cases

1. Single Key for all renditions
2. Multi-key i.e different keys for different renditions

In this tutorial we’ll run through use case #2 i.e Multi-Key

## Step 1. Get DRM information from PallyCon

**OVERVIEW**

We’ll be discussing multi-key integration i.e 1 key for SD and 1 key for AUDIO. Implementation of the below logic can be found in the method [\_get\_pallycon\_drm\_config @ cenc\_drm\_content\_protection.py](https://assets.ctfassets.net/blfijbdi3ei3/58OoJ5My9xDyfaGIkpOHIX/dcffcd842561f340899a5e8982d5513f/cenc_drm_content_protection.py)

**STEPS**

1. Get the values from the pre-requisites section and update them respectively

```auto
...
CONTENT_ID = "my-unique_content_id"
PALLYCON_KMS_URL = "https://kms.pallycon.com/v2/cpix/pallycon/getKey/"
PALLYCON_ENC_TOKEN = 'PALLYCON_KMS_TOKEN'

# Request headers
headers = {'content-type': 'application/xml'}
...

```

1. Request DRM keys from PallyCon. in this case it’s been configured for the Fairplay, Widevine and Playready for 1 SD key and 1 AUDIO key.
2. Parse the PallyCon DRM response into the Pallycon\_Drm\_Config helper class

## Step 2. Apply PallyCon DRM using Bitmovin CENC API

1. After getting the PallyCon drm configs we first split the DRM config by tracks i.e SD/AUDIO

```auto
...
    def get_drm_config_by_track(pallycon_drm_configs: typing.Dict, track: str) -> typing.Dict:
        return dict(filter(lambda elem: (elem[1]).get_track() == track,pallycon_drm_configs.items()))

    pallycon_drm_configs = _get_pallycon_drm_config()
    audio_drm_configs = get_drm_config_by_track(pallycon_drm_configs, "AUDIO")
    sd_drm_configs = get_drm_config_by_track(pallycon_drm_configs, "SD")
...

```

1. Lastly we apply the `Pallycon_Drm_Config` and create the DRM Muxing by using the method [\_create\_drm\_config @ cenc\_drm\_content\_protection.py](https://assets.ctfassets.net/blfijbdi3ei3/58OoJ5My9xDyfaGIkpOHIX/dcffcd842561f340899a5e8982d5513f/cenc_drm_content_protection.py)

It’s **THAT EASY!** 🎉

## FAQ

### Question: Exception in \_get\_pallycon\_drm\_config @ cenc\_drm\_content\_protection.py

Answer: This could be due to an

1. expired PallyCon DRM token OR
2. invalid request body

Kindly check with your PallyCon contact for more details.

## Appendix

WORKING Source code

1. Clone the [Bitmovin GitHub](https://github.com/bitmovin/bitmovin-api-sdk-examples/blob/main/python/src/cenc_drm_content_protection.py) repository
2. use this updated [cenc\_drm\_content\_protection.py](https://assets.ctfassets.net/blfijbdi3ei3/58OoJ5My9xDyfaGIkpOHIX/dcffcd842561f340899a5e8982d5513f/cenc_drm_content_protection.py) file w/ the PallyCon integation in place of the GitHub sample

Additional reads

1. please visit the reference By [PallyCon](https://pallycon.com/docs/en/multidrm/packaging/bitmovin-encoder-guide/).
