Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding API methods for adding captioning files #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -430,18 +430,63 @@ private BrightcoveImage DoAddImage(BrightcoveImage image, FileUploadInfo fileUpl
return RunFilePost<BrightcoveResultContainer<BrightcoveImage>>(parms, fileUploadInfo).Result;
}

#endregion

#region AddLogoOverlay

/// <summary>
/// Adds a logo overlay image to a video.
/// </summary>
/// <param name="logoOverlay">The metadata for the logo overlay you'd like to create (or update).</param>
/// <param name="fileUploadInfo">Information for the file to be uploaded.</param>
/// <param name="videoId">The ID of the video you want to assign a logo overlay to.</param>
/// <returns>The newly created or updated BrightcoveLogoOverlay</returns>
public BrightcoveLogoOverlay AddLogoOverlay(BrightcoveLogoOverlay logoOverlay, FileUploadInfo fileUploadInfo, long videoId)
#endregion

#region AddCaptioning
public void AddCaptioning(string captionFileUrl, long videoId, string filename)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method will allow posting a subtitle file that resides on an external URL

{
string propName;
object propValue;
GetIdValuesForUpload(videoId, null, "video_id", "video_reference_id", out propName, out propValue);

var captionSource = new CaptionSource {
Complete = true,
IsRemote = true,
DisplayName = filename,
Url = captionFileUrl
};

BrightcoveParamCollection parms = CreateWriteParamCollection("add_captioning",
methodParams => {
methodParams.Add(propName, propValue);
methodParams.Add("caption_source", captionSource);
methodParams.Add("filename", filename);
});
RunPost<BrightcoveResultContainer<long>>(parms);
}

public void AddCaptioning(FileUploadInfo captionFileUploadInfo, long videoId, string filename)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this one will rely on us uploading an actual file created from a Stream. This is the way to go for our scenario, since we don't expose our generated captions on Amazon

{
string propName;
object propValue;
GetIdValuesForUpload(videoId, null, "video_id", "video_reference_id", out propName, out propValue);

var captionSource = new CaptionSource {
Complete = true,
IsRemote = false,
DisplayName = filename,
};

BrightcoveParamCollection parms = CreateWriteParamCollection("add_captioning",
methodParams => {
methodParams.Add(propName, propValue);
methodParams.Add("caption_source", captionSource);
methodParams.Add("filename", filename);
});
RunFilePost<BrightcoveResultContainer<long>>(parms, captionFileUploadInfo);
}
#endregion

#region AddLogoOverlay

