diff --git a/.gitignore b/.gitignore index 7e5c4c3e..38677726 100644 --- a/.gitignore +++ b/.gitignore @@ -387,3 +387,9 @@ FodyWeavers.xsd .idea/ *.sln.iml /package.zip + + + +# Brightcove +Brightcove.Web/App_Config/Include/Unicorn/Unicorn.Configs.Brightcove.config + diff --git a/Brightcove.Core/Brightcove.Core.csproj b/Brightcove.Core/Brightcove.Core.csproj index ca68e880..508c665f 100644 --- a/Brightcove.Core/Brightcove.Core.csproj +++ b/Brightcove.Core/Brightcove.Core.csproj @@ -67,6 +67,7 @@ + diff --git a/Brightcove.Core/Models/VideoVariant.cs b/Brightcove.Core/Models/VideoVariant.cs new file mode 100644 index 00000000..834418de --- /dev/null +++ b/Brightcove.Core/Models/VideoVariant.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Brightcove.Core.Models +{ + /// + /// Represents a video object from the Brightcove API + /// For more information, see http://support.brightcove.com/en/video-cloud/docs/media-api-objects-reference#Video + /// + public class VideoVariant + { + [JsonIgnore] + public string Id { get; set; } + + [JsonProperty("language", NullValueHandling = NullValueHandling.Ignore)] + public string Language { get; set; } + + [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + public string Name { get; set; } + + [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + public string Description { get; set; } + + [JsonProperty("long_description", NullValueHandling = NullValueHandling.Ignore)] + public string LongDescription { get; set; } + + [JsonProperty("custom_fields", NullValueHandling = NullValueHandling.Ignore)] + public IDictionary CustomFields { get; set; } + + public VideoVariant ShallowCopy() + { + return (VideoVariant)this.MemberwiseClone(); + } + } +} diff --git a/Brightcove.Core/Services/BrightcoveService.cs b/Brightcove.Core/Services/BrightcoveService.cs index 37531a79..ea180e91 100644 --- a/Brightcove.Core/Services/BrightcoveService.cs +++ b/Brightcove.Core/Services/BrightcoveService.cs @@ -99,6 +99,34 @@ public PlayList CreatePlaylist(string name) return playlist; } + public VideoVariant CreateVideoVariant(string videoId, string videoVariantName, string language) + { + VideoVariant videoVariant = new VideoVariant(); + videoVariant.Language = language; + videoVariant.Name = videoVariantName; + + if (videoId.Contains(",")) + { + throw new ArgumentException("the video ID must not contain any commas", nameof(videoId)); + } + + if (string.IsNullOrWhiteSpace(videoVariantName)) + { + throw new ArgumentException("the video name cannnot be null or empty string", nameof(videoVariantName)); + } + + HttpRequestMessage request = new HttpRequestMessage(); + request.Content = new StringContent(JsonConvert.SerializeObject(videoVariant), Encoding.UTF8, "application/json"); + request.Method = HttpMethod.Post; + request.RequestUri = new Uri($"{cmsBaseUrl}/{accountId}/videos/{videoId}/variants"); + + HttpResponseMessage response = SendRequest(request); + videoVariant = JsonConvert.DeserializeObject(response.Content.ReadAsString()); + videoVariant.Id = videoId; + + return videoVariant; + } + public void DeletePlaylist(string playlistId) { if (string.IsNullOrWhiteSpace(playlistId)) @@ -143,6 +171,28 @@ public void DeleteVideo(string videoId) return; } + public void DeleteVideoVariant(string videoId, string language) + { + if (string.IsNullOrWhiteSpace(videoId)) + { + return; + } + + if (videoId.Contains(",")) + { + throw new ArgumentException("the video ID must not contain any commas", nameof(videoId)); + } + + HttpRequestMessage request = new HttpRequestMessage(); + + request.Method = HttpMethod.Delete; + request.RequestUri = new Uri($"{cmsBaseUrl}/{accountId}/videos/{videoId}/variants/{language}"); + + SendRequest(request); + + return; + } + public Video UpdateVideo(Video video) { HttpRequestMessage request = new HttpRequestMessage(); @@ -164,6 +214,26 @@ public Video UpdateVideo(Video video) return JsonConvert.DeserializeObject