Customizing your Kaltura CE Remote Storage Profile

Kaltura CE comes with several solutions for Storing and Playing your Video out-of-the-box, but sometimes Kaltura CE Remote Storage doesn’t offer the exact solution to fit your requirements.
If you can’t find a suitable solution from the list of features that come with Kaltura CE, you can always rewrite and enhance the Remote Storage Profile.

  • We’ll also explain how to change the Playing Path in this blog post.

The changes that we are suggesting in this blog post, came due to the fact that we wanted to control and manage our storage for every partner, based on the name of the Video, and not on the entryID ( The entry id is meaningless if we don’t have any access to Kaltura KMC).

Change the Kaltura CE Remote Storage Profile Path

1. Create a new file which will contain the new custom path for the storage.
* You should create this file under app/alpha/apps/kaltura/lib/storage/<Storage_file_name>

2. Open the StorageHelper file which can be found under “app/admin_console/forms/Partner/StorageHelper.php” and search for the following function:

public static function addPathManagersToForm(Zend_Form $form)
{
  $arr = array(
    'kPathManager' => 'Kaltura Path',
    'kExternalPathManager' => 'External Path',
    'kXslPathManager' => 'XSL Path',
    'kCustomPathManager' => 'Custom Path Manager',
    '<Storage_file_name_from_step_1> => '<The_name_of_storage>’,
  );

  $form->getElement('pathManagerClass')->setMultiOptions($arr);
}

3. Copy the content from app/alpha/apps/kaltura/lib/storage/kCustomPathManager.php file to your new Storage file and rewrite it as you wish.
NOTE: In order to understand the flow it is recommended to edit the $path_format variable and then just “Search & Replace” its content; this will make the code more readable.

Example of changing the Kaltura CE Remote Storage Path:
From: “2013-07-12/112/The Simpsons.mp4”
To: “112/0_ssjkadhka.Panda-OS/The Simpsons.mp4”.
{fileName} = The Simpsons.mp4
{entryId} = 0_ssjkadhka
{partnerDir} = 112
Original Code:

$path_format = '{year}{month}{day}/{partnerDir}/{fileName}';
$path = str_replace('{fileName}', $fileName, $path_format);
$path = str_replace('{partnerDir}', $partnerDir, $path);

My New Path Code:

$path_format = '{partnerDir}/{entryId}.Panda-OS/{fileName}';
$path = str_replace('{fileName}', $fileName, $path_format);
$path = str_replace('{partnerDir}', $partnerDir . ‘Panda-OS’ ,$path);

Now when uploading files to the Remote Storage they will be saved with the new path you have defined.

Change the Playing source

1. Create a new file which will contain the new custom playing source.
* You should create this file under app/alpha/apps/kaltura/lib/storage/urlMgr/<Playing_path_file_name>

2. Repeat the same procedure in step 2 above for the StorageHelper.php file but this time change the following function:

public static function addUrlManagersToForm(Zend_Form $form)

3. Copy the content from app/alpha/apps/kaltura/lib/storage/urlMgr/kLocalPathUrlManager.php file to your new Storage file and rewrite it as you wish.
NOTE: this code line $url = $fileSync->getFilePath(); will bring the file path you have defined in your Storage Profile >> Path Manager so if you’re using another source file that should be played such as .f4m or .m3u8 and not the flavor itself you should again “Search and Replace” the $url object as you wish.

Example:
In this example I’ll show how to change the file extension.
If Apple format, then extension should be “m3u8” for HLS, Else, “f4m” for playing HDS.

public function getFileSyncUrl(FileSync $fileSync)
{
    $fileSync = kFileSyncUtils::resolve($fileSync);
    $url = $fileSync->getFilePath();
    $url = str_replace('\', '/', $url);
    $urlAssist = explode('/',$url);
    $url = str_replace($urlAssist[count($urlAssist)-1], 'Panda-OS.', $url);
    // If apple we want that the file extension will be m3u8 which is apple format, else we want f4m.
    if ($this->protocol == StorageProfile::PLAY_FORMAT_APPLE_HTTP)
    {
        $url = $url . "m3u8";
    }
    else
    {
        $url = $url . "f4m";
    }
    return $url;
}

For any additional questions or assistance you can comment below and we will reply.

Leave a Reply

Your email address will not be published. Required fields are marked *