Example #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //remove access filter
            using (new Sitecore.SecurityModel.SecurityDisabler()) {
                using (new EditContext(currentItem.videoItem, true, false)) {
                    currentItem.VideoName        = uvVideo.VideoName;
                    currentItem.ShortDescription = uvVideo.ShortDescription;
                    currentItem.LongDescription  = uvVideo.LongDescription;
                    currentItem.Tags             = uvVideo.Tags;
                    currentItem.ReferenceID      = uvVideo.ReferenceID;
                    currentItem.Economics        = uvVideo.Economics;
                }
            }

            BCVideo v = uvVideo.GetBCVideo();

            v.id = currentItem.VideoID;
            RPCResponse <BCVideo> rpcr = bc.UpdateVideo(v);

            pnlSaveMessage.Visible = true;

            if (rpcr.error.message != null)
            {
                ltlSaveMessage.Text = rpcr.error.code + ": " + rpcr.error.message;
            }
            else
            {
                ltlSaveMessage.Text = "The video settings have been saved to Brightcove Successfully with name: " + rpcr.result.name;
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //build bcvideo
            BCVideo vid = uvVideo.GetBCVideo();

            //upload the video
            RPCResponse <long> rpcr = bc.CreateVideo(vid, uvVideo.FileName, uvVideo.FileBytes);

            if (rpcr.error.message != null)
            {
                ltlMessage.Text = rpcr.error.code + ": " + rpcr.error.message;
            }
            else
            {
                ltlMessage.Text = "Video Created Successfully with ID: " + rpcr.result.ToString();

                vid.id               = rpcr.result;
                vid.creationDate     = DateTime.Now;
                vid.lastModifiedDate = DateTime.Now;
                vid.publishedDate    = DateTime.Now;

                UpdateInsertPair <VideoItem> a = accountItem.ImportToSitecore(vid, UpdateType.NEW);
            }

            //blank out the other fields after upload
            uvVideo.ClearForm();

            //display the current video and playlist count
            ltlTotalVideos.Text = accountItem.VideoLib.Videos.Count.ToString();
        }
Example #3
0
        private static void SetVideoFields(ref Item currentItem, BCVideo vid)
        {
            //Set the appropriate field values for the new item
            currentItem.Fields["Name"].Value = vid.name;
            currentItem.Fields["Short Description"].Value = vid.shortDescription;
            currentItem.Fields["Long Description"].Value  = vid.longDescription;
            currentItem.Fields["Reference Id"].Value      = vid.referenceId;
            currentItem.Fields["Economics"].Value         = vid.economics.ToString();
            currentItem.Fields["ID"].Value                 = vid.id.ToString();
            currentItem.Fields["Creation Date"].Value      = vid.creationDate.ToDateFieldValue();
            currentItem.Fields["Published Date"].Value     = vid.publishedDate.ToDateFieldValue();
            currentItem.Fields["Last Modified Date"].Value = vid.lastModifiedDate.ToDateFieldValue();
            currentItem.Fields["Link URL"].Value           = vid.linkURL;
            currentItem.Fields["Link Text"].Value          = vid.linkText;
            string taglist = "";

            foreach (string tag in vid.tags)
            {
                if (taglist.Length > 0)
                {
                    taglist += ",";
                }
                taglist += tag;
            }
            currentItem.Fields["Tags"].Value                = taglist;
            currentItem.Fields["Video Still URL"].Value     = vid.videoStillURL;
            currentItem.Fields["Thumbnail URL"].Value       = vid.thumbnailURL;
            currentItem.Fields["Length"].Value              = vid.length;
            currentItem.Fields["Plays Total"].Value         = vid.playsTotal.ToString();
            currentItem.Fields["Plays Trailing Week"].Value = vid.playsTrailingWeek.ToString();
        }
Example #4
0
        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);
        }
