.NET wrapper for Vippy released

Maris Krivtezs 18.01.2014 16.00.00

More information about Vippy can be found on it's website.

Source code for Vippy wrapper can be found on GitHub.

We published three separate libraries to work with Vippy:

  • VippyWrapper - .NET library for Vippy API
  • VippyModule - EPiServer module for custom Vippy Video page property
  • VippyVpp - EPiServer Virtual Path Provider for Vippy (for EPiServer till version 7.5)

VippyWrapper

To start using the VippyWrapper install it through NuGet into the project.

Install-Package Geta.VippyWrapper

Then create new instance of VippyWrapper class and provide Vippy API key and secret key as constructor parameters.

var wrapper = new VippyWrapper("apikey", "secretkey");
var allVideos = wrapper.GetVideos();

VippyWrapper implements all public endpoints of Vippy:

  • GetTags - gets all archive tags
  • DeleteVideo - deletes the video
  • GetEmbedCode - gets embed code for media
  • GetLogo - gets logo
  • GetLogos - gets all logos
  • GetPlayers - gets all players
  • GetVideo - gets video
  • GetVideoThumbnails - gets video thumbnail for multiple videos
  • GetVideos - gets videos
  • PostVideo - updates video data
  • PutVideo - uploads new video
  • GetPresentation - gets presentation
  • GetPresentations - gets presentations

All methods on VippyWrapper are async. Sample of async MVC controller action:

public async Task<JsonResult> Index()
{
var wrapper = new VippyWrapper("apikey", "secretkey");
var allVideos = await wrapper.GetVideos();
return JsonContent(allVideos);
}

Uploading a new video is quite tricky. Here is an example how to do it:

 var wrapper = new VippyWrapper("apikey", "secretkey");
var file = HttpContext.Current.Request.Files[0];
var fileStream = file.InputStream;
var contentType = file.ContentType;
var filename = file.FileName;

long contentLength;
byte[] data;

using (var memoryStream = new MemoryStream())
{
fileStream.Position = 0;
fileStream.CopyTo(memoryStream);
contentLength = memoryStream.Length;
data = memoryStream.ToArray();
}

var newVideoRequest = new NewVideoRequest
{
Data = data,
ContentLength = contentLength,
Title = Path.GetFileNameWithoutExtension(filename),
VideoPath = filename,
ContentType = contentType
};

var response = wrapper.PutVideo(newVideoRequest);

It is suggested to use IoC container to resolve VippyWrapper.

VippyModule

VippyModule also can be installed through NuGet, but from EPiServer nuget feed. Add this feed URL to visual studion Package Manager sources and run:

Install-Package Geta.VippyModule

It will add new keys into Web.config appSettings section:

<add key="Vippy:ApiKey" value="" />
<add key="Vippy:SecretKey" value="" />
<add key="Vippy:ArchiveNumber" value="" />

Fill in required values for these settings for you Vippy account.

Then in your page type or block type add field with type string and UIHint "vippyvideo":

[ContentType(GUID = "1C48B12A-41F3-4AA0-B1C5-2EDE6C5C1110", 
DisplayName = "Video") ]
public class VideoPage : PageData
{
[UIHint("vippyvideo")]
[Display(Name = "Video")]
public virtual string MainVideo { get; set; }
}

Now in edit mode you will be able to select videos from the autocomplete list.

The value of field will contain Vippy video ID by which you can fetch video embed code using VippyWrapper:

private async Task<IHtmlString> 
GetMainVideoEmbedCode(VideoPage currentPage)
{
if (currentPage.MainVideo == null)
{
return null;
}

return await _vippyWrapper.GetEmbedCode(new GetEmbedCodeRequest
{
VideoId = CurrentPage.MainVideo
});
}

VippyVpp

VippyVpp library is not published as NuGet package, but it's source can be freely used.

Thanks to our customer NHO for letting us open source this module.