/// <summary>
/// Adds a logo overlay image to a video.
/// </summary>
/// <param name="logoOverlay">The metadata for the logo overlay you'd like to create (or update).</param>
/// <param name="fileUploadInfo">Information for the file to be uploaded.</param>
/// <param name="videoId">The ID of the video you want to assign a logo overlay to.</param>
/// <returns>The newly created or updated BrightcoveLogoOverlay</returns>
public BrightcoveLogoOverlay AddLogoOverlay(BrightcoveLogoOverlay logoOverlay, FileUploadInfo fileUploadInfo, long videoId)
{
return DoAddLogoOverlay(logoOverlay, fileUploadInfo, videoId, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Model\Items\BrightcoveAudioTrack.cs" />
<Compile Include="Model\Items\BrightcoveItem.cs" />
<Compile Include="Model\Items\BrightcoveVideo.cs" />
<Compile Include="Model\Items\CaptionSource.cs" />
<Compile Include="Serialization\IJavaScriptConvertable.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serialization\BrightcoveItemConverter.cs" />
Expand Down
87 changes: 87 additions & 0 deletions source/BrightcoveOS .NET-MAPI-Wrapper/Model/Items/CaptionSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using BrightcoveMapiWrapper.Serialization;
using BrightcoveMapiWrapper.Util;

namespace BrightcoveMapiWrapper.Model.Items
{
/// <summary>
/// A source that provides captions for a video (metadata)
/// </summary>
public class CaptionSource : BrightcoveItem, IJavaScriptConvertable
{
/// <summary>
/// A Boolean indicating whether a CaptionSource is usable.
/// </summary>
public bool Complete { get; set; }

/// <summary>
/// The name of the caption source, which will be displayed in the Media module.
/// </summary>
public string DisplayName { get; set; }

/// <summary>
/// A number that uniquely identifies this CaptionSource object,
/// assigned by Video Cloud when this object is created.
/// </summary>
public long? Id { get; set; }

/// <summary>
/// A Boolean indicating whether or not this CaptionSource is hosted on a remote server,
/// as opposed to hosted by Brightcove.
/// </summary>
public bool IsRemote { get; set; }

/// <summary>
/// The complete path to the file.
/// </summary>
public string Url { get; set; }

public IDictionary<string, object> Serialize(JavaScriptSerializer serializer)
{
IDictionary<string, object> serialized = new Dictionary<string, object>();

serialized["complete"] = Complete;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is ugly. Yes, it can be resolved with json.net and simple conversion settings, but it was done like this everywhere else, so I followed convention.

serialized["displayName"] = DisplayName;
serialized["id"] = Id ?? 0;
serialized["isRemote"] = IsRemote;
serialized["url"] = Url;

return serialized;
}

public void Deserialize(IDictionary<string, object> 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;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ static BrightcoveSerializerFactory()
new BrightcoveItemConverter<BrightcoveResultContainer<BrightcoveItemCollection<BrightcoveVideo>>>(),
new BrightcoveItemConverter<BrightcoveResultContainer<BrightcoveItemCollection<BrightcoveAudioTrack>>>(),
new BrightcoveItemConverter<BrightcoveResultContainer<BrightcoveItemCollection<BrightcovePlaylist>>>(),
new BrightcoveItemConverter<BrightcoveResultContainer<BrightcoveItemCollection<BrightcoveAudioTrackPlaylist>>>()
new BrightcoveItemConverter<BrightcoveResultContainer<BrightcoveItemCollection<BrightcoveAudioTrackPlaylist>>>(),

// captioning
new BrightcoveItemConverter<CaptionSource>()
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<Compile Include="IntegrationTests\VideoRead\SearchVideosCoreTests.cs" />
<Compile Include="IntegrationTests\VideoRead\SearchVideosUrlConstructionTests.cs" />
<Compile Include="IntegrationTests\VideoRead\VideoReadTestBase.cs" />
<Compile Include="IntegrationTests\VideoWrite\AddCaptioningTest.cs" />
<Compile Include="IntegrationTests\VideoWrite\AddImageTests.cs" />
<Compile Include="IntegrationTests\VideoWrite\AddLogoOverlayTests.cs" />
<Compile Include="IntegrationTests\VideoWrite\CreateVideoTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public static class ApiKeys
/// <summary>
/// Read token taken from Brightcove's media API sample @ http://docs.brightcove.com/en/media/samples/search_videos.html.
/// </summary>
public const string ReadToken = "ZY4Ls9Hq6LCBgleGDTaFRDLWWBC8uoXQun0xEEXtlDUHBDPZBCOzbw..";
public const string ReadToken = "AIe8Zmp7bAq8paSBoLt_-1_jII2yjQ1Yd1yAQxmFK10NcfVmhVhiPQ..";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kish9nine in order to test locally, you can change these values to use your own


/// <summary>
/// Write token taken from Brightcove's media API sample @ http://docs.brightcove.com/en/media/samples/update_video.html.
/// </summary>
public const string WriteToken = "ZY4Ls9Hq6LCBgleGDTaFRDLWWBC8uoXQHkhGuDebKvjFPjHb3iT-4g..";
public const string WriteToken = "AIe8Zmp7bAq8paSBoLt_-1_jII2yjQ1YSMqMTaL8MS2Ins8VYKbJKQ..";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.IO;
using BrightcoveMapiWrapper.Api.Connectors;
using NUnit.Framework;

namespace BrightcoveOS.NET_MAPI_Wrapper.Tests.IntegrationTests.VideoWrite
{
[TestFixture]
public class AddCaptioningTest : VideoWriteTestBase
{
/// <summary>
/// Sample DFXP found here:
/// https://s3-us-west-2.amazonaws.com/public-rev/captions/Example.dfxp
/// </summary>
private readonly string FileToUpload = @"C:\Temp\Example.dfxp";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Change to use an embedded resource


[Test]
public void AddCaptioning_ExternalUrl_VideoId()
{
_api.AddCaptioning(
"https://s3-us-west-2.amazonaws.com/public-rev/captions/Example.dfxp", 4348957026001,
"TestFileName.dfxp");
}

[Test]
public void AddCaptioning_FileUploadInfo_VideoId()
{
using (FileStream fs = File.OpenRead(FileToUpload))
{
var captionFileUplaodInfo = new FileUploadInfo(fs, "TestFileName.dfxp");
_api.AddCaptioning(captionFileUplaodInfo, 4348957026001, "TestFileName.dfxp");
}
}

//TODO: AddCaptioning_ExternalUrl_VideoRefId
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if you were using Video IDs, or VideoRefs. Just implemented VideoIds for simplicity, if you need refs we can do that tomorrow @kish9nine

//TODO: AddCaptioning_FileUploadInfo_VideoRefId
}
}