Example #5
0
        public string GetVideosInPlaylist(string playlistId)
        {
            string     result   = string.Empty;
            BCPlaylist playlist = null;

            string[] selectedVideoList = null;

            try
            {
                if (string.IsNullOrEmpty(playlistId) || (this._playlistId <= 0))
                {
                    selectedVideoList = new string[] { string.Empty };
                }
                else
                {
                    playlist           = this.bcApi.FindPlaylistById(long.Parse(playlistId));
                    this._playlistName = playlist.name;
                    this._playlistType = playlist.playlistType.ToString();
                    this._playlistTags = playlist.filterTags.ToDelimitedString(",");
                    selectedVideoList  = new string[playlist.videos.Count];

                    for (int i = 0; i < playlist.videoIds.Count; i++)
                    {
                        long    video     = playlist.videoIds[i];
                        BCVideo videoData = playlist.videos[i];

                        if (!result.Equals(string.Empty))
                        {
                            result += ",";
                        }

                        result += video.ToString();
                        selectedVideoList[i] = string.Format(@"{{ ""id"":{0}, ""name"":'{1}', ""thumbnailURL"":'{2}' }}",
                                                             videoData.id, videoData.name, videoData.thumbnailURL);
                    }
                }

                this._videoIdList = result;

                string output = string.Format(
                    @"<script language=""javascript"" type=""text/javascript"" charset=""utf-8"">/*<![CDATA[*/
                        var vcPlaylistVideos = [{0}];
                    /*]]>*/</script>", string.Join(",", selectedVideoList));

                message.InnerHtml += output;
            }
            catch
            {
                // Do nothing
            }

            return(result);
        }
Example #6
0
        public BCVideo GetBCVideo()
        {
            BCVideo vid = new BCVideo();

            vid.name             = this.VideoName;
            vid.referenceId      = this.ReferenceID;
            vid.shortDescription = this.ShortDescription;
            vid.longDescription  = this.LongDescription;
            vid.tags             = this.Tags;
            vid.economics        = this.Economics;

            return(vid);
        }
        /// <summary>
        /// Upload a file to your Brightcove account
        /// </summary>
        /// <param name="video">
        /// The metadata for the video you'd like to create. This takes the form of a
        /// JSON object of name/value pairs, each of which corresponds to a settable
        /// property of the Video object.
        /// </param>
        /// <param name="filename">
        /// The name of the file that's being uploaded. You don't need to specify this in
        /// the JSON if it is specified in the file part of the POST.
        /// </param>
        /// <param name="file">
        /// A byte array of the video file you're uploading. This takes the
        /// form of a file part, in a multipart/form-data HTTP request. This input stream and
        /// the filename and maxSide parameters are automatically inferred from that file part.
        /// </param>
        /// <param name="encode_to">
        /// If the file requires transcoding, use this parameter to specify the target encoding. Valid
        /// values are MP4 or FLV, representing the H264 and VP6 codecs respectively. Note that transcoding
        /// of FLV files to another codec is not currently supported. This parameter is optional and defaults to FLV.
        /// </param>
        /// <param name="create_multiple_renditions">
        /// If the file is a supported transcodeable type, this optional flag can be used to control the
        /// number of transcoded renditions. If true (default), multiple renditions at varying encoding
        /// rates and dimensions are created. Setting this to false will cause a single transcoded VP6
        /// rendition to be created at the standard encoding rate and dimensions.
        /// </param>
        /// <param name="H264NoProcessing">
        /// If the video file is H.264 encoded and if create_multiple_ renditions=true, then multiple
        /// VP6 renditions are created and in addition the H.264 source is retained as an additional rendition.
        /// </param>
        /// <param name="preserve_source_rendition">
        /// Use this option to prevent H.264 source files from being transcoded. This parameter cannot be
        /// used in combination with create_multiple_renditions. It is optional and defaults to false.
        /// </param>
        /// <param name="maxsize">
        /// The maximum size that the file will be. This is used as a limiter to know when
        /// something has gone wrong with the upload. The maxSize is same as the file you uploaded.
        /// You don't need to specify this in the JSON if it is specified in the file part of the POST.
        /// </param>
        /// <param name="file_checksum">
        /// An optional MD5 hash of the file. The checksum can be used to verify that the file checked
        /// into your Brightcove Media Library is the same as the file you uploaded.
        /// </param>
        /// <returns>
        /// The id of the video that's been created. if null or error returns -1
        /// </returns>
        private RPCResponse <long> CreateVideo(BCVideo video, string filename, byte[] file, BCEncodeType encode_to, bool create_multiple_renditions, bool H264NoProcessing, bool preserve_source_rendition, long maxsize, string file_checksum)
        {
            // Generate post objects
            Dictionary <string, object> postParams = new Dictionary <string, object>();

            //add video to the post params
            RPCRequest rpc = new RPCRequest();

            rpc.method     = "create_video";
            rpc.parameters = "\"video\": " + video.ToCreateJSON() + ", \"token\": \"" + Account.WriteToken.Value + "\"";
            if (maxsize > -1)
            {
                rpc.parameters += ", \"maxsize\": " + maxsize.ToString();
            }
            if (file_checksum != null)
            {
                rpc.parameters += ", \"file_checksum\": \"" + file_checksum + "\"";
            }
            rpc.parameters += ", \"filename\": \"" + filename + "\"";
            if (!encode_to.Equals(BCEncodeType.UNDEFINED))
            {
                rpc.parameters += ", \"encode_to\": " + encode_to.ToString();
            }
            rpc.parameters += ", \"create_multiple_renditions\": " + create_multiple_renditions.ToString().ToLower();
            rpc.parameters += ", \"H264NoProcessing\": " + H264NoProcessing.ToString().ToLower();
            rpc.parameters += ", \"preserve_source_rendition\": " + preserve_source_rendition.ToString().ToLower();
            postParams.Add("json", rpc.ToJSON());

            //add the file to the post
            postParams.Add("file", new FileParameter(file, filename));

            //Get the JSon reader returned from the APIRequest
            RPCResponse        rpcr  = BCAPIRequest.ExecuteWrite(postParams, this.Account);
            RPCResponse <long> rpcr2 = new RPCResponse <long>();

            rpcr2.error = rpcr.error;
            rpcr2.id    = rpcr.id;
            if (!string.IsNullOrEmpty(rpcr.result))
            {
                rpcr2.result = long.Parse(rpcr.result);
            }
            else
            {
                rpcr2.result = -1;
            }

            return(rpcr2);
        }
        /// <summary>
        /// Updates the video you specify
        /// </summary>
        /// <param name="video">
        /// The metadata for the video you'd like to update. This takes the form of a JSON object of name/value pairs, each of which corresponds to a settable property of the Video object.
        /// </param>
        /// <returns></returns>
        public RPCResponse <BCVideo> UpdateVideo(BCVideo video)
        {
            // Generate post objects
            Dictionary <string, object> postParams = new Dictionary <string, object>();

            //add video to the post params
            RPCRequest rpc = new RPCRequest();

            rpc.method     = "update_video";
            rpc.parameters = "\"video\": " + video.ToJSON() + " ,\"token\": \"" + Account.WriteToken.Value + "\"";
            postParams.Add("json", rpc.ToJSON());

            //Get the JSon reader returned from the APIRequest
            RPCResponse <BCVideo> rpcr = BCAPIRequest.ExecuteWrite <BCVideo>(postParams, Account);

            return(rpcr);
        }
Example #9
0
        /// <summary>
        /// This handles syncing the local info with brightcove
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            pnlUpdateMessage.Visible = true;

            //import/update the video

            BCVideo v = bc.FindVideoById(currentItem.VideoID);
            UpdateInsertPair <VideoItem> vidUIP = accountItem.ImportToSitecore(v, UpdateType.UPDATE);

            //show message over how many things changed
            if (vidUIP.UpdatedItems.Count > 0)
            {
                loadFormWithCurrentValues();
                ltlUpdateMessage.Text = "The settings have been updated from Brightcove.";
            }
            else
            {
                ltlUpdateMessage.Text = "There was a problem updating this video.";
            }
        }
