Showing posts with label RESTVideoAPI. Show all posts
Showing posts with label RESTVideoAPI. Show all posts

Sunday 19 June 2016

Retrieving videos from o365 video portal in multiple ways

In this post, we will see how we can retrieve videos and related information from o365 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 o365 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 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, the 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 has 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:

  1. $.ajax({  
  2.     url: "/_api/search/query?QueryText=%27contenttypeid:0x010100F3754F12A9B6490D9622A01FE9D8F012*%27",  
  3.     type: "GET",  
  4.     async: false,  
  5.     headers: { "accept""application/json;odata=verbose" },  
  6.     success: function(data){  
  7.         var videosInfo = data.d.query.PrimaryQueryResult.RelevantResults;  
  8.           
  9.         console.log("Available Videos Count on Channel : " + videosInfo.RowCount);  
  10.     var videoResults = videosInfo.Table.Rows.results;  
  11.     for(var i = 0; i< videoResults.length; i++){  
  12.         console.log("Title : "+videoResults[i].Cells.results[3].Value);  
  13.         console.log("Created By : "+videoResults[i].Cells.results[4].Value);  
  14.         console.log("Video URL : "+videoResults[i].Cells.results[6].Value);  
  15.     }  
  16.     //Similarly other results can be retrieved and displayed  
  17.     },  
  18.     error: function(data){  
  19.     }  
  20. });  

The necessary parameters can be only be retrieved using selectProperties option in the API. The example looks like, 
/_api/search/query?QueryText=%27contenttypeid:0x010100F3754F12A9B6490D9622A01FE9D8F012*%27&selectproperties=%27Title%27


Retrieve Videos using Video & List APIs:

The REST Video API used to retrieve the videos from 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 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 API will get same set of JSON response, 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:
  1. $.ajax  
  2. ({    
  3.     url: "https://chennal_url/_api/web/lists/GetByTitle('Videos')/Items?$select=Title&$filter=VideoProcessingStatus eq 2",    
  4.     type: "GET",    
  5.     async: false,    
  6.     headers: { "accept""application/json;odata=verbose" },    
  7.     success: function(data){    
  8.         if(data.d != null && data.d.results.length > 0){    
  9.             var videoResults = data.d.results;    
  10.                 
  11.                 
  12.         for(var i = 0; i< videoResults.length; i++){    
  13.             console.log("Title : "+videoResults[i].Title);      
  14.         }    
  15.     }    
  16.     //Similarly other results can be retrieved and displayed    
  17.     },    
  18.     error: function(data){    
  19.     }    
  20. });   
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:
  1. $.ajax({  
  2.     url: "https://videoportal_url/_api/VideoService/Channels('channelid')/GetAllVideos?$select=Title&$filter=VideoProcessingStatus eq 2",  
  3.     type: "GET",  
  4.     async: false,  
  5.     headers: { "accept""application/json;odata=verbose" },  
  6.     success: function(data){  
  7.         if(data.d != null && data.d.results.length > 0){  
  8.             var videoResults = data.d.results;  
  9.             for(var i = 0; i< videoResults.length; i++){  
  10.                 console.log("Title : "+videoResults[i].Title);  
  11.             }  
  12.         }  
  13.         //Similarly other results can be retrieved and displayed  
  14.     },  
  15.     error: function(data){  
  16.     }  
  17. });  

Note: 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.

Thursday 16 June 2016

Retrieve Channels and Videos from Office 365 Video Portal Using REST Video API

In this post, you will learn how to retrieve the video portal information, video channels and videos of respective channel from the Office 365 sites using REST Video APIs (Newly introduced for Video Portal).

Microsoft has introduced new APIs for working with video portal. The hierarchy of information storage will be,
  • Video portal is present in an Office 365 instance.
  • Video Portal consists of channels.
  • Channels in turn consist of many videos.


Retrieve Video Portal Details:


First we will see how we can retrieve video portal URL of the Office 365 site using REST Video API.

