/// <summary> /// Find all playlists in this account. /// </summary> /// <param name="howMany"> /// Number of videos returned (-1 will return all) defaults to -1 /// </param> /// <param name="sortBy"> /// The field by which to sort (defaults to CREATION_DATE) /// </param> /// <param name="sortOrder"> /// The direction by which to sort (default to DESC) /// </param> /// <param name="video_fields"> /// A comma-separated list of the fields you wish to have populated in the videos contained in the returned object. Passing null populates with all fields. (defaults to all) /// </param> /// <param name="custom_fields"> /// A comma-separated list of the custom fields you wish to have populated in the videos contained in the returned object. Passing null populates with all fields. (defaults to all) /// </param> /// <param name="playlist_fields"> /// A comma-separated list of the fields you wish to have populated in the playlists contained in the returned object. Passing null populates with all fields. /// </param> /// <returns> /// Returns a BCQueryResult item /// </returns> public BCQueryResult FindAllPlaylists(int howMany, BCSortByType sortBy, BCSortOrderType sortOrder, List <VideoFields> video_fields, List <String> custom_fields, List <string> playlist_fields, MediaDeliveryTypeEnum media_delivery) { Dictionary <String, String> reqparams = new Dictionary <string, string>(); //Build the REST parameter list reqparams.Add("command", "find_all_playlists"); reqparams.Add("sort_order", sortOrder.ToString()); reqparams.Add("sort_by", sortBy.ToString()); reqparams.Add("media_delivery", media_delivery.ToString()); if (howMany >= 0) { reqparams.Add("page_size", howMany.ToString()); } if (playlist_fields != null) { reqparams.Add("playlist_fields", Implode(playlist_fields)); } if (video_fields != null) { reqparams.Add("video_fields", video_fields.ToFieldString()); } if (custom_fields != null) { reqparams.Add("custom_fields", Implode(custom_fields)); } BCQueryResult qr = MultipleQueryHandler(reqparams, BCObjectType.playlists, Account); return(qr); }
/// <summary> /// Retrieve multiple playlists based on their publisher-assigned reference ids. /// </summary> /// <param name="reference_ids"> /// The reference ids of the playlists we'd like to retrieve. /// </param> /// <param name="video_fields"> /// A comma-separated list of the fields you wish to have populated in the videos contained in the returned object. Passing null populates with all fields. (defaults to all) /// </param> /// <param name="custom_fields"> /// A comma-separated list of the custom fields you wish to have populated in the videos contained in the returned object. Passing null populates with all fields. (defaults to all) /// </param> /// <param name="playlist_fields"> /// A comma-separated list of the fields you wish to have populated in the playlists contained in the returned object. Passing null populates with all fields. /// </param> /// <returns> /// Returns a BCQueryResult item /// </returns> public BCQueryResult FindPlaylistsByReferenceIds(List <string> reference_ids, List <VideoFields> video_fields, List <string> custom_fields, List <PlaylistFields> playlist_fields, MediaDeliveryTypeEnum media_delivery) { Dictionary <String, String> reqparams = new Dictionary <string, string>(); //Build the REST parameter list reqparams.Add("command", "find_playlists_by_reference_ids"); reqparams.Add("reference_ids", Implode(reference_ids)); reqparams.Add("media_delivery", media_delivery.ToString()); if (playlist_fields != null) { reqparams.Add("playlist_fields", playlist_fields.ToFieldString()); } if (video_fields != null) { reqparams.Add("video_fields", video_fields.ToFieldString()); } if (custom_fields != null) { reqparams.Add("custom_fields", Implode(custom_fields)); } BCQueryResult qr = MultipleQueryHandler(reqparams, BCObjectType.playlists, Account); return(qr); }
/// <summary> /// Given the id of a player, returns all the playlists assigned to that player. /// </summary> /// <param name="player_id"> /// The player id whose playlists we want to return. /// </param> /// <param name="howMany"> /// The number of videos to return (-1 will return all) defaults to -1 /// </param> /// <param name="video_fields"> /// A comma-separated list of the fields you wish to have populated in the videos contained in the returned object. Passing null populates with all fields. (defaults to all) /// </param> /// <param name="custom_fields"> /// A comma-separated list of the custom fields you wish to have populated in the videos contained in the returned object. Passing null populates with all fields. (defaults to all) /// </param> /// <param name="playlist_fields"> /// A comma-separated list of the fields you wish to have populated in the playlists contained in the returned object. Passing null populates with all fields. /// </param> /// <returns> /// Returns a BCQueryResult item /// </returns> public BCQueryResult FindPlaylistsForPlayerId(long player_id, int howMany, List <VideoFields> video_fields, List <string> custom_fields, List <PlaylistFields> playlist_fields, MediaDeliveryTypeEnum media_delivery) { Dictionary <String, String> reqparams = new Dictionary <string, string>(); //Build the REST parameter list reqparams.Add("command", "find_playlists_for_player_id"); reqparams.Add("player_id", player_id.ToString()); reqparams.Add("media_delivery", media_delivery.ToString()); if (howMany >= 0) { reqparams.Add("page_size", howMany.ToString()); } if (playlist_fields != null) { reqparams.Add("playlist_fields", playlist_fields.ToFieldString()); } if (video_fields != null) { reqparams.Add("video_fields", video_fields.ToFieldString()); } if (custom_fields != null) { reqparams.Add("custom_fields", Implode(custom_fields)); } BCQueryResult qr = MultipleQueryHandler(reqparams, BCObjectType.playlists, Account); return(qr); }
private static void MakeRequest(BCQueryResult qr, Dictionary <string, string> reqparams, BCObjectType itemType, BCAccount account) { QueryResultPair qrp = BCAPIRequest.ExecuteRead(reqparams, account); qrp.JsonResult = qrp.JsonResult.Replace("\"items\":", "\"" + itemType.ToString() + "\":"); qr.QueryResults.Add(qrp); qr.Merge(JSON.Converter.Deserialize <BCQueryResult>(qrp.JsonResult)); }
public static string[] GetAllVideos(BCAPI api, int pageNumber, string query) { string[] result = null; if (api != null) { List <BrightcoveSDK.VideoFields> videoSearchFields = new List <VideoFields>(); int itemsPerPage = 50; int itemCount = 0; BCQueryResult videos = null; videoSearchFields.Add(VideoFields.NAME); if (!string.IsNullOrEmpty(query)) { query = query.Trim(); } else { query = string.Empty; } if (query.Length == 0) { videos = api.FindAllVideos(itemsPerPage, BCSortByType.MODIFIED_DATE, BCSortOrderType.DESC, null, null, MediaDeliveryTypeEnum.DEFAULT, pageNumber, true); } else { videos = api.FindVideosByText(query, itemsPerPage, BCSortByType.MODIFIED_DATE, BCSortOrderType.DESC, null, null, MediaDeliveryTypeEnum.DEFAULT, pageNumber, true); } if (videos != null) { itemCount = videos.TotalCount; } result = new string[videos.TotalCount]; for (int i = 0; i < videos.Videos.Count; i++) { BCVideo video = videos.Videos[i]; if (i < itemsPerPage) { result[i] = string.Format(@"{{ ""id"":{0}, ""name"":'{1}', ""thumbnailURL"":'{2}' }}", video.id, Util.FixParam(video.name), Util.FixParam(video.thumbnailURL)); } else { result[i] = "null"; } } } return(result); }
private static BCQueryResult MultipleQueryHandler(Dictionary <String, String> reqparams, BCObjectType itemType, BCAccount account) { //Get the JSon reader returned from the APIRequest BCQueryResult qr = new BCQueryResult(); qr.TotalCount = 0; int defaultPageSize = 100; if (!reqparams.ContainsKey("page_size")) // if page size is not set than set it { reqparams.Add("page_size", defaultPageSize.ToString()); qr.MaxToGet = -1; } else // else parse it { qr.MaxToGet = Convert.ToInt32(reqparams["page_size"]); defaultPageSize = qr.MaxToGet; } MakeRequest(qr, reqparams, itemType, account); if (!reqparams.ContainsKey("page_number")) // if page number is not set then pass make recursive calls { reqparams.Add("page_number", "0"); //make sure you get the correct page num int modifier = (qr.MaxToGet.Equals(-1)) ? qr.TotalCount : qr.MaxToGet; double maxPageNum = (qr.TotalCount > 0) ? Math.Ceiling((double)(modifier / defaultPageSize)) : 0; //if there are more to get move to next page and keep getting them for (int pageNum = 1; pageNum <= maxPageNum; pageNum++) { //update page each iteration reqparams["page_number"] = pageNum.ToString(); MakeRequest(qr, reqparams, itemType, account); } if (itemType.Equals(BCObjectType.videos)) { //trim if specified if (qr.Videos.Count > qr.MaxToGet && !qr.MaxToGet.Equals(-1) && qr.MaxToGet < qr.TotalCount) { List <BCVideo> vidTemp = qr.Videos.GetRange(0, Convert.ToInt32(qr.MaxToGet)); qr.Videos.Clear(); qr.Videos.AddRange(vidTemp); } } } return(qr); }
public static string[] GetAllPlaylists(BCAPI api, int pageNumber, string query) { string[] result = null; if (api != null) { int itemsPerPage = 50; int itemCount = 0; BCQueryResult playlists = null; // Cannot search playlists yet, but in the future use "query" -ACA 9/12/2011 if (!string.IsNullOrEmpty(query)) { query = query.Trim().ToLower(); } else { query = string.Empty; } playlists = api.FindAllPlaylists(itemsPerPage, BCSortByType.MODIFIED_DATE, BCSortOrderType.DESC, null, null, Util.PlaylistBrowseFields, MediaDeliveryTypeEnum.DEFAULT, pageNumber, true); if (playlists != null) { itemCount = playlists.TotalCount; } result = new string[playlists.TotalCount]; for (int i = 0; i < playlists.Playlists.Count; i++) { if (i < itemsPerPage) { BCPlaylist playlist = playlists.Playlists[i]; result[i] = string.Format(@"{{ ""id"":{0}, ""name"":'{1}', ""thumbnailURL"":'{2}' }}", playlist.id, Util.FixParam(playlist.name), Util.FixParam(playlist.thumbnailURL)); } else { result[i] = "null"; } } } return(result.ToArray()); }
public BCQueryResult GetResults(string query) { this._pageNumber = Util.ParseInt(Request.QueryString[Util.PagingKey]); if (this.bcApi != null) { if (string.IsNullOrEmpty(query)) { this.result = this.bcApi.FindAllVideos(this._itemsPerPage, BCSortByType.MODIFIED_DATE, BCSortOrderType.DESC, null, null, MediaDeliveryTypeEnum.DEFAULT, this._pageNumber, true); } else { List <string> customFields = null; if (!string.IsNullOrEmpty(CustomFields)) { string[] fields = CustomFields.Split(",".ToCharArray()); customFields = new List <string>(fields.Length); foreach (string field in fields) { customFields.Add(field); } } //this.result = this.bcApi.SearchVideos(-1, null, Util.GetVideoSearchFields("*" + query + "*"), null, BCSortOrderType.DESC, false, // null, null, MediaDeliveryTypeEnum.DEFAULT); this.result = this.bcApi.FindVideosByText(query, this._itemsPerPage, BCSortByType.MODIFIED_DATE, BCSortOrderType.DESC, null, customFields, MediaDeliveryTypeEnum.DEFAULT, this._pageNumber, true); } if (this.result != null) { this._itemCount = this.result.TotalCount; } } return(this.result); }
public override void Deprecated_Page_Load() { if (this.bcApi == null) { return; } this._changedPlaylist = false; bool isNewPlaylist = false; if (!string.IsNullOrEmpty(Request.Form["playlistId"])) { PlaylistId = Request.Form["playlistId"]; } else if (!string.IsNullOrEmpty(Request.QueryString["playlistid"])) { PlaylistId = Request.QueryString["playlistid"]; } if (!string.IsNullOrEmpty(Request["cancel"])) { Response.Redirect(Request.FilePath); return; } if (this.IsPostBack) { BCPlaylist playlistObj = null; if (string.IsNullOrEmpty(PlaylistId) || (PlaylistId == "0")) { if (!string.IsNullOrEmpty(Request.Form["playlistName"])) { playlistObj = AddPlaylist(); this._changedPlaylist = true; isNewPlaylist = true; } } if (!this.IsAdmin) { message.InnerHtml = "<p class=\"error\">ERROR: user " + this.CurrentUser.LoginName + " is not an administrator</p>"; } if (this.IsAdmin && (this._playlistId > 0)) { if (!string.IsNullOrEmpty(Request.Form["deletePlaylist"])) { RPCResponse response = this.bcApi.DeletePlaylist(this._playlistId); if (response.error.message != null) { message.InnerHtml = "<p class=\"error\">ERROR: " + response.error.message + "</p>"; this._playlistId = 0; } else { this._changedPlaylist = true; } } else if (!string.IsNullOrEmpty(Request.Form["videos"])) { if (!UpdatePlaylist(isNewPlaylist, playlistObj)) { this._playlistId = 0; } this._changedPlaylist = true; } else { this._changedPlaylist = true; } } if (this._changedPlaylist) { Response.Redirect(Request.FilePath + "?close=1"); return; } else { this._videoIdList = GetVideosInPlaylist(PlaylistId); } } else { this._videoIdList = GetVideosInPlaylist(PlaylistId); if (this._playlistId > 0) { return; } } int pageNumber = Util.ParseInt(Request.QueryString[Util.PagingKey]); BCQueryResult result = this.bcApi.FindAllPlaylists(this._itemsPerPage, BCSortByType.MODIFIED_DATE, BCSortOrderType.DESC, null, null, Util.PlaylistBrowseFields, MediaDeliveryTypeEnum.DEFAULT, pageNumber, true); if ((result != null) && (result.Playlists.Count > 0)) { this._itemCount = result.TotalCount; foreach (BCPlaylist item in result.Playlists) { message.InnerHtml += string.Format( @"<div class=""playlistRow"" playlistId=""{0}""> <input type=""checkbox"" value=""{0}"" style=""display:none;"" /> <div class=""thumbnail""><a href=""{8}""><img src=""{7}"" border=""0""/></a></div> <div class=""playlist""> <a href=""{8}"">{1}</a><br /> <span class=""playlistVideoCount"" val=""{3}"">{3}</span> <span class=""playlistType"" val=""{2}"">{6}</span> <span class=""playlistTags"" val=""{4}"">{4}</span> </div><a class=""playlistEdit"" href=""{5}"">Edit</a> </div>", item.id, item.name, item.playlistType.ToString(), item.videos.Count.ToString(), item.filterTags.ToDelimitedString(","), string.Format(this.EditPlaylistLink, item.id), GetPlaylistTypeDisplay(item.playlistType.ToString()), item.thumbnailURL, string.Format(this.PlayVideoLink, item.id)); } message.InnerHtml += Util.GetPaging(pageNumber, this._itemsPerPage, this._itemCount, Request.FilePath); } else { message.InnerHtml += "No playlists"; } }
private static BCQueryResult MultipleQueryHandler(Dictionary <String, String> reqparams, BCObjectType itemType, AccountConfigElement account) { //Get the JSon reader returned from the APIRequest BCQueryResult qr = new BCQueryResult(); qr.TotalCount = 0; try { //set some global request paramameters if (!reqparams.ContainsKey("page_number")) { reqparams.Add("page_number", "0"); } //set if not set or if (!reqparams.ContainsKey("page_size")) { qr.MaxToGet = -1; } else { qr.MaxToGet = Convert.ToInt32(reqparams["page_size"]); } //get initial query double maxPageNum = 0; QueryResultPair qrp = BCAPIRequest.ExecuteRead(reqparams, account); //convert the result for deserialization qrp.JsonResult = qrp.JsonResult.Replace("\"items\":", "\"" + itemType.ToString() + "\":"); qr.QueryResults.Add(qrp); qr.Merge(JSON.Converter.Deserialize <BCQueryResult>(qrp.JsonResult)); //make sure you get the correct page num if (qr.TotalCount > 0) { //if you want all use the total count to calculate the number of pages if (qr.MaxToGet.Equals(-1)) { maxPageNum = Math.Ceiling((double)(qr.TotalCount / 100)); } //or just use the max you want to calculate the number of pages else { maxPageNum = Math.Ceiling((double)(qr.MaxToGet / 100)); } } //if there are more to get move to next page and keep getting them for (int pageNum = 1; pageNum <= maxPageNum; pageNum++) { //update page each iteration reqparams["page_number"] = pageNum.ToString(); QueryResultPair qrp2 = BCAPIRequest.ExecuteRead(reqparams, account); //convert the result for deserialization qrp2.JsonResult = qrp2.JsonResult.Replace("\"items\":", "\"" + itemType.ToString() + "\":"); qr.QueryResults.Add(qrp2); qr.Merge(JSON.Converter.Deserialize <BCQueryResult>(qrp2.JsonResult)); } //sorting on our end if (itemType.Equals(BCObjectType.videos) && reqparams.ContainsKey("sort_by")) { //PUBLISH_DATE, if (reqparams["sort_by"].Equals("PUBLISH_DATE")) { qr.Videos.Sort(BCVideo.PublishDateComparison); } //PLAYS_TOTAL, else if (reqparams["sort_by"].Equals("PLAYS_TOTAL")) { qr.Videos.Sort(BCVideo.TotalPlaysComparison); } //PLAYS_TRAILING_WEEK else if (reqparams["sort_by"].Equals("PLAYS_TRAILING_WEEK")) { qr.Videos.Sort(BCVideo.PlaysTrailingComparison); } //MODIFIED_DATE, else if (reqparams["sort_by"].Equals("MODIFIED_DATE")) { qr.Videos.Sort(BCVideo.ModifiedDateComparison); } //CREATION_DATE, else { qr.Videos.Sort(BCVideo.CreationDateComparison); } //if they want asc if (reqparams["sort_order"].Equals("DESC")) { qr.Videos.Reverse(); } //trim if specified if (qr.Videos.Count > qr.MaxToGet && !qr.MaxToGet.Equals(-1) && qr.MaxToGet < qr.TotalCount) { List <BCVideo> vidTemp = qr.Videos.GetRange(0, Convert.ToInt32(qr.MaxToGet)); qr.Videos.Clear(); qr.Videos.AddRange(vidTemp); } } } catch (Exception ex) { throw new Exception(ex.ToString()); } return(qr); }
public static string[] GetAllPlaylists(BCAPI api, int pageNumber, string query, string order, string sort) { string[] result = null; if (api != null) { int itemsPerPage = 50; int itemCount = 0; BCQueryResult playlists = null; List <BCPlaylist> playListsSorted = new List <BCPlaylist>(); // Cannot search playlists yet, but in the future use "query" -ACA 9/12/2011 if (!string.IsNullOrEmpty(query)) { query = query.Trim().ToLower(); } else { query = string.Empty; } playlists = api.FindAllPlaylists(itemsPerPage, getSort(sort), getOrder(order), null, null, Util.PlaylistBrowseFields, MediaDeliveryTypeEnum.DEFAULT, pageNumber, true); if (sort != null) { if (sort.Equals("display name")) { if (order.Equals("ascending")) { playListsSorted = playlists.Playlists.OrderBy(i => i.name).ToList(); } else { playListsSorted = playlists.Playlists.OrderByDescending(i => i.name).ToList(); } } } if (playListsSorted != null) { if (playListsSorted.Count == 0) { playListsSorted = playlists.Playlists; } } if (playlists != null) { itemCount = playListsSorted.Count; } result = new string[playListsSorted.Count]; for (int i = 0; i < playListsSorted.Count; i++) { if (i < itemsPerPage) { BCPlaylist playlist = playListsSorted[i]; result[i] = string.Format(@"{{ ""id"":{0}, ""name"":'{1}', ""thumbnailURL"":'{2}' }}", playlist.id, Util.FixParam(playlist.name), Util.FixParam(playlist.thumbnailURL)); } else { result[i] = "null"; } } } return(result.ToArray()); }
public static string[] GetAllVideos(BCAPI api, int pageNumber, string query, string order, string sort) { string[] result = null; if (api != null) { List <BrightcoveSDK.VideoFields> videoSearchFields = new List <VideoFields>(); int itemsPerPage = 50; int itemCount = 0; BCQueryResult videos = null; List <BCVideo> videosSorted = new List <BCVideo>(); videoSearchFields.Add(VideoFields.NAME); if (!string.IsNullOrEmpty(query)) { query = query.Trim(); } else { query = string.Empty; } if (query.Length == 0) { videos = api.FindAllVideos(itemsPerPage, getSort(sort), getOrder(order), null, null, MediaDeliveryTypeEnum.DEFAULT, pageNumber, true); } else { videos = api.FindVideosByText(query, itemsPerPage, getSort(sort), getOrder(order), null, null, MediaDeliveryTypeEnum.DEFAULT, pageNumber, true); } if (videos != null) { itemCount = videos.TotalCount; } if (sort != null) { if (sort.Equals("display name")) { if (order.Equals("ascending")) { videosSorted = videos.Videos.OrderBy(i => i.name).ToList(); } else { videosSorted = videos.Videos.OrderByDescending(i => i.name).ToList(); } } } if (videosSorted != null) { if (videosSorted.Count == 0) { videosSorted = videos.Videos; } } result = new string[videosSorted.Count]; for (int i = 0; i < videosSorted.Count; i++) { BCVideo video = videosSorted[i]; if (i < itemsPerPage) { result[i] = string.Format(@"{{ ""id"":{0}, ""name"":'{1}', ""thumbnailURL"":'{2}' }}", video.id, Util.FixParam(video.name), Util.FixParam(video.thumbnailURL)); } else { result[i] = "null"; } } } return(result); }