Example #10
0
		private static void SetVideoFields(ref Item currentItem, BCVideo vid) {

			//Set the appropriate field values for the new item
			currentItem.Fields["Name"].Value = vid.name;
			currentItem.Fields["Short Description"].Value = vid.shortDescription;
			currentItem.Fields["Long Description"].Value = vid.longDescription;
			currentItem.Fields["Reference Id"].Value = vid.referenceId;
			currentItem.Fields["Economics"].Value = vid.economics.ToString();
			currentItem.Fields["ID"].Value = vid.id.ToString();
			currentItem.Fields["Creation Date"].Value = vid.creationDate.ToDateFieldValue();
			currentItem.Fields["Published Date"].Value = vid.publishedDate.ToDateFieldValue();
			currentItem.Fields["Last Modified Date"].Value = vid.lastModifiedDate.ToDateFieldValue();
			currentItem.Fields["Link URL"].Value = vid.linkURL;
			currentItem.Fields["Link Text"].Value = vid.linkText;
			string taglist = "";
			foreach (string tag in vid.tags) {
				if (taglist.Length > 0) {
					taglist += ",";
				}
				taglist += tag;
			}
			currentItem.Fields["Tags"].Value = taglist;
			currentItem.Fields["Video Still URL"].Value = vid.videoStillURL;
			currentItem.Fields["Thumbnail URL"].Value = vid.thumbnailURL;
			currentItem.Fields["Length"].Value = vid.length;
			currentItem.Fields["Plays Total"].Value = vid.playsTotal.ToString();
			currentItem.Fields["Plays Trailing Week"].Value = vid.playsTrailingWeek.ToString();
		}
		public RPCResponse<long> CreateVideo(BCVideo video, BCCreateVideoOptions options) {
			return CreateVideo(video, 
            options.filename, options.file, options.encode_to, options.create_multiple_renditions, options.H264NoProcessing, 
            options.preserve_source_rendition, options.maxsize, options.file_checksum, options.fileFullPath);
		}
 public RPCResponse <long> CreateVideo(BCVideo video, string filename, byte[] file, BCEncodeType encode_to, bool create_multiple_renditions, bool preserve_source_rendition)
 {
     return(CreateVideo(video, filename, file, encode_to, create_multiple_renditions, preserve_source_rendition, -1));
 }
		public BCVideo GetBCVideo() {

			BCVideo vid = new BCVideo();
			vid.name = this.VideoName;
			vid.referenceId = this.ReferenceID;
			vid.shortDescription = this.ShortDescription;
			vid.longDescription = this.LongDescription;
			vid.tags = this.Tags;
			vid.economics = this.Economics;

			return vid;
		}
