It’s a(n expiration) date!

Well there are different types of date that one can be part of. This specific one is related to your videos and how you to could easily set and remove a date at some time in future.

Ziggeo is filled with different features, some very easily found. Of course we admin, some not as visible unless you search for them. Today we will write about one such feature that is very simple, available and quite useful.

In some use cases you might want to set when the videos should expire. These could be different types of dates. They could be dates that are connected to your own customers like a date when subscription would stop. Quite an easy way to have the work done by our service and not by yours. In the same time you can still easily manage the subscription or payment interval that your own customer has paid for.

How exactly? Well by setting the date when the videos would expire.

Videos Expiration date

All of the videos within your account can only expire if you set it like so. There are some cases where videos could expire if for example plan you are on is directly set with a time for the videos. For all our standard plans that is not the case.

What we will show you here is a way for you to easily set up a date in future when the video can expire. What will happen then is that our system will automatically detect the time and remove the videos. No further action needed.

  • Of course, please do be mindful that the videos, once removed they can not really be brought back.

The expiration date can be set during recording as well as through the update call afterwards.

What to consider

The way to set the expiration date is by setting the number of days since the video was created when it should be removed. For example if you set 2 videos to expire on the Sunday and one is recorded on Monday and another on Wednesday, they will be set differently.

The Monday one would need to be set to expire in 6 days (Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday). The second one we recorded on Wednesday would need to be set to expire in 4 days instead.

Because of this setting up many videos would require some clever code to calculate this for us.

Once set, you can use the same approach to cancel or update expiration to different date.

The Codes

You can see complete code here: This is Python code, however we will be adding similar example to our other server side SDKs as well.

Bellow we will go through the most important parts of the code, so that you can understand what and why we are doing.

As with all of our server side SDKs the first thing is to initialize our SDK. We can do that by using:

ziggeo = Ziggeo(api_token, private_key)

Now in our demo, we are using Python functionality to ask you for the date you want to insert. You could just as easily modify the code to pass the date in through console. Similar is the case for the api_token and the private_key used above.

Now we need to have our date in a specific format for processing. In Python if you use

global TargetDate 
TargetDate = datetime.datetime.strptime()

You will end up with the date in perfect format, allowing us to easily calculate the difference that we are after.

Now in our code, we also check if the given date is in pass or above the current date. If you are in the past your videos will not really be deleted right away, however midnight comes for our servers and they will be detected. Once detected, the system will remove them almost instantly.

For your own code, you can add such check, or you can decide that it is not important, just be aware what might happen if this happens.

Preparing for update

In our demo we made the update get applied to all videos within the account. To do that, we need to utilize our index API node ziggeo.videos().index().

By default this node will return 50 videos. Since we want to do this quickly, we will change this default “limit” value to 100. The 100 is the limit for the index call, however we have ways to paginate through the videos.

To get the next 100 videos, we would just use the “skip” parameter in the index call to additional 100.

The way that would look is like so:

video_list = ziggeo.videos().index({"limit":100, "skip":skip})

and our video_list now holds all of the videos. The only thing we need to remember is to re-call the index until there are no more videos in our application.

Now for every video that we get, what we want to do is to capture the information when the video was created. This will tell us how many days we need to add to meet the expiration days. And for that in Python, our code looks like so:

CreationDate =["created"]);

The “created” value is Epoch time or Unix Epoch. It looks like a number and it is, it is the number of seconds since the 1st of January 1970. We need to form our date from this string and then we can continue using it as normal.

In case of Python, calculating with dates is very simple, so we just do something like so:

NewExpirationDays = (TargetDate - CreationDate).days

Updating the videos

With the NewExpirationDays retrieved as per above we now have exact number of days that we should add to that specific video. All that is left for us to do is to fill out our expiration_days argument and make the call.

We have 2 options. We can call update per video like so:

arguments["expiration_days"] = expiration_days
print ziggeo.videos().update(video_token, arguments)

Alternatively we can update up to 100 videos at the same time, by supplying a comma separated list of video tokens to the update_bulk function like so:

arguments['tokens_or_keys'] = video_token_list
arguments["expiration_days"] = expiration_days

The first is clean and simple. You make one call for 1 video. Now the second is much more productive in a sense that you make a single call to our server to update 100 videos. For some services or servers that have a limit on bandwidth and those that like to leave smaller footprint, this is the way to go with.

What next?

Well if you came to this point, you got familiar with everything you need in order to start updating your videos and their expiration days. We suggest checking out some other blog posts we have and reaching out to our to let us know your thoughts about this blog post.

Have a feature request? Feel inspired? Well in that case we suggest checking out our as well and leaving your thoughts.

Author: ZiggeoPublished on: 12/20/2021

Related Posts