Tags are awesome, but only if you really give them the attention they deserve. Just like kids (or pets) each one is different and deserves special care. However, what do you do when you have 100s of them? We had this problem with the Kaltura Video Portal and we needed a smarter way for metadata management. While the KMC (Kaltura’s Management Console) provides many robust versatile tools for managing your media and its metadata, simple fields like tags, are managed only at the entry level, while missing the overall-view of your content library.
Tags Editor is a new tool to let you quickly and efficiently add and remove tags from your media entries. What used to be slow and tedious has now been made a painless process. Updating the tags for your videos has never been easier.
To generate the list of tags for the user’s entire media.list there is no choice but to traverse every entry and retrieve its tags. However, doing so without a filter and using a pager to increment the page index will not end well. The server has a hard limit of 10,000 entries when accessing the media.list. A user may in fact have more than 10,000 entries stored but without the proper filters you cannot simply go in order and access all of them using a pager. There is however a way to get around this and it involves a clever use of filters.
As the entries are traversed there are two properties that we keep track of, their creation time and their entry id’s. The page index on the other hand is not used at all. Instead of blindly going through each page, we set a filter that arranges the entries by their createdAt times in descending order. So when a call to the API is made to retrieve 500 entries, it retrieves the 500 newest entries it can find.
So now we’re starting to get somewhere. However, if we were to create a loop, this would just keep giving us the same 500 entries over and over. This is where the filter’s “createdAtLessThanOrEqual” and “idNotIn” fields come into play. Each time the loop iterates, the id of every entry examined is added to a list and we record the entry’s createdAt time as well. That way, the next time the loop iterates, createdAtLessThanOrEqual and idNotIn ensure that the 500 entries being pulled from the server have not been traversed yet. This is much faster than using a pager and gets around the server limitations.
The source code for the tool can be found at our Github page.
Feel free to fork it or suggest new features!
You can view a demo of Tags Editor by clicking the thumbnail above or right here.
Stay tuned for more API best-practices and apps. To learn more now, check out the Kaltura API Documentation Set and subscribe to the Kaltura Newsletter.