Example #14
0
 public RPCResponse <long> CreateVideo(BCVideo video, string filename)
 {
     return(CreateVideo(video, filename, null));
 }
 public RPCResponse <long> CreateVideo(BCVideo video, string filename, byte[] file, BCEncodeType encode_to)
 {
     return(CreateVideo(video, filename, file, encode_to, false));
 }
Example #16
0
 public RPCResponse <long> CreateVideo(BCVideo video, BCCreateVideoOptions options)
 {
     return(CreateVideo(video,
                        options.filename, options.file, options.encode_to, options.create_multiple_renditions, options.H264NoProcessing,
                        options.preserve_source_rendition, options.maxsize, options.file_checksum, options.fileFullPath));
 }
 //favors no processing renditions
 public RPCResponse <long> CreateVideo(BCVideo video, string filename, byte[] file, bool H264NoProcessing)
 {
     return(CreateVideo(video, filename, file, H264NoProcessing, false));
 }
		public RPCResponse<long> CreateVideo(BCVideo video, string filename, byte[] file, bool H264NoProcessing, bool preserve_source_rendition, long maxsize) {
			return CreateVideo(video, filename, file, H264NoProcessing, preserve_source_rendition, maxsize, null);
		}
		public RPCResponse<long> CreateVideo(BCVideo video, string filename, byte[] file, bool H264NoProcessing, bool preserve_source_rendition, long maxsize, string file_checksum) {
			return CreateVideo(video, filename, file, BCEncodeType.UNDEFINED, false, H264NoProcessing, preserve_source_rendition, maxsize, file_checksum);
		}
		//favors no processing renditions
		public RPCResponse<long> CreateVideo(BCVideo video, string filename, byte[] file, bool H264NoProcessing) {
			return CreateVideo(video, filename, file, H264NoProcessing, false);
		}
		/// <summary>
		/// Updates the video you specify
		/// </summary>
		/// <param name="video">
		/// The metadata for the video you'd like to update. This takes the form of a JSON object of name/value pairs, each of which corresponds to a settable property of the Video object. 
		/// </param>
		/// <returns></returns>
		public RPCResponse<BCVideo> UpdateVideo(BCVideo video) {

			// Generate post objects
			Dictionary<string, object> postParams = new Dictionary<string, object>();

			//add video to the post params
			RPCRequest rpc = new RPCRequest();
			rpc.method = "update_video";
			rpc.parameters = "\"video\": " + video.ToJSON() + " ,\"token\": \"" + Account.WriteToken.Value + "\"";
			postParams.Add("json", rpc.ToJSON());

			//Get the JSon reader returned from the APIRequest
			RPCResponse<BCVideo> rpcr = BCAPIRequest.ExecuteWrite<BCVideo>(postParams, Account);

			return rpcr;
		}
