Setup: Tenant in O365 with Stream

Problem: How to export a list with all the videos from Microsoft Stream into a CSV. Microsoft does not provide an API for this.

Solution:

Fort this task you need to use a combination of tools: PowerShell and Chrome.

Step1. Load in Chrome the Stream admin https://web.microsoftstream.com/admin?view=Administrators . Inspect the page and find out the api domain. For Europe should be euno-1.api.microsoftstream.com

Step2. Create a list of URLs for JSON extraction of all the videos.
Each URL is like this: https://euno-1.api.microsoftstream.com/api/videos?NoSignUpCheck=1&$top=100&$orderby=publishedDate%20desc&$expand=creator,events&$filter=published%20and%20(state%20eq%20%27Completed%27%20or%20contentSource%20eq%20%27livestream%27)&adminmode=true&api-version=1.4-private&$skip=0
You need to replace the domain with the actual domain from Step1. Copy paste the above URL on a text file, one URL per line, replace skip parameter with a number multiple of 100. Example:

https://euno-1.api.microsoftstream.com/api/videos?NoSignUpCheck=1&...$skip=0
https://euno-1.api.microsoftstream.com/api/videos?NoSignUpCheck=1&...$skip=100
https://euno-1.api.microsoftstream.com/api/videos?NoSignUpCheck=1&...$skip=200
https://euno-1.api.microsoftstream.com/api/videos?NoSignUpCheck=1&...$skip=300

You need to estimate the approximate number of videos in the tenant. For ex: If you have approx. 950 videos, you need 10 lines

Step 3. Add 2 plugins to Chrome:

OpenList (link in Chrome store)

Tab Save (Link in Chrome Store)

Use a fresh Chrome browser. Login to Stream admin page. Open the OpenList plugin and paste the file form Step 2. Chrome will open multiple tabs with the JSON containing the videos list.
With Tab Save you can save all with 1 click on your local computer. Move all the json files in a folder.

Step 4. Import all JSON into PowerShell and export as CSV.

$streamJSONfolder = "C:\path\to\json\files"
Write-host " -----------------------------------------" -ForegroundColor Green
$JSONFiles = Get-ChildItem -Path $streamJSONfolder -Recurse -Include *.json
[int]$videoscounter = 0
[email protected]()
[email protected]()

foreach($fileItem in $JSONFiles)
{
	Write-host " -----------------------------------------" -ForegroundColor Green
	Write-Host "     =====>>>> getting content of JSON File:", $fileItem, "- Path:", $fileItem.FullName -ForegroundColor Yellow
	$Videosjsondata = Get-Content -Raw -Path $fileItem.FullName | ConvertFrom-Json
	$VideosjsonAggregateddata += $Videosjsondata
	Write-host " -----------------------------------------" -ForegroundColor Green
	#Write-Host "     =====>>>> Channel JSON Raw data:", $Videosjsondata -ForegroundColor green
	#Read-Host -Prompt "Press Enter to continue ...."
}

foreach($myVideo in $VideosjsonAggregateddata.value)
{

		$videoscounter += 1
		$datum = New-Object -TypeName PSObject
<# 		Write-host "        -----------------------------------------" -ForegroundColor Green
		Write-Host "        =====>>>> Video (N°", $videoscounter ,") ID:", $myVideo.id -ForegroundColor green
		Write-Host "        =====>>>> Video Name:", $myVideo.name," created:", $myVideo.created,"- modified:", $myVideo.modified -ForegroundColor green
		Write-Host "        =====>>>> Video Metrics views:", $myVideo.metrics.views, "- comments:", $myVideo.metrics.comments -ForegroundColor Magenta
		Write-Host "        =====>>>> Video Creator Name: ", $myVideo.creator.name , " - Email:", $myVideo.creator.mail -ForegroundColor Magenta		
		Write-Host "        =====>>>> Video Description: ", $myVideo.description -ForegroundColor Magenta #>	



		$datum | Add-Member -MemberType NoteProperty -Name VideoID -Value $myVideo.id
		$datum | Add-Member -MemberType NoteProperty -Name VideoName -Value $myVideo.name
		$datum | Add-Member -MemberType NoteProperty -Name VideoURL -Value $($StreamPortalVideoViewRoot + $myVideo.id)
		$datum | Add-Member -MemberType NoteProperty -Name VideoCreatorName -Value $myVideo.creator.name
		$datum | Add-Member -MemberType NoteProperty -Name VideoCreatorEmail -Value $myVideo.creator.mail
        $datum | Add-Member -MemberType NoteProperty -Name VideoCreatorAAD -Value $myVideo.creator.aadstate
		$datum | Add-Member -MemberType NoteProperty -Name VideoCreationDate -Value $myVideo.created
		$datum | Add-Member -MemberType NoteProperty -Name VideoModificationDate -Value $myVideo.modified
		$datum | Add-Member -MemberType NoteProperty -Name VideoViews -Value $myVideo.metrics.views
		$datum | Add-Member -MemberType NoteProperty -Name VideoComments -Value $myVideo.metrics.comments
		$datum | Add-Member -MemberType NoteProperty -Name Videodescription -Value $myVideo.description
		$datum | Add-Member -MemberType NoteProperty -Name Videoduration -Value $myVideo.media.duration

		$data += $datum
	
}

$datestring = (get-date).ToString("yyyyMMdd-hhmm")
$csvfileName = ("c:\temp\" + "\stream_" + $datestring + ".csv")    #<<<< Update this value if you want a different file name 
	
Write-host " -----------------------------------------" -ForegroundColor Green
Write-Host (" >>> writing to file {0}" -f $csvfileName) -ForegroundColor Green
$data | Export-csv $csvfileName -NoTypeInformation
Write-host " -----------------------------------------" -ForegroundColor Green

Leave a Reply

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