This post provides insights into the new features available in Cinegy Convert v11. With powerful pre- and post-scripting events, it is possible to extend your workflow way further beyond the out-of-the-box functionality, for example, automatically publish videos on Facebook on a user’s behalf. Source codes are also available for reference.

Introduction

The idea behind Hacking Cinegy presentations during TechCon 2017 is to demonstrate tips and tricks that can be used to extend the functionality of your products using open Cinegy architecture and APIs. The latest demo showed the following features:

Cinegy Convert Processing Scripts

During the demo, Cinegy Convert’s pre- and post-processing script capabilities are shown to:

  • Generate new metadata as a pre-processing step;

  • Upload a video file to Facebook as a post-processing step.

All sources are available for download on Cinegy GitHub in the Uploading video to Facebook via Convert and Generating TrafficID using Convert pre-processing events sections.

Pre-Processing

Cinegy Convert v11 provides an option to perform additional initialization steps when the task is about to be processed. This allows, for example, scanning source media to generate additional metadata, perform sanity checks, and cancel the task when necessary, etc.

Pre-processing profile

The sample script demonstrates how an operator can access task logs to generate additional informational messages, access already existing metadata, and generate new ones.

The script input parameter provides access to the Cinegy.Media.Linker.Strategies.ScriptOptimizationProvider interface, which is a common access point to other available capabilities. For example, the Cinegy.Logging.ILogger interface is accessible via $provider.Logger. Once logger access is received, additional log messages can be added to the task processing logs via $logger.Info / $logger.Warn / $logger.Error / $logger.Fatal / $logger.Trace calls.

The available metadata can be accessed via $provider.Metadata['<macro>'], where <macro> defines the name of a metadata item to be retrieved, for example, {src.name}. The new metadata generated during the pre-processing script execution can be registered using $provider.AddMetadata(<macro>', $value). Once registered, the new metadata can be referenced, for example, in the profile parameters:

Pre-processing

The demo script shows how to generate new TrafficProgrammId metadata from the source file name, truncating the special substring NRHD when necessary.

Post-Processing

Cinegy Convert v11 provides an option to perform additional steps when the task is completed. This allows you, for example, to move the generated media to another location, send notification messages about new media available, publish media on the web, etc.

The sample script demonstrates how an operator can automatically upload media to Facebook and register a new post on behalf of the selected user.

In order to simplify the demo, the process of receiving the Facebook authorization token for the media upload is left out of scope for the script. Nevertheless, the manual token generation process is described.

Introduction

For an application to publish content on a Facebook user’s behalf, several steps should be performed:

  • application registration;

  • authentication token generation on the user’s behalf;

  • uploading the media using the Facebook SDK.

Application Registration

In order for the application to have access to the Facebook API, it has to be registered with Facebook. To do this, you have to be promoted to the "Facebook developer" role.

Once registered as a developer, you will be able to create applications that can access the Facebook API:

Facebook App

The details of the new application should be specified:

Facebook App Register

Authentication Token

Once the application is created, you can access its details and generate test authentication tokens on the user’s behalf. To do this, use the Access Token Tool from Facebook.

You can generate a user access token with a limited lifetime:

Facebook UAT Limited

Although the default lifetime is limited, for practical purposes, you will have to either renew an access token via API or generate the token with an extended lifetime (30 days):

Facebook UAT Extended

Once the extended user access token is generated, copy the provided data and save it as a Convert-Facebook-AccessToken.txt file in the folder specified in the PowerShell script.

Facebook API

There are a lot of ways to access the Facebook API. In order to simplify the script, we used the Facebook SDK.

Once the NuGet package is downloaded, specify the path to Facebook.dll in the PowerShell script.

Running the Script

When all preliminary steps are done, the rest is very simple. The script just loads a Facebook SDK assembly, creates a Facebook.FacebookClient object to access the API, specifies the previously generated access token, and uploads the media file generated by Cinegy Convert using the $fb.Post("/me/videos", $parameters) call. As simple as that 😊!