The API used to get the video portal information will be “https://siteurl/_api/VideoService.Discover”. The properties which can be accessed from this operation are, Video Site Page URL, Channel Template URL, Player template URL and Video Site URL.

The following code snippet shows the JQuery Ajax call to get the video portal information from the Office 365 site.
  1. $.ajax
  2. ({  
  3.     url: "/_api/VideoService.Discover",  
  4.     type: "GET",  
  5.     headers: { "accept""application/json;odata=verbose" },  
  6.     success: function(data)
  7.     {  
  8.         var videoSiteInfo = data.d;  
  9.         console.log("Video Site Page URL : " + videoSiteInfo.O365VideoPageUrl);  
  10.         console.log("Video Channel URL : " + videoSiteInfo.ChannelUrlTemplate);  
  11.         console.log("Player URL : " + videoSiteInfo.PlayerUrlTemplate);  
  12.         console.log("Video Site URL : " + videoSiteInfo.VideoPortalUrl);          
  13.     },  
  14.     error: function(data){  
  15.     }  
  16. });  


Retrieve Channels:


On the Video portal, you can start creating channels. The channels are used to categorize the videos. Creating channel literally means you are going to create site collections.

To get the channels from the video portal, the video portal URL should be used with REST Video API to pull the information. The REST API URL will be https://videositeurl/_api/VideoService/Channels. Here video site URL is the component which we have identified in the above section.

Next, we will see how we can retrieve information about particular channel. Identify the channel and get the channel id manually or by using the previous operation. The operation will be very similar to the above one. Only difference is Channel id is passed to get the particular channel information.
https://videositeurl/_api/VideoService/Channels('Channel-GUID')

The following code snippet shows the JQuery Ajax call to get the channel details from the Office 365 Video portal.
  1. $.ajax
  2. ({  
  3.     url: "/portals/hub/_api/VideoService/Channels"// Pass Channel id to get particular channel info  
  4.     type: "GET",  
  5.     headers: { "accept""application/json;odata=verbose" },  
  6.     success: function(data)
  7.     {  
  8.     var channelInfo = data.d.results[0]; // First Channel  
  9.         console.log("channel Name : " + channelInfo.Title);  
  10.         console.log("channel URL : " + channelInfo.ServerRelativeUrl);  
  11.       // Similarly other properties can be retrieved
  12.     },  
  13.     error: function(data){  
  14.     }  
  15. });  


Retrieve Videos from Channels: 


Now we will see how we can retrieve videos from a particular channel using REST Video API. With the video portal URL and channel ID identified in the above sections, get the channel videos using below API.
https://videositeurl/_api/VideoService/Channels('Channel-GUID')/Videos

The operation will fetch us all the videos from the channel. Using for each, loop through the result set to get the details of each video. The properties which can be viewed are File name, video url, Author details, video download URL, view count, thumbnail url, duration, video uploaded date and channel details. The following code snippet shows the operation in detail.

Now we will see how we can retrieve particular video detail. This is again similar to the above operation. Once you identify the video id, you can pass it using query to SharePoint along with channel id to get more information about single video. The same set of properties will be retrieved here. The REST Video API will be,
https://videositeurl/_api/VideoService/Channels('Channel-GUID')/Videos('Video-GUID') 

The following code snippet shows the JQuery Ajax call to get the video details of a channel from the Office 365 Video portal.
  1. $.ajax
  2. ({  
  3.     url: "/portals/hub/_api/VideoService/Channels('Channel-GUID')/Videos",  
  4.     type: "GET",  
  5.     async: false,  
  6.     headers: { "accept""application/json;odata=verbose" },  
  7.     success: function(data)
  8.     {  
  9.         var videoInfo = data.d.results[0]; // First Video  
  10.         console.log("Video Name : " + videoInfo.FileName);  
  11.         console.log("Video URL : " + videoInfo.Url);  
  12.     // Similarly other properties can be retrieved  
  13.     },  
  14.     error: function(data){  
  15.     }  
  16. });