示例#1
0
        public static string ToJSON(this RPCRequest jsonRPC)
        {
            Builder rpc = new Builder(",", "{", "}");

            rpc.AppendField("method", jsonRPC.method);
            string parameters = (!jsonRPC.parameters.Equals("null")) ? "{" + jsonRPC.parameters + "}" : "null";

            rpc.AppendObject("params", parameters);
            rpc.AppendObject("id", jsonRPC.id);

            return(rpc.ToString());
        }
        public static string ToJSON(this RPCRequest jsonRPC)
        {
            string rpc = "{\"method\": \"" + jsonRPC.method + "\", \"params\":";

            if (!jsonRPC.parameters.Equals("null"))
            {
                rpc += "{" + jsonRPC.parameters + "}";
            }
            else
            {
                rpc += "null";
            }
            rpc += ", \"id\": " + jsonRPC.id + "}";

            return(rpc);
        }
		/// <summary>
		/// Updates a playlist, specified by playlist id. This method must be called 
		/// using an HTTP POST request and JSON parameters.
		/// </summary>
		/// <param name="playlist">
		/// The metadata for the playlist 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 Playlist object. Populate the videoIds property of the 
		/// playlist, not the videos property. 
		/// </param>
		/// <returns></returns>
		public RPCResponse<BCPlaylist> UpdatePlaylist(BCPlaylist playlist) {

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

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

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

			return rpcr;
		}
		/// <summary>
		/// Deletes a playlist, specified by playlist id.
		/// </summary>
		/// <param name="playlist_id">
		/// the id for the playlist to delete
		/// </param>
		/// <param name="reference_id">
		///	The publisher-assigned reference id of the playlist you'd like to delete.
		/// </param>
		/// <returns>
		/// RPC Response Object
		/// </returns>
		private RPCResponse DeletePlaylist(long playlist_id, string reference_id, bool cascade) {

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

			//add video to the post params
			RPCRequest rpc = new RPCRequest();
			rpc.method = "delete_playlist";
			if (playlist_id > -1) {
				rpc.parameters = "\"playlist_id\": " + playlist_id.ToString();
			} else if (reference_id != null) {
				rpc.parameters = "\"reference_id\": " + reference_id.ToString();
			}
			rpc.parameters += ", \"token\": \"" + Account.WriteToken.Value + "\"";
			rpc.parameters += ", \"cascade\": " + cascade.ToString().ToLower();
			postParams.Add("json", rpc.ToJSON());

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

			return rpcr;
		}
		/// <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>
		/// 
		/// </summary>
		/// <param name="videoId"></param>
		/// <param name="reference_id"></param>
		/// <returns></returns>
		private RPCResponse<BCVideo> RemoveLogoOverlay(long video_id, string video_reference_id) {

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

			//add video to the post params
			RPCRequest rpc = new RPCRequest();
			rpc.method = "remove_logo_overlay";
			if (video_id > -1) {
				rpc.parameters += ",\"video_id\": \"" + video_id.ToString() + "\"";
			} else if (video_reference_id != null) {
				rpc.parameters += ",\"video_reference_id\": \"" + video_reference_id + "\"";
			}
			rpc.parameters += ", \"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;
		}
		/// <summary>
		/// Add a new thumbnail or video still image to a video, or assign an existing image to another video.
		/// </summary>
		/// <param name="image">
		/// The metadata for the image you'd like to create (or update). This takes the form of a 
		/// JSON object of name/value pairs, each of which corresponds to a property of the Image 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="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">
		/// An input stream associated with the image 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 
		/// maxSize parameters are automatically inferred from that file part. 
		/// </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>
		/// <param name="video_id">
		/// The ID of the video you'd like to assign an image to.
		/// </param>
		/// <param name="video_reference_id">
		/// The publisher-assigned reference ID of the video you'd like to assign an image to.
		/// </param>
		/// <param name="resize">
		/// Set this to false if you don't want your image to be automatically resized to the default 
		/// size for its type. By default images will be resized. 
		/// </param>
		/// <returns></returns>
		private RPCResponse<BCImage> AddImage(BCImage image, string filename, byte[] file, long video_id, string video_reference_id, bool resize, 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 = "add_image";
			rpc.parameters = "\"image\": " + image.ToJSON();
			rpc.parameters += ", \"filename\": \"" + filename + "\"";
			if (video_id > -1) {
				rpc.parameters += ",\"video_id\": \"" + video_id.ToString() + "\"";
			} else if (video_reference_id != null) {
				rpc.parameters += ",\"video_reference_id\": \"" + video_reference_id + "\"";
			}
			if (maxsize > -1) {
				rpc.parameters += ", \"maxsize\": \"" + maxsize.ToString() + "\"";
			}

			if (file_checksum != null) {
				rpc.parameters += ", \"file_checksum\": \"" + file_checksum + "\"";
			}
			rpc.parameters += ", \"token\": \"" + Account.WriteToken.Value + "\"";
			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<BCImage> rpcr = BCAPIRequest.ExecuteWrite<BCImage>(postParams, Account);

			return rpcr;
		}
		/// <summary>
		/// Shares the specified video with a list of sharee accounts
		/// </summary>
		/// <param name="video_id">
		/// The id of the video whose status you'd like to get.
		/// </param>
		/// <param name="auto_accept">
		/// If the target account has the option enabled, setting this flag to true will bypass 
		/// the approval process, causing the shared video to automatically appear in the target 
		/// account's library. If the target account does not have the option enabled, or this 
		/// flag is unspecified or false, then the shared video will be queued up to be approved 
		/// by the target account before appearing in their library.	
		/// defaults to false
		/// </param>
		/// <param name="sharee_account_ids">
		/// List of Account IDs to share video with.
		/// </param>
		/// <returns></returns>
		public RPCResponse<BCCollection<long>> ShareVideo(long video_id, bool auto_accept, List<long> sharee_account_ids) {

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

			//add video to the post params
			RPCRequest rpc = new RPCRequest();
			rpc.method = "share_video";
			rpc.parameters = "\"video_id\": " + video_id;
			rpc.parameters += ", \"auto_accept\": " + auto_accept.ToString().ToLower();
			rpc.parameters += ", \"sharee_account_ids\": [";
			for (int i = 0; i < sharee_account_ids.Count; i++) {
				if (i > 0) {
					rpc.parameters += ", ";
				}
				rpc.parameters += "\"" + sharee_account_ids[i].ToString() + "\"";
			}
			rpc.parameters += "]";
			rpc.parameters += ", \"token\": \"" + Account.WriteToken.Value + "\"";
			postParams.Add("json", rpc.ToJSON());

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

			return rpcr;
		}
		/// <summary>
		/// Call this function in an HTTP POST request to determine the status of an upload.
		/// </summary>
		/// <param name="video_id">
		/// The id of the video whose status you'd like to get.
		/// </param>
		/// <param name="reference_id">
		/// The publisher-assigned reference id of the video whose status you'd like to get.
		/// </param>
		/// <returns>
		/// an UploadStatusEnum that specifies the current state of the upload.
		/// </returns>
		private RPCResponse<UploadStatusEnum> GetUploadStatus(long video_id, string reference_id) {

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

			//add video to the post params
			RPCRequest rpc = new RPCRequest();
			rpc.method = "get_upload_status";
			if (video_id > -1) {
				rpc.parameters = "\"video_id\": " + video_id.ToString();
			} else if (reference_id != null) {
				rpc.parameters = "\"reference_id\": " + video_id.ToString();
			}
			rpc.parameters += " ,\"token\": \"" + Account.WriteToken.Value + "\"";

			postParams.Add("json", rpc.ToJSON());

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

			switch (rpcr.result) {
				case "COMPLETE":
					rpcr2.result = UploadStatusEnum.COMPLETE;
					break;
				case "ERROR":
					rpcr2.result = UploadStatusEnum.ERROR;
					break;
				case "PROCESSING":
					rpcr2.result = UploadStatusEnum.PROCESSING;
					break;
				case "UPLOADING":
					rpcr2.result = UploadStatusEnum.UPLOADING;
					break;
				default:
					rpcr2.result = UploadStatusEnum.UNDEFINED;
					break;
			}
			return rpcr2;
		}
示例#10
0
		/// <summary>
		/// Add a logo overlay image to a video. For code examples, see Adding Logo Overlays to Videos with the Media API: http://support.brightcove.com/en/docs/adding-logo-overlays-videos-media-api
		/// </summary>
		/// <param name="logo_overlay">The metadata for the logo overlay you want to create (or update). This takes the form of a JSON object of name/value pairs, each of which corresponds to a property of the LogoOverlay object.</param>
		/// <param name="file_name">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="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">An input stream associated with the image 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 maxsize parameters are automatically inferred from that file part.</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 Video Cloud Media Library is the same as the file you uploaded.</param>
		/// <param name="video_id">The ID of the video you want to assign a logo overlay to. You must specify either a video_id or a video_reference_id.</param>
		/// <param name="video_reference_id">The publisher-assigned reference ID of the video you want to assign a logo overlay to. You must specify either a video_id or a video_reference_id.</param>
		/// <returns>LogoOverlay</returns>
		private RPCResponse<LogoOverlay> AddLogoOverlay(LogoOverlay logo_overlay, string filename, long maxsize, byte[] file, string file_checksum, long video_id, string video_reference_id) {

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

			//add video to the post params
			RPCRequest rpc = new RPCRequest();
			rpc.method = "add_logo_overlay";
			rpc.parameters += ", \"filename\": \"" + filename + "\"";
			if (video_id > -1) {
				rpc.parameters += ",\"video_id\": \"" + video_id.ToString() + "\"";
			} else if (video_reference_id != null) {
				rpc.parameters += ",\"video_reference_id\": \"" + video_reference_id + "\"";
			}
			if (maxsize > -1) {
				rpc.parameters += ", \"maxsize\": \"" + maxsize.ToString() + "\"";
			}

			if (file_checksum != null) {
				rpc.parameters += ", \"file_checksum\": \"" + file_checksum + "\"";
			}
			rpc.parameters += ", \"token\": \"" + Account.WriteToken.Value + "\"";
			postParams.Add("json", rpc.ToJSON());

			//add the file to the post
			if (file != null && !string.IsNullOrEmpty(filename)) {
				postParams.Add("file", new FileParameter(file, filename));
			}
			
			//Get the JSon reader returned from the APIRequest
			RPCResponse<LogoOverlay> rpcr = BCAPIRequest.ExecuteWrite<LogoOverlay>(postParams, Account);

			return rpcr;
		}
示例#11
0
      private RPCResponse DeleteCaptioning(long video_id, string video_reference_id)
      {
			Dictionary<string, object> postParams = new Dictionary<string, object>();

         Builder builder = new Builder()
            .AppendField("token", Account.WriteToken.Value);

         // Either a video_id or video_reference_id is required
         if (video_id > 0)
            builder.Append(",").AppendField("video_id", video_id);
         else if (!string.IsNullOrEmpty(video_reference_id))
            builder.Append(",").AppendField("video_reference_id", video_reference_id);
         else
            throw new System.ArgumentException("A video_id or video_reference_id is required for delete_captioning");

			RPCRequest rpc = new RPCRequest();
			rpc.method = "delete_captioning";
         rpc.parameters = builder.ToString();
			postParams.Add("json", rpc.ToJSON());

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

         return rpcr;
      }
示例#12
0
      /// <summary>
      /// Adds a Captioning to an existing video
      /// http://docs.brightcove.com/en/media/reference.html#Video_Write
      /// The captions can either be uploaded to BC or be referred to by an external url
      /// BrightCove supports the DFXP and SMPTE-TT formats
      /// http://support.brightcove.com/en/docs/using-captions-smart-player-api
      /// </summary>
      /// <param name="caption_source">Metadata about the captions</param>
      /// <param name="options">Parameters (options) including the ID of the video that MUST be set</param>
      /// <param name="captions">a buffer containing DFXP or SMPTE-TT caption data</param>
      /// <returns>the captionSources object</returns>
      public RPCResponse<BCCaptionSources> AddCaptioning(BCCaptionSource caption_source, BCAddCaptioningOptions options, byte[] captions)
      {
			Dictionary<string, object> postParams = new Dictionary<string, object>();

         Builder builder = new Builder()
            .AppendObject("caption_source", caption_source.ToJSON(JSONType.Create))
            .Append(",").AppendField("token", Account.WriteToken.Value);

         if (!string.IsNullOrEmpty(options.filename))
            builder.Append(",").AppendField("filename", options.filename);

         if (options.maxsize > 0)
            builder.Append(",").AppendField("maxsize", options.maxsize);

         if (!string.IsNullOrEmpty(options.file))
            throw new System.ArgumentException("The file property not supported.  Pass the captions in as a byte array.");

         if (!string.IsNullOrEmpty(options.file_checksum))
            builder.Append(",").AppendField("file_checksum", options.file_checksum);

         // Either a video_id or video_reference_id is required
         if (options.video_id > 0)
            builder.Append(",").AppendField("video_id", options.video_id);
         else if (!string.IsNullOrEmpty(options.video_reference_id))
            builder.Append(",").AppendField("video_reference_id", options.video_reference_id);
         else
            throw new System.ArgumentException("A video_id or video_reference_id is required for add_captioning");

			RPCRequest rpc = new RPCRequest();
			rpc.method = "add_captioning";
         rpc.parameters = builder.ToString();
			postParams.Add("json", rpc.ToJSON());

         postParams.Add("file", new UploadBufferParameter(captions, "captions.dfxp"));

			// Get the JSon reader returned from the APIRequest
			// RPCResponse<BCCaptionSources> rpcr = BCAPIRequest.ExecuteWriteFile<BCCaptionSources>(postParams, this.Account, @"C:\dev\svn\BrightCove\TestFormApp\sample_captions.dfxp");
			RPCResponse<BCCaptionSources> rpcr = BCAPIRequest.ExecuteWriteNew<BCCaptionSources>(postParams, this.Account);

         return rpcr;
      }