Introduction
In this article we will see how we can retrieve videos and related information from the Office 365 video portal with multiple ways. First we will see how we can retrieve all the videos from the portal using content type and also we will see how we can retrieve videos from the portal with multiple filters.
Retrieve All Videos Using Site Content Type ID
The videos are stored on the portal using cloud video content type. At the video library (list level), the cloud video content type will differ for multiple channels. Also this content type will differ on various sites. Video cloud content type is present at site level. The content type id of video cloud will be common for any Office 365 portal. The content type id is 0x010100F3754F12A9B6490D9622A01FE9D8F012. It is 40 digits.
At the library level, the video cloud content type id consists of 74 digits. But the first 40 digits will be common, since the list level video cloud content type is inherited from site level video cloud content type.
Using REST Search API, all the videos present across various channels can be retrieved from the portal in a single call with site level cloud video content type. In the query text, we will pass the content type id by appending '*'. So that all the videos which have the content type starting with the same digits will be retrieved.
The Search API will be,
/_api/search/query?QueryText=%27contenttypeid:0x010100F3754F12A9B6490D9622A01FE9D8F012*%27
The results are based on search indexing. The crawl should run periodically to get the video results. And also the properties retrieved here will be more focused on analytical information with some basic video properties. The information like processing status, video running time, channel information will not be retrieved here.
The following code snippet shows the JQuery Ajax call to get the videos from Office 365 video portal, using REST search API,
- $.ajax({
- url: "/_api/search/query?QueryText=%27contenttypeid:0x010100F3754F12A9B6490D9622A01FE9D8F012*%27",
- type: "GET",
- async: false,
- headers: { "accept": "application/json;odata=verbose" },
- success: function(data){
- var videosInfo = data.d.query.PrimaryQueryResult.RelevantResults;
-
- console.log("Available Videos Count on Channel : " + videosInfo.RowCount);
- var videoResults = videosInfo.Table.Rows.results;
- for(var i = 0; i< videoResults.length; i++){
- console.log("Title : "+videoResults[i].Cells.results[3].Value);
- console.log("Created By : "+videoResults[i].Cells.results[4].Value);
- console.log("Video URL : "+videoResults[i].Cells.results[6].Value);
- }
-
- },
- error: function(data){
- }
- });
The ncessary parameters can be only be retrieved using the selectProperties option in the API. The example looks like,
/_api/search/query?QueryText=%27contenttypeid:0x010100F3754F12A9B6490D9622A01FE9D8F012*%27&selectproperties=%27Title%27
Retrieve Videos using Video and List APIs
The REST Video API used to retrieve the videos from the channel will be,
https://videoportalurl/_api/VideoService/Channels('channelid')/GetAllVideos
Here we will see various ways to filter out the videos from the portal.
The video results here are instant results. More information like processing status, video download URL, owner details, running information, tags, channel and other basic information can be retrieved instantly. Here we can get the required parameters for videos using select parameters. The properties which are retrieved from the operation can be used in the select parameters to retrieve only specific information. For example, in the following example, we have retrieved only the file name and video url using the REST API.
User can apply following use cases for retrieving videos.
- User can get only playable (processed) videos by applying processing status filter. (VideoProcessingStatus:2)
- User can get only incomplete videos by applying the status filter (Not processed). (VideoProcessingStatus:1)
- Filter only videos with the known property values. (AnyProperty:Value)
- Most played videos (Sort Asc/desc using VideoDurationInSeconds)
There are many other scenarios where filter and other parameters can be used to retrieve videos with REST Video API. These filter functionalities are available with REST List API as well.
The API will look like,
https://videoportalurl/_api/VideoService/Channels('channelid')/GetAllVideos?$select=FileName, ServerRelativeUrl,Author&$expand=Author/Name&$filter=VideoProcessingStatus eq 2
or
https://channelsiteURL/_api/web/lists/GetByTitle('Videos')/Items?$filter= VideoProcessingStatus eq 2
Both the above APIs will get the same set of JSON responses, which can be processed and displayed. But the response is different from search API response.
The following code snippet shows the Jquery Ajax call to get the videos present on the specified channel with filters and select parameters, using REST List API:
- $.ajax
- ({
- url: "https://chennal_url/_api/web/lists/GetByTitle('Videos')/Items?$select=Title&$filter=VideoProcessingStatus eq 2",
- type: "GET",
- async: false,
- headers: { "accept": "application/json;odata=verbose" },
- success: function(data){
- if(data.d != null && data.d.results.length > 0){
- var videoResults = data.d.results;
-
-
- for(var i = 0; i< videoResults.length; i++){
- console.log("Title : "+videoResults[i].Title);
- }
- }
-
- },
- error: function(data){
- }
- });
The following code snippet shows the Jquery Ajax call to get the videos present on the specified channel with filters and select parameters, using REST Video API:
- $.ajax({
- url: "https://videoportal_url/_api/VideoService/Channels('channelid')/GetAllVideos?$select=Title&$filter=VideoProcessingStatus eq 2",
- type: "GET",
- async: false,
- headers: { "accept": "application/json;odata=verbose" },
- success: function(data){
- if(data.d != null && data.d.results.length > 0){
- var videoResults = data.d.results;
- for(var i = 0; i< videoResults.length; i++){
- console.log("Title : "+videoResults[i].Title);
- }
- }
-
- },
- error: function(data){
- }
- });
Summary
Thus you have learned how to retrieve video details using REST search, REST video and REST list APIs with filter and select parameters. Also we understood the basic difference in getting the response using various REST API methods.