Inventory videos from Classic Stream
Overview
As Microsoft announced the The new version of Microsoft Stream, many enterprises started to look at the existing videos from their classic Stream portal and figure out how to coordinate to the new Stream migration. For people who are familiar with migration process, the inventory is the first step when you deal with migration. Currently, when you looked the OOTB reporting capabilities for video inventory perspectives, the classic Stream provided the below approaches.
- Go to Stream Admin->Manager Stream->Usage Details. this option gives you the usage information for entire tenant. it also comes up a percentage how much you used and you can setup a notification when it’s over curtain percentage.
- Go to Stream Admin->Data Privacy-> Manage user data. this option allows you to generate a report for a specific user.
From above approaches, there is no way you can generate a detail inventory report to show who create how many videos at when.
From Tech community, there is post Powershell Script to list ALL videos in your 365 Stream environment which mentioned how to use a PowerShell to communicate undocumented Stream API to retrieve all the videos from classic Stream. Appreciated Dorje McKinnon. It actually gives me some ideas that how we can leverage that API to get all videos.
Solution
The key point for the solution is to use below API:
https://[datacenter-name].api.microsoftstream.com/api/videos?NoSignUpCheck=1&$top=100&$orderby=publishedDate desc&$expand=creator,events&$filter=published and (state eq ‘Completed’ or contentSource eq ‘livestream’)&adminmode=true&api-version=1.4-private&$skip=0
There are a few things we need to figure out:
- Data center name
- Authentication
- How many time we need to call
Let’s look at them one by one
Data Center Name
The Classic Stream is hosting on the Azure platform, there are data center mapped to your tenant. the prefix data center name will be slightly different based on your tenant. you can reference the below steps to get your data center name
- Open up your classic Stream Microsoft Stream and login
- Open up F12 developer tools from your modern browser
- Go to “Network” tab and make sure you checked “Preserve log” option
- Refresh your Stream home page, you will see HTTP traffics shown in your “Network” tab.
- Search for “api.microsoftstream.com”, you will find out your data center prefix as below screenshot. For my tenant, the URL is https://usso-1.api.microsoftstream.com.
Authentication
Since this is undocumented Stream API, we don’t know what authenticaton we can provide. What we can do is to use the browser authentication. In order to do that, I leveraged WebView2 control to access Stream web site. the webView2 control supports .NET Framework windows form application which allows me to host a web page access in my windows application. After authentication, I should be able to use the same authentication cookie to communicate to the Stream API from the browser session.
How many time we need to call
When you looked close to the API, you will see there are multiple query string parameters which we can send to the API endpoint. I leveraged $top and $skip parameters to implement a pagination process. As there is no document for the API, we don’t know how many time we need to call this API. The approach which I used is to call the API by appending the sequence number at the end of the $skip parameter until I got a empty return like below:
{
"value":[
]
}
When I received the above return, it will indicate that there is no more videos coming back.
Implementation
I created a Windows Form application which used webView2 control and implement the following logic:
- Accessed Stream web site to allow a admin user to login
- Called Stream API with a sequence number to enumerate all videos until we receive a empty return.
- Read content from API’s JSON return and append the content to a spreadsheet. For demo purpose, I just retrieved video’s Id, name, description, playbackUrl, duration, creatorName and creatorEmail. you can include more properties from the JSON return.
you can reference the source code from frankchen76 / StreamsInventory. the below is the demo animation.