Example #22
0
        private void SetVideo(long videoId)
        {
            if ((videoId > 0) && (this.bcApi != null))
            {
                this.video    = this.bcApi.FindVideoById(videoId, Util.VideoWriteFields);
                this.video.id = videoId;
            }

            if (this.video == null)
            {
                this.video = new BCVideo();
            }

            if (this.IsAdmin && this.IsPostBack)
            {
                this.video                  = new BCVideo();
                this.video.id               = videoId;
                this.video.name             = Request.Form["name"];
                this.video.shortDescription = Request.Form["shortDesc"];
                this.video.longDescription  = Request.Form["longDesc"];

                if (Request.Form["isActive"] == "Yes")
                {
                    this.video.itemState = ItemStateEnum.ACTIVE;
                }
                else if (Request.Form["isActive"] == "No")
                {
                    this.video.itemState = ItemStateEnum.INACTIVE;
                }

                this.video.linkURL       = Request.Form["linkUrl"];
                this.video.linkText      = Request.Form["linkText"];
                this.video.videoStillURL = Request.Form["videoStillUrl"];
                this.video.thumbnailURL  = Request.Form["thumbnailUrl"];
                this.video.referenceId   = Request.Form["referenceId"];
                try { this.video.startDate = BCVideo.DateToUnix(DateTime.Parse(Request.Form["startDate"])); } catch { }
                try { this.video.endDate = BCVideo.DateToUnix(DateTime.Parse(Request.Form["endDate"])); } catch { }

                // Validate start and end dates
                if (!string.IsNullOrEmpty(this.video.startDate) && !string.IsNullOrEmpty(this.video.endDate))
                {
                    if (long.Parse(this.video.startDate) > long.Parse(this.video.endDate))
                    {
                        // Notify user of the validatioin error
                        // TBD
                    }
                }

                // Economics
                if (Request.Form["economics"] == BCVideoEconomics.AD_SUPPORTED.ToString())
                {
                    this.video.economics = BCVideoEconomics.AD_SUPPORTED;
                }
                else if (Request.Form["economics"] == BCVideoEconomics.FREE.ToString())
                {
                    this.video.economics = BCVideoEconomics.FREE;
                }

                // Custom Fields
                if (!string.IsNullOrEmpty(Request.Form["customFields"]))
                {
                    string[] list = Request.Form["customFields"].Split(",".ToCharArray());

                    if (this.video.customFields == null)
                    {
                        this.video.customFields = new CustomFields();
                    }
                    else
                    {
                        this.video.customFields.Values.Clear();
                    }

                    foreach (string item in list)
                    {
                        string[] pair = item.Split(":".ToCharArray());
                        string   key  = pair[0].Trim();

                        if (!key.Equals(string.Empty))
                        {
                            this.video.customFields.Values.Add(key, pair[1].Trim());
                        }
                    }
                }

                // Tags
                if (this.video.tags == null)
                {
                    this.video.tags = new BCCollection <string>();
                }
                else
                {
                    this.video.tags.Clear();
                }

                if (!string.IsNullOrEmpty(Request.Form["tags"]))
                {
                    string[] list = Request.Form["tags"].Split(",".ToCharArray());

                    foreach (string item in list)
                    {
                        if (!item.Equals(string.Empty))
                        {
                            this.video.tags.Add(item.Trim());
                        }
                    }
                }
            }
        }
Example #23
0
		public static UpdateInsertPair<VideoItem> ImportToSitecore(this AccountItem account, BCVideo Video, UpdateType utype) {
			List<BCVideo> Videos = new List<BCVideo>();
			Videos.Add(Video);
			return ImportToSitecore(account, Videos, utype);
		}
 public RPCResponse <long> CreateVideo(BCVideo video, string filename, byte[] file, bool H264NoProcessing, bool preserve_source_rendition, long maxsize, string file_checksum)
 {
     return(CreateVideo(video, filename, file, BCEncodeType.UNDEFINED, false, H264NoProcessing, preserve_source_rendition, maxsize, file_checksum));
 }
		//favors multiple renditions
		public RPCResponse<long> CreateVideo(BCVideo video, string filename, byte[] file) {
			return CreateVideo(video, filename, file, BCEncodeType.UNDEFINED);
		}
Example #26
0
 //favors no processing renditions
 public RPCResponse <long> CreateVideo(BCVideo video)
 {
     return(CreateVideo(video, ""));
 }
		public RPCResponse<long> CreateVideo(BCVideo video, string filename, byte[] file, BCEncodeType encode_to) {
			return CreateVideo(video, filename, file, encode_to, false);
		}
		public RPCResponse<long> CreateVideo(BCVideo video, string filename, byte[] file, BCEncodeType encode_to, bool create_multiple_renditions) {
			return CreateVideo(video, filename, file, encode_to, create_multiple_renditions, false);
		}
 public RPCResponse <long> CreateVideo(BCVideo video, string filename, byte[] file, bool H264NoProcessing, bool preserve_source_rendition, long maxsize)
 {
     return(CreateVideo(video, filename, file, H264NoProcessing, preserve_source_rendition, maxsize, null));
 }
		public RPCResponse<long> CreateVideo(BCVideo video, string filename, byte[] file, BCEncodeType encode_to, bool create_multiple_renditions, bool preserve_source_rendition) {
			return CreateVideo(video, filename, file, encode_to, create_multiple_renditions, preserve_source_rendition, -1);
		}
 //favors multiple renditions
 public RPCResponse <long> CreateVideo(BCVideo video, string filename, byte[] file)
 {
     return(CreateVideo(video, filename, file, BCEncodeType.UNDEFINED));
 }
Example #32
0
        public static UpdateInsertPair <VideoItem> ImportToSitecore(this AccountItem account, BCVideo Video, UpdateType utype)
        {
            List <BCVideo> Videos = new List <BCVideo>();

            Videos.Add(Video);
            return(ImportToSitecore(account, Videos, utype));
        }
 public RPCResponse <long> CreateVideo(BCVideo video, string filename, byte[] file, BCEncodeType encode_to, bool create_multiple_renditions)
 {
     return(CreateVideo(video, filename, file, encode_to, create_multiple_renditions, false));
 }
		//favors no processing renditions
		public RPCResponse<long> CreateVideo(BCVideo video) {
			return CreateVideo(video, "");
		}
 public RPCResponse <long> CreateVideo(BCVideo video, string filename, byte[] file, BCEncodeType encode_to, bool create_multiple_renditions, bool preserve_source_rendition, long maxsize, string file_checksum)
 {
     return(CreateVideo(video, filename, file, encode_to, create_multiple_renditions, false, preserve_source_rendition, maxsize, file_checksum));
 }
        private void SetVideo(long videoId)
        {
            if ( (videoId > 0) && (this.bcApi != null) )
            {
                this.video = this.bcApi.FindVideoById(videoId, Util.VideoWriteFields);
                this.video.id = videoId;
            }

            if (this.video == null)
            {
                this.video = new BCVideo();
            }

            if (this.IsAdmin && this.IsPostBack)
            {
                this.video = new BCVideo();
                this.video.id = videoId;
                this.video.name = Request.Form["name"];
                this.video.shortDescription = Request.Form["shortDesc"];
                this.video.longDescription = Request.Form["longDesc"];

                if (Request.Form["isActive"] == "Yes")
                {
                    this.video.itemState = ItemStateEnum.ACTIVE;
                }
                else if (Request.Form["isActive"] == "No")
                {
                    this.video.itemState = ItemStateEnum.INACTIVE;
                }

                this.video.linkURL = Request.Form["linkUrl"];
                this.video.linkText = Request.Form["linkText"];
                this.video.videoStillURL = Request.Form["videoStillUrl"];
                this.video.thumbnailURL = Request.Form["thumbnailUrl"];
                this.video.referenceId = Request.Form["referenceId"];
                try { this.video.startDate = BCVideo.DateToUnix(DateTime.Parse(Request.Form["startDate"])); } catch { }
                try { this.video.endDate = BCVideo.DateToUnix(DateTime.Parse(Request.Form["endDate"])); } catch { }

                // Validate start and end dates
                if (!string.IsNullOrEmpty(this.video.startDate) && !string.IsNullOrEmpty(this.video.endDate))
                {
                    if (long.Parse(this.video.startDate) > long.Parse(this.video.endDate))
                    {
                        // Notify user of the validatioin error
                        // TBD
                    }
                }

                // Economics
                if (Request.Form["economics"] == BCVideoEconomics.AD_SUPPORTED.ToString())
                {
                    this.video.economics = BCVideoEconomics.AD_SUPPORTED;
                }
                else if (Request.Form["economics"] == BCVideoEconomics.FREE.ToString())
                {
                    this.video.economics = BCVideoEconomics.FREE;
                }

                // Custom Fields
                if (!string.IsNullOrEmpty(Request.Form["customFields"]))
                {
                    string[] list = Request.Form["customFields"].Split(",".ToCharArray());

                    if (this.video.customFields == null)
                    {
                        this.video.customFields = new CustomFields();
                    }
                    else
                    {
                        this.video.customFields.Values.Clear();
                    }

                    foreach (string item in list)
                    {
                        string[] pair = item.Split(":".ToCharArray());
                        string key = pair[0].Trim();

                        if (!key.Equals(string.Empty))
                        {
                            this.video.customFields.Values.Add(key, pair[1].Trim());
                        }
                    }
                }

                // Tags
                if (this.video.tags == null)
                {
                    this.video.tags = new BCCollection<string>();
                }
                else
                {
                    this.video.tags.Clear();
                }

                if (!string.IsNullOrEmpty(Request.Form["tags"]))
                {
                    string[] list = Request.Form["tags"].Split(",".ToCharArray());

                    foreach (string item in list)
                    {
                        if (!item.Equals(string.Empty))
                        {
                            this.video.tags.Add(item.Trim());
                        }
                    }
                }
            }
        }
		public RPCResponse<long> CreateVideo(BCVideo video, string filename, byte[] file, BCEncodeType encode_to, bool create_multiple_renditions, bool preserve_source_rendition, long maxsize, string file_checksum) {
			return CreateVideo(video, filename, file, encode_to, create_multiple_renditions, false, preserve_source_rendition, maxsize, file_checksum);
		}
		public RPCResponse<long> CreateVideo(BCVideo video, string filename) {
			return CreateVideo(video, filename, null);
		}
		/// <summary>
		/// Upload a file to your Brightcove account
		/// </summary>
		/// <param name="video">
		/// The metadata for the video you'd like to create. This takes the form of a 
		/// JSON object of name/value pairs, each of which corresponds to a settable 
		/// property of the Video object.
		/// </param>
		/// <param name="filename">
		/// The name of the file that's being uploaded. You don't need to specify this in 
		/// the JSON if it is specified in the file part of the POST. 
		/// </param>
		/// <param name="file">
		/// A byte array of the video file you're uploading. This takes the 
		/// form of a file part, in a multipart/form-data HTTP request. This input stream and 
		/// the filename and maxSide parameters are automatically inferred from that file part.
		/// </param>
		/// <param name="encode_to">
		/// If the file requires transcoding, use this parameter to specify the target encoding. Valid 
		/// values are MP4 or FLV, representing the H264 and VP6 codecs respectively. Note that transcoding 
		/// of FLV files to another codec is not currently supported. This parameter is optional and defaults to FLV.
		/// </param>
		/// <param name="create_multiple_renditions">
		/// If the file is a supported transcodeable type, this optional flag can be used to control the 
		/// number of transcoded renditions. If true (default), multiple renditions at varying encoding 
		/// rates and dimensions are created. Setting this to false will cause a single transcoded VP6 
		/// rendition to be created at the standard encoding rate and dimensions. 
		/// </param>
		/// <param name="H264NoProcessing">
		/// If the video file is H.264 encoded and if create_multiple_ renditions=true, then multiple 
		/// VP6 renditions are created and in addition the H.264 source is retained as an additional rendition. 
		/// </param>
		/// <param name="preserve_source_rendition">
		/// Use this option to prevent H.264 source files from being transcoded. This parameter cannot be 
		/// used in combination with create_multiple_renditions. It is optional and defaults to false.
		/// </param>
		/// <param name="maxsize">
		/// The maximum size that the file will be. This is used as a limiter to know when 
		/// something has gone wrong with the upload. The maxSize is same as the file you uploaded. 
		/// You don't need to specify this in the JSON if it is specified in the file part of the POST.  
		/// </param>
		/// <param name="file_checksum">
		/// An optional MD5 hash of the file. The checksum can be used to verify that the file checked 
		/// into your Brightcove Media Library is the same as the file you uploaded. 
		/// </param>
		/// <returns>
		/// The id of the video that's been created. if null or error returns -1
		/// </returns>
		private RPCResponse<long> CreateVideo(BCVideo video, string filename, byte[] file, BCEncodeType encode_to, bool create_multiple_renditions, bool H264NoProcessing, bool preserve_source_rendition, long maxsize, string file_checksum) {

			// Generate post objects
			Dictionary<string, object> postParams = new Dictionary<string, object>();

			//add video to the post params
			RPCRequest rpc = new RPCRequest();
			rpc.method = "create_video";
			rpc.parameters = "\"video\": " + video.ToCreateJSON() + ", \"token\": \"" + Account.WriteToken.Value + "\"";
			if (maxsize > -1) {
				rpc.parameters += ", \"maxsize\": " + maxsize.ToString();
			}
			if (file_checksum != null) {
				rpc.parameters += ", \"file_checksum\": \"" + file_checksum + "\"";
			}
			rpc.parameters += ", \"filename\": \"" + filename + "\"";
			if (!encode_to.Equals(BCEncodeType.UNDEFINED)) {
				rpc.parameters += ", \"encode_to\": " + encode_to.ToString();
			}
			rpc.parameters += ", \"create_multiple_renditions\": " + create_multiple_renditions.ToString().ToLower();
			rpc.parameters += ", \"H264NoProcessing\": " + H264NoProcessing.ToString().ToLower();
			rpc.parameters += ", \"preserve_source_rendition\": " + preserve_source_rendition.ToString().ToLower();
			postParams.Add("json", rpc.ToJSON());

			//add the file to the post
			postParams.Add("file", new FileParameter(file, filename));

			//Get the JSon reader returned from the APIRequest
			RPCResponse rpcr = BCAPIRequest.ExecuteWrite(postParams, this.Account);
			RPCResponse<long> rpcr2 = new RPCResponse<long>();
			rpcr2.error = rpcr.error;
			rpcr2.id = rpcr.id;
			if (!string.IsNullOrEmpty(rpcr.result)) {
				rpcr2.result = long.Parse(rpcr.result);
			} else {
				rpcr2.result = -1;
			}

			return rpcr2;
		}
Example #40
0
        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);
        }