How to pre-populate your editor with content

Kaltura Bug on Safari

Overview

This guide will show you how to pre-populate your editor clip library.
This guide will use the Kaltura testme API console to demonstrate the API calls in images and code samples will be provided in PHP. This guide is especially useful for publishers creating remixing campaigns.
Note : If you are using the editor but not the remix site there is one important thing you need to know. You do NOT need to create a new mix every time you launch the editor. See bottom of page for more information.

Populate the Editor with Multiple Files (using a script and the KMC)

Select your content in the Kaltura Management Console (KMC)
In order to select the content you want to populate your editor with, follow these few easy steps -

  1. Log in to the Kaltura Management Console (http://www.kaltura.com/index.php/kmc/kmc) with your username and password.
  2. Select the videos, images or sound you want to populate your editor with using the check-boxes.
  3. Click on the 'Add Admin Tags' button at the bottom of the screen. Choose any filter such as 'for_remix'. This filter will determine which entries will be added to your mix.

Defining Parameters
First you need to define a few mandatory paremeters such as your partner id, sub partner id, Kaltura secret etc. You will also need to define the name of the mix you will create (note it will appear as the editor title by default) and the filter for the entries you set as the admin tags in the KMC in the previous step.
It is also recommended you include the Kaltura client at this point:

require_once("kaltura_client.php");

$userId = "username";
$partnerId = "XXXX";
$subPartnerId = "XXXXXX";
$secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$adminsecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$host = "www.kaltura.com";
$mix_name = "Mix Title";
$filtered_entries = "the_admin_tag_you_set_in_the_kmc";

Start an admin session
The first thing we'll do is to pull the list of entries you determined on earlier in the KMC using the admin tags. Before we call listEntries on your partner we will need an admin session as listEntries is an admin API call:

$config = new KalturaConfiguration($partnerId, $subPartnerId);
$config->serviceUrl = $host;
$client = new KalturaClient($config);
$user = new KalturaSessionUser();
$user->userId = $userId;

$result = $client->startSession($user, $adminsecret, true, "edit:*");
$sessionId = @$result["result"]["ks"];
$client->setKS($sessionId);

Build the filter and list the entries
Now that we have the admin session we're able to list the entries we want to add to the mix. We can list and add all of the entries in our partner but since we probably only want a few selected entries, the filter we create will only return entries with the admin tag we defined in the KMC:

// create the filter
$filter = new KalturaEntryFilter();
// .... that are admin-tagged for this purpose (i.e. for the remix)
$filter->multiLikeAndAdminTags = $filtered_entries;

// list entries that are returned with the filter defined above
$result = $client->listEntries($user, $filter, false, null, $pageSize, $page);
$entries = $result['result']['entries'];

Start a web services (normal) session
Now we're going to perform two actions that require a web services (normal) session - create a new mix entry (roughcut) and add the entries we listed above to that mix. Both addRoughcutEntry and addEntry require a web services session:

$result = $client->startSession($user, $secret, false);
$sessionId = @$result["result"]["ks"];
$client->setKs($sessionId);

Create a new mix (Roughcut)
Now that we have the session we can create a new mix (roughcut). We'll start by defining the Kaltura entry (only mandatory parameter in this class is the title, in the addRoughcutEntry call itself you pass the entry id, '-2' as the kshow id (fixed parameter - don't ask why). This call will return your new mix ID. You will use it in your minisite so write it down somewhere.

$mix = new KalturaEntry;
$mix->name = $mix_name;
       
$result = $client->addRoughcutEntry($user, -2, $mix);
$mix_id = @$result["result"]["entry"]["id"];
echo '<b>Your new mix ID is </b>"' . $mix_id . '"<br>';

Add the entries to the new mix
Now all you need to do is to add the entries you listed above to the mix you just created.

echo '<b>These entries were added to the mix - </b><br>';
foreach ($entries as $key => $entry) {
        $e = new KalturaEntry;
        $e->name = $entry["name"];
        $e->source = 23;
        $e->mediaId = $entry["id"];
        $result = $client->addEntry($user, 'entry-' . $mix_id, $e, null, '0');
        echo $entry["id"] . '-' . $entry["name"] . '<br>';
        }

At this point it's important to make a few clarifications -

  1. The entries you add will actually be duplicated and form new entries. It's not optimal however that's this specific script's side effect. This also means that every time you run the script you'll double the entries that will be added to the mix since the admin tag is also copied with the entry. I've already received suggestions on better ways to accomplish this use case and avoid this issue and I will add it to this guide soon. If you already figured it out please post your suggestions in the comments.
    Obviously you can delete the original files afterwards - you don't need to keep it twice.
  2. The kshow parameter is mandatory in the addEntry, and in this case and in many other cases in this remix site the kshow id will be 'entry-MIX_ID' so if the mix id you created is 'abc123' your kshow will be 'entry-abc123'
  3. To prevent the entries from being added to the editor timeline (to create a clean start for your users) you will have to pass a parameter called 'quick_edit' false (0) when performing the addEntry call. your client might not have this parameter included so I recommend downloading the code below.

Click here to download the complete script (includes the Kaltura PHP5 Client Library).

*Kalturian* Please review the code, repack and put somewhere public :-) Note it needs to come with the attached client as I made some modifications to the client that are not supported in the generic client.

That's it!
Now editor your remix site configuration file and look for the 'BASE KSHOW' parameter. Your 'BASE KSHOW' will be 'entry-MIX_ID' so if the mix id you created is 'abc123' it should be 'entry-abc123'

Note if you are not using the remix mini site source code and building something of your own you should know that you should NOT open the editor with the mix ID you just created since you probably want to keep it nice and clean. And so before launching the editor you should use the cloneRoughcut API call to create a new mix for that specific user/remixing session and launch the editor with that.

Populate the Editor with a Single or a Few Files (using Testme) - Visual Guide

Start a web services session

First start a web services session. You will need a few mandatory paremeters such as your partner id, sub partner id and Kaltura secret.

Create a new mix (Roughcut)
Now call the ‘addRoughcutEntry’ method in order to create your new empty mix. Once an empty mix has been created you will use it as your template/base mix. Please note -

  1. The kshow_id should be ‘-2’ in this use case (it is really not important why).
  2. This call will return your new mix ID. You will use it in your minisite so write it down somewhere.

Add entries to the new mix
Perform “Add Entry” -By passing kshow_id as “entry-{ENTRYID}” when ENTRYID is the id of the template mix you created at the previous step, you basically populate your mix. Passing quick_edit ‘0’ gets the entry added to the clip library, but not to the timeline This step should be repeated for each video that you want to add to the clip library

That's it!
Now editor your remix site configuration file and look for the 'BASE KSHOW' parameter. Your 'BASE KSHOW' will be 'entry-MIX_ID' so if the mix id you created is 'abc123' it should be 'entry-abc123'

Note if you are not using the remix mini site source code and building something of your own you should know that you should NOT open the editor with the mix ID you just created since you probably want to keep it nice and clean. And so before launching the editor you should use the cloneRoughcut API call to create a new mix for that specific user/remixing session and launch the editor with that.

Using the editor but not the remix site?

If you are using the editor but not the remix site there is one important thing you need to know. You do NOT need to create a new mix every time you launch the editor. You only go thorough the process above ONCE to create the base mix, and then CLONE it every time before you launch the editor so each user remixes a clone of the original mix and doesn't manipulate the original clip library.
It is not mentioned in the guide as Kaltura Remix Site already does the cloning for you while you only provide the base mix id. Cloning a roughcut is very easy -

$mix_id = 'vq3okhsf94';     // The entry id of the mix we created above
$result         = $client->cloneRoughcut($user,$mix_id);      // Cloning the mix.
$new_mix_id = @$result["result"]["entry"]["id"];    // Retrieving the new mix id. THIS is what you launch the editor with.     

Comments

[SOLVED] PHP librairies seems corrupted

I tried this using the new PHP libraries and even on a basic listEntries() I get an CURL_ERROR
We are using PHP 5.2 and previous Kaltira libraries were working just fine except for the missing 'quick-edit' parameter.

Did someone got it to work ?

Thanks.

My mistake, using the code

My mistake, using the code provided it works.

Attention Non Remix Site Users

now realize I should have mentioned it in the guide. The guide was written mainly for partners using our 'remix site' application that already contains the cloning function and one of the parameters it requires is a base remix with the content populated in it. I will add a comment to the guide.

After you create your base remix properly once, every time you launch the editor you need to run cloneRoughcut API method on that remix you created (that's the only parameter you need to pass). The result will contain the new mix ID that was duplicated and that's what you need to run the editor with.

I attached an updated script

I attached an updated script that is easier to integrate - use this.
Don't forget to replace the partner details with yours.

AttachmentSize
pre-populated-mix.rar11.02 KB

prepopulate script

Hi,

I am using your prepop script for KSE and some strange things happen. The first time I loaded it, the entries were written to the page but the flash editor hung (just the spinning icon in the middle with nothing loading). The second time I loaded it, I got the Editor and it loaded the clips and worked. Now, I have tried at least 10 times to load it and it hangs again. I have not changed the code and it resides on the same server.

I then uploaded it to a less busy server and got the load failed message in the flash piece.

The code:

<?php
require_once("kaltura_client.php");
// CHANGE THE FOLLOWING PARAMS TO YOUR PARTNER AND APPLICATION INFORMATION:
// Replace the 'xxxxx' with your partner values.
$userId = "kyle";
$partnerId = "353251";
$subPartnerId = "35325100";
$secret = "93e13cb9f788732a42deb4a243463374";
$adminsecret = "743fa225e0e1b9c343c06e17f6ee8e16";
$host = "www.kaltura.com";
$mix_name = "Mix Title";
$filtered_entries = "";

// create admin session for listentries
$config = new KalturaConfiguration($partnerId, $subPartnerId);
$config->serviceUrl = $host;
$client = new KalturaClient($config);
$user = new KalturaSessionUser();
$user->userId = $userId;

$result = $client->startSession($user, $adminsecret, true, "edit:*");
$sessionId = @$result["result"]["ks"];
$client->setKS($sessionId);

// create the filter
$filter = new KalturaEntryFilter();
// .... that are admin-tagged for this purpose (i.e. for the remix)
$filter->multiLikeAndAdminTags = $filtered_entries;

// list entries that are returned with the filter defined above
$result = $client->listEntries($user, $filter, false, null, $pageSize, $page);
$entries = $result['result']['entries'];

// create new web session for creating a new mix (roughcut) and addEntry
$result = $client->startSession($user, $secret, false);
$sessionId = @$result["result"]["ks"];
$client->setKs($sessionId);

// create a new mix (roughcut)
$mix = new KalturaEntry;
$mix->name = $mix_name;

$result = $client->addRoughcutEntry($user, -2, $mix);
$mix_id = @$result["result"]["entry"]["id"];
echo 'Your new mix ID is "' . $mix_id . '"
';

// add entries to roughcut defined as $mix_id
echo 'These entries were added to the mix -
';
foreach ($entries as $key => $entry) {
$e = new KalturaEntry;
$e->name = $entry["name"];
$e->source = 23;
$e->mediaId = $entry["id"];
$result = $client->addEntry($user, 'entry-' . $mix_id, $e, null, '0');
echo $entry["id"] . '-' . $entry["name"] . '
';
}

$flashVars = array();
$flashVars["partnerId"] = $partnerId;
$flashVars["subpId"] = $subPartnerId;
$flashVars["uid"] = $user->userId;
$flashVars["ks"] = $sessionId;
$flashVars["kshowId"] = "entry-".$mix_id;
$flashVars["entryId"] = $mix_id;
$flashVars["backF"] = "onSimpleEditorBackClick";
$flashVars["saveF"] = "onSimpleEditorSaveClick";
$flashVars["quick_edit"] = 0;
?>

var params = {
allowScriptAccess: "always",
allowNetworking: "all",
wmode: "opaque"
};
var flashVars = <?php echo json_encode($flashVars); ?>;
swfobject.embedSWF("http://www.kaltura.com/kse/ui_conf_id/1000200", "kse", "890", "546", "9.0.0", false, flashVars, params);

function onSimpleEditorBackClick(isModified) {
alert('onSimpleEditorBackClick');
}

function onSimpleEditorSaveClick() {
alert('onSimpleEditorSaveClick');
}

Any tips would be appreciated. THe code worked once so why would it crap out now? Very confusing...

Quote: The entries you add

Quote:
The entries you add will actually be duplicated and form new entries. It's not optimal however that's this specific script's side effect. This also means that every time you run the script you'll have double the entries that will be added to the mix since the admin tag is also copied with the entry. I've already received suggestions on better ways to accomplish this use case and avoid this issue and I will add it to this guide soon. If you already figured it out please post your suggestions in the comments. Obviously you can delete the original files afterward - you don't need to keep it twice.

Any news on this? What's the best way to accomplish it?

actually there's even a better way to do it

It might be even simpler than the above if you're only starting to upload the content especially for that, and you don't mind populating the timeline. This is what you do -
1) Create a new roughcut using addroughcutentry.
2) Launch the contribution wizard and pass this kshow id - "entry-{TheRoughcutYouCreatedAbove}" i.e. entry-124dj39d.
3) All of the content uploaded in tht uploading session will be added to the mix, but also to the timeline.
This is all becoming much easier in api v3 released very soon.

I just noticed that the

I just noticed that the kaltura_client.php included does not actually include support for the quick_edit tag despite the fact that this document says it does. Attached is a updated file that includes support for the quick_edit tag.

AttachmentSize
kaltura_client.txt93.54 KB

Attached is an updated

Attached is an updated version of Assaf's code. It's essentially the same except it now removes the admin tag after duplicating the entry, and it removes the original entry after it's been duplicated. It also assumes you wish to have quick_edit set to false (so that entries aren't automatically added to the remix timeline).

Please review and test the code before applying it for lots of important entries as it may not behave as expected.

I hope this is of some help!

Best Regards, Chris!

AttachmentSize
kaltura_client_base.php_.txt6.51 KB
kaltura_client.php_.txt93.54 KB
index.php_.txt3.9 KB

After playing around some

After playing around some more, I've updated the index.php file so that it now adds ALL entries that have the appropriate admin tag - not just the first ten (as per the original script).

It's a very crude implementation, so feel free to improve upon it!

Best Regards, Chris Hocking.

AttachmentSize
index_updated.txt4.2 KB

Chris you are a genious!

Chris -
I just had to use this functionality again for a personal project I'm working on and the new code you created is slick, clean, clear and plain awesome. thank you so much for sharing this!

My absolute pleasure!

My absolute pleasure!

What happened to this

What happened to this document???

WordPress plugin

Is there any documentation to apply the pre-load function for use with the All-In-One WordPress plugin? I cannot seem to get the Remix function to work using WP 2.7.1 no matter what. I've posted in the forum already too.

Sorry... What exactly are

Sorry... What exactly are you trying to achieve? Do you want the editor to already contain clips when it opens via the Wordpress Plugin?

What about API v3?

Can we get an updated document for v3 of the API?

API v3?

Still no update for v3?

API V3

is there allready a sample white the api v3?
THX and look forward :-)

api v3 samples

anyone got an api v3 working sample? thanks

empty mix after getting a

empty mix after getting a $ksession:
$config = new KalturaConfiguration();
$config->serviceUrl = 'yourServerURL';
$client = new KalturaClient($config);
$mixEntry = null;
$client->setKs('$ksession');
$mixEntry = new KalturaMixEntry();
$mixEntry->name = 'myNewMix';
$mixEntry->editorType = KalturaEditorType::SIMPLE;
$results = $client->mixing->add($mixEntry);

now add entry to mix:

$mixEntryId = '0_dflapxib';
$mediaEntryId = '0_nbzu0izx';
$results = $client->mixing->appendMediaEntry($mixEntryId, $mediaEntryId);

Noise Figure

Really your written style is very attractive. thank you

Noise Figure