From 71ea3b77b405ab50acd224ba02921be6817f43df Mon Sep 17 00:00:00 2001 From: amhed Date: Thu, 23 Jul 2015 11:49:06 -0700 Subject: [PATCH] Support for API method AddCaptioning * Added Sample DFXP file to resources * Addied Captioning Entity (it's the return type for AddCaptioning method) * Added Missing Mappings --- .../Api/BrightcoveApi.video.write.cs | 88 +++++++++++++++--- .../BrightcoveOS .NET-MAPI-Wrapper.csproj | 2 + .../Model/Items/BrightcoveCaptionSource.cs | 90 +++++++++++++++++++ .../Model/Items/BrightcoveCaptioning.cs | 63 +++++++++++++ .../BrightcoveSerializerFactory.cs | 9 +- .../Assets/Sample_CaptionFile.dfxp | 80 +++++++++++++++++ ...rightcoveOS .NET-MAPI-Wrapper.Tests.csproj | 4 + .../VideoWrite/AddCaptioningTest.cs | 53 +++++++++++ 8 files changed, 375 insertions(+), 14 deletions(-) create mode 100644 source/BrightcoveOS .NET-MAPI-Wrapper/Model/Items/BrightcoveCaptionSource.cs create mode 100644 source/BrightcoveOS .NET-MAPI-Wrapper/Model/Items/BrightcoveCaptioning.cs create mode 100644 tests/BrightcoveOS .NET-MAPI-Wrapper.Tests/Assets/Sample_CaptionFile.dfxp create mode 100644 tests/BrightcoveOS .NET-MAPI-Wrapper.Tests/IntegrationTests/VideoWrite/AddCaptioningTest.cs diff --git a/source/BrightcoveOS .NET-MAPI-Wrapper/Api/BrightcoveApi.video.write.cs b/source/BrightcoveOS .NET-MAPI-Wrapper/Api/BrightcoveApi.video.write.cs index e79bc7a..fa2750b 100644 --- a/source/BrightcoveOS .NET-MAPI-Wrapper/Api/BrightcoveApi.video.write.cs +++ b/source/BrightcoveOS .NET-MAPI-Wrapper/Api/BrightcoveApi.video.write.cs @@ -430,18 +430,82 @@ private BrightcoveImage DoAddImage(BrightcoveImage image, FileUploadInfo fileUpl return RunFilePost>(parms, fileUploadInfo).Result; } - #endregion - - #region AddLogoOverlay - - /// - /// Adds a logo overlay image to a video. - /// - /// The metadata for the logo overlay you'd like to create (or update). - /// Information for the file to be uploaded. - /// The ID of the video you want to assign a logo overlay to. - /// The newly created or updated BrightcoveLogoOverlay - public BrightcoveLogoOverlay AddLogoOverlay(BrightcoveLogoOverlay logoOverlay, FileUploadInfo fileUploadInfo, long videoId) + #endregion + + #region AddCaptioning + public BrightcoveCaptioning AddCaptioning(string captionFileUrl, long videoId, string filename) + { + return DoAddCaptioningWithExternalUrl(captionFileUrl, videoId, null, filename); + } + + public BrightcoveCaptioning AddCaptioning(string captionFileUrl, string videoReferenceId, string filename) + { + return DoAddCaptioningWithExternalUrl(captionFileUrl, -1, videoReferenceId, filename); + } + + private BrightcoveCaptioning DoAddCaptioningWithExternalUrl(string captionFileUrl, long videoId, string videoReferenceId, string filename) + { + string propName; + object propValue; + GetIdValuesForUpload(videoId, videoReferenceId, "video_id", "video_reference_id", out propName, out propValue); + + var captionSource = new BrightcoveCaptionSource { + DisplayName = filename, + Url = captionFileUrl + }; + + BrightcoveParamCollection parms = CreateWriteParamCollection("add_captioning", + methodParams => { + methodParams.Add(propName, propValue); + methodParams.Add("caption_source", captionSource); + methodParams.Add("filename", filename); + }); + + return RunPost>(parms).Result; + } + + public BrightcoveCaptioning AddCaptioning(FileUploadInfo captionFileUploadInfo, long videoId, string filename) + { + return DoAddCaptioningWithFileUpload(captionFileUploadInfo, videoId, null, filename); + } + + public BrightcoveCaptioning AddCaptioning(FileUploadInfo captionFileUploadInfo, string videoReferenceId, string filename) + { + return DoAddCaptioningWithFileUpload(captionFileUploadInfo, -1, videoReferenceId, filename); + } + + private BrightcoveCaptioning DoAddCaptioningWithFileUpload(FileUploadInfo captionFileUploadInfo, long videoId, string videoReferenceid, string filename) + { + string propName; + object propValue; + GetIdValuesForUpload(videoId, videoReferenceid, "video_id", "video_reference_id", out propName, out propValue); + + var captionSource = new BrightcoveCaptionSource { + DisplayName = filename, + }; + + BrightcoveParamCollection parms = CreateWriteParamCollection("add_captioning", + methodParams => { + methodParams.Add(propName, propValue); + methodParams.Add("caption_source", captionSource); + methodParams.Add("filename", filename); + }); + + return RunFilePost>(parms, captionFileUploadInfo).Result; + } + + #endregion + + #region AddLogoOverlay + + /// + /// Adds a logo overlay image to a video. + /// + /// The metadata for the logo overlay you'd like to create (or update). + /// Information for the file to be uploaded. + /// The ID of the video you want to assign a logo overlay to. + /// The newly created or updated BrightcoveLogoOverlay + public BrightcoveLogoOverlay AddLogoOverlay(BrightcoveLogoOverlay logoOverlay, FileUploadInfo fileUploadInfo, long videoId) { return DoAddLogoOverlay(logoOverlay, fileUploadInfo, videoId, null); } diff --git a/source/BrightcoveOS .NET-MAPI-Wrapper/BrightcoveOS .NET-MAPI-Wrapper.csproj b/source/BrightcoveOS .NET-MAPI-Wrapper/BrightcoveOS .NET-MAPI-Wrapper.csproj index 7059c9e..fc7064e 100644 --- a/source/BrightcoveOS .NET-MAPI-Wrapper/BrightcoveOS .NET-MAPI-Wrapper.csproj +++ b/source/BrightcoveOS .NET-MAPI-Wrapper/BrightcoveOS .NET-MAPI-Wrapper.csproj @@ -58,8 +58,10 @@ + + diff --git a/source/BrightcoveOS .NET-MAPI-Wrapper/Model/Items/BrightcoveCaptionSource.cs b/source/BrightcoveOS .NET-MAPI-Wrapper/Model/Items/BrightcoveCaptionSource.cs new file mode 100644 index 0000000..2017b87 --- /dev/null +++ b/source/BrightcoveOS .NET-MAPI-Wrapper/Model/Items/BrightcoveCaptionSource.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Web.Script.Serialization; +using BrightcoveMapiWrapper.Serialization; +using BrightcoveMapiWrapper.Util; + +namespace BrightcoveMapiWrapper.Model.Items +{ + /// + /// A source that provides captions for a video + /// + /// + /// See https://docs.brightcove.com/en/video-cloud/media/references/reference.html#CaptionSource + /// + public class BrightcoveCaptionSource : BrightcoveItem, IJavaScriptConvertable + { + /// + /// A number that uniquely identifies this CaptionSource object, + /// assigned by Video Cloud when this object is created. + /// + public long? Id { get; private set; } + + /// + /// A Boolean indicating whether or not this CaptionSource is hosted on a remote server, + /// as opposed to hosted by Brightcove. + /// + public bool IsRemote { get; private set; } + + /// + /// A Boolean indicating whether a CaptionSource is usable. + /// + public bool Complete { get; private set; } + + /// + /// The name of the caption source, which will be displayed in the Media module. + /// + public string DisplayName { get; set; } + + /// + /// The complete path to the file. + /// + public string Url { get; set; } + + public IDictionary Serialize(JavaScriptSerializer serializer) + { + IDictionary serialized = new Dictionary(); + + serialized["complete"] = Complete; + serialized["displayName"] = DisplayName; + serialized["id"] = Id ?? 0; + serialized["isRemote"] = IsRemote; + serialized["url"] = Url; + + return serialized; + } + + public void Deserialize(IDictionary dictionary, JavaScriptSerializer serializer) + { + foreach (string key in dictionary.Keys) + { + switch (key) + { + case "error": + ApiUtil.ThrowIfError(dictionary, key, serializer); + break; + + case "complete": + Complete = Convert.ToBoolean(dictionary[key]); + break; + + case "displayName": + DisplayName = Convert.ToString(dictionary[key]); + break; + + case "id": + Id = Convert.ToInt64(dictionary[key]); + break; + + case "isRemote": + IsRemote = Convert.ToBoolean(dictionary[key]); + break; + + case "url": + Url = Convert.ToString(dictionary[key]); + break; + } + } + } + } +} diff --git a/source/BrightcoveOS .NET-MAPI-Wrapper/Model/Items/BrightcoveCaptioning.cs b/source/BrightcoveOS .NET-MAPI-Wrapper/Model/Items/BrightcoveCaptioning.cs new file mode 100644 index 0000000..4bb4577 --- /dev/null +++ b/source/BrightcoveOS .NET-MAPI-Wrapper/Model/Items/BrightcoveCaptioning.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Web.Script.Serialization; +using BrightcoveMapiWrapper.Serialization; +using BrightcoveMapiWrapper.Util; + +namespace BrightcoveMapiWrapper.Model.Items +{ + /// + /// The Captioning object represents all closed captioning files and metadata assigned to a video. + /// + /// + /// See https://docs.brightcove.com/en/video-cloud/media/references/reference.html#Captioning + /// + public class BrightcoveCaptioning : BrightcoveItem, IJavaScriptConvertable + { + /// + /// A number that uniquely identifies this Captioning object, + /// assigned by VideoCloud when this object is created. + /// + public long? Id { get; set; } + + /// + /// A set of sources which provide caption. + /// Only one CaptionSource is supported at this time. + /// + public ICollection CaptionSources { get; set; } + + public IDictionary Serialize( + JavaScriptSerializer serializer) + { + IDictionary serialized = new Dictionary(); + + serialized["id"] = Id ?? 0; + serialized["captionSources"] = CaptionSources; + + return serialized; + } + + public void Deserialize( + IDictionary dictionary, + JavaScriptSerializer serializer) + { + foreach (string key in dictionary.Keys) + { + switch (key) + { + case "error": + ApiUtil.ThrowIfError(dictionary, key, serializer); + break; + + case "id": + Id = Convert.ToInt64(dictionary[key]); + break; + + case "captionSources": + CaptionSources = serializer.ConvertToType>(dictionary[key]); + break; + } + } + } + } +} diff --git a/source/BrightcoveOS .NET-MAPI-Wrapper/Serialization/BrightcoveSerializerFactory.cs b/source/BrightcoveOS .NET-MAPI-Wrapper/Serialization/BrightcoveSerializerFactory.cs index 25cf1bd..b4814e0 100644 --- a/source/BrightcoveOS .NET-MAPI-Wrapper/Serialization/BrightcoveSerializerFactory.cs +++ b/source/BrightcoveOS .NET-MAPI-Wrapper/Serialization/BrightcoveSerializerFactory.cs @@ -66,8 +66,13 @@ static BrightcoveSerializerFactory() new BrightcoveItemConverter>>(), new BrightcoveItemConverter>>(), new BrightcoveItemConverter>>(), - new BrightcoveItemConverter>>() - }); + new BrightcoveItemConverter>>(), + + // captioning + new BrightcoveItemConverter(), + new BrightcoveItemConverter(), + new BrightcoveItemConverter>(), + }); } /// diff --git a/tests/BrightcoveOS .NET-MAPI-Wrapper.Tests/Assets/Sample_CaptionFile.dfxp b/tests/BrightcoveOS .NET-MAPI-Wrapper.Tests/Assets/Sample_CaptionFile.dfxp new file mode 100644 index 0000000..d031adc --- /dev/null +++ b/tests/BrightcoveOS .NET-MAPI-Wrapper.Tests/Assets/Sample_CaptionFile.dfxp @@ -0,0 +1,80 @@ + + + + +