Panopto API 103 – Organise course folders into subfolders

Return to the Panopto API index page

This piece of code is the first half of why I started learning the Panopto API. This blog post was written after page 204, but is only to do with folders so I’ve called it 103.

Our Panopto server is connected to Blackboard, and the in-built integration is really fantastic. Nearly everything is automatic and all videos are nicely secured to the course in which they were recorded.

Now that the University owns Unison the requirement “secured to the course in which they were recorded” is a little too strict. Videos are normally uploaded to a course, not a course in a particular year. Guest lecturers are normally recorded once and re-used year on year. What we need is the ability to have a lecture capture folder that just has that years recordings, but to also have a course folder that can be re-used without breaking year on year.

… and of course this has to happen without our staff having to do it manually 500 times per year.

What I’m trying to do is probably best explained in a video. (1 minute)

Warning: This code should not be run on its own. Parent folders must have the permissions of the subfolders or the users will not see it.

The code first part of the code works in a similar way to page 102. The system goes through all of the folders and uses the code from ### to work out how many pages there are and to loop through them all.

I’ve decided that the easiest way to work with all the folders is to make an array up with all the folder names and the matching Guids. working with Folders has a great deal of extra metadata. Making a new Dictionary means we only have to work with two things.

When you define a dictionary you select a key (that needs to be unique, so the Folder Guid works well) and a value (that’s the folder name). For this task we’ll be taking a Blackboard folder


and making a course folder


, which the Blackboard course sits in, and a subject folder


that the course folder sits in.

So to work with all those folders (because only the first time we run the code with the subject and course folders not exist) we need to define the dictionaries

We also need to define how many results per page we will deal with. You should experiment with your own system by using the commands


to time how long the code takes to run. On my system

5 results per page took 80 seconds
50 results per page took 31 seconds
150 results per page took 21 seconds
250 results per page crashed as it returned more than 2MB of data (which we set on page ###)

We loop through the code, and for each folder we use some RegEx to see what the folder is called.

On my system I know that 4 capital letters is a course folder, 4 capital letters followed by 4 numbers is a subject folder and 4 capital letters followed by 4 numbers followed by more characters is a Blackboard course.

So after checking each folder we put it into the corresponding dictionary.

So now we have a dictionary containing all the Blackboard folders, then two for the subject and course codes.

We loop through the Blackboard folders…

For ARCH1001-12345-13-14 we first ask “Is there an ARCH folder?”. To do this we ask if the subject array contains “ARCH”.

If it does then we remember the Guid for the folder, we’ll need it in a minute. If it doesn’t then we need to make a new folder. When a new folder is made it returns a Folder object, so we can use that to find the Guid of the new “ARCH” folder.

Next we do almost exactly the same thing, except this time we are looking for ARCH1001. If we don’t find it in the dictionary we need to make the new folder with a parent folder of the subject above.

If the folder did exist we need to update the parent folder

Finally we know that ARCH1001-12345-13-14 exists, it’s the folder we are dealing with in the loop, so we need to update its parent folder to be what we found (or made) above.

Then we just carry on the loop a couple of hundred times.

I recorded the process of running this code in this video (5 minutes)

Full code below

Return to the Panopto API index page

One Comment

  1. Robynne Blissett

    Hi Graham,

    I have found this post very useful, so thank you! Do you have any advice on how I could go about creating a set of pre-defined folders from a list and batch create them under a parent folder?

    1 year ago

Leave a Reply

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