microsoft / MK.IO

A .NET client SDK for MediaKind MK.IO

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A .NET client SDK for MediaKind MK.IO

This project is an open source .NET SDK for MediaKind MK.IO. For maximum compatibility, it targets .NET 8.0, .NET Standard 2.0 and .NET Framework 4.6.2.

Link to MK.IO Nuget package.

Usage (C#, .NET)

MK.IO API Token

You need the MK.IO API token mkiotoken to connect to the API.

To do so,

  1. Open a web browser and log into https://mk.io (sign in with Microsoft SSO).
  2. Once you are logged in, open a second tab on the same browser and open this link in the new tab: https://api.mk.io/auth/token/

This should provide you with your user_id and token. Note that this token is valid for 1 year.

Another way to get the token is to use Fiddler when you connect to the MK.IO portal with your browser. It is displayed in the header as x-mkio-token. For example, you should see it on the second REST call to https://api.mk.io/api/ams/mkiosubscriptionname/stats/.

For more information, please read this article.

Supported operations

In the current version, operations are supported for :

  • Assets
  • Streaming endpoints
  • Streaming locators
  • Storage accounts
  • Content key policies
  • Transforms, including with CVQ presets and converter presets
  • Jobs
  • Live events
  • Live outputs
  • Asset filters
  • Account filters
  • Streaming policies

End-to-end sample code

There is a documented end-to-end sample code available in the SampleNet8.0 project, in file SimpleEncodingAndPublishing.cs.

This sample code does the following :

  • upload a mp4 file to a new asset using authentication in the browser (you need contribution role on the storage)
  • create the output asset
  • create/update a transform with MK.IO
  • submit a encoding job with MK.IO anbd wait for its completion
  • create a locator with MK.IO
  • create a streaming endpoint with MK.IO if there is none
  • list the streaming urls and test player urls
  • clean the resources

Run the SampleNet8.10 to execute this sample code.

There is another documented end-to-end sample code for live streaming, in file SimpleLiveStreaming.cs.

Other examples

Here is an example on how to use the SDK to manage assets and streaming endpoints :

using MK.IO;
using MK.IO.Models;

// **********************
// MK.IO Client creation
// **********************

var client = new MKIOClient("mkiosubscriptionname", "mkiotoken");

// get user profile info
var profile = client.Account.GetUserProfile();

// Get subscription stats
var stats = client.Account.GetSubscriptionStats();

// *****************
// asset operations
// *****************

// list assets
var mkioAssets = client.Assets.List();

// list assets with pages, 10 assets per page, sorted by creation date
var mkioAssetsResult = client.Assets.ListAsPage("properties/created desc", null, null, null, 10);
while (true)
{
    // do stuff here using mkioAssetsResult.Results

    if (mkioAssetsResult.NextPageLink == null) break;
    mkioAssetsResult = client.Assets.ListAsPageNext(mkioAssetsResult.NextPageLink);
}

// get asset
var mkasset = client.Assets.Get("myassetname");

// create a first asset, letting MK.IO generates a container name
var newAssetName = MKIOClient.GenerateUniqueName("asset");
var newasset = client.Assets.CreateOrUpdate(newAssetName, null, "storagename", "description of my asset");

// create another asset and use labels to tag it. Container name will be the nae of the asset
var newAssetName2 = MKIOClient.GenerateUniqueName("asset");
var newasset2 = client.Assets.CreateOrUpdate(
    newAssetName,
    newAssetName, // container name
    "storagename",
    "description of asset using labels",
    AssetContainerDeletionPolicyType.Retain,
    null,
    new Dictionary<string, string>() { { "typeAsset", "source" } }
    );

// list assets using labels filtering
var sourceEncodedAssets = client.Assets.List(label: new List<string> { "typeAsset=source" });

// delete created asset
client.Assets.Delete(newsasset.Name);

// get streaming locators for asset
var locatorsAsset = client.Assets.ListStreamingLocators("asset-1b510ee166");

// Get tracks and directory of an asset
var tracksAndDir = client.Assets.ListTracksAndDirListing("asset-ef2058b692");


// ******************************
// Streaming endpoint operations
// ******************************

// get streaming endpoint
var mkse = client.StreamingEndpoints.Get("streamingendpoint1");

// list streaming endpoints
var mkses = client.StreamingEndpoints.List();

// create streaming endpoint
var newSe = client.StreamingEndpoints.Create("streamingendpoint2", "francecentral", new StreamingEndpointProperties
            {
                Description = "my description",
                ScaleUnits = 0,
                CdnEnabled = false,
                Sku = new StreamingEndpointsCurrentSku
                {
                    Name = StreamingEndpointSkuType.Standard
                }
            });

// start, stop, delete streaming endpoint
client.StreamingEndpoints.Start("streamingendpoint1", true);
client.StreamingEndpoints.Stop("streamingendpoint1", true);
client.StreamingEndpoints.Delete("streamingendpoint1");

Additional samples are available :

Async operations are also supported. For example :

// *****************
// asset operations
// *****************

// Retrieve assets with pages for better performances, sorted by names, with a batch of 10 assets in each page
var mkioAssetsResult = await client.Assets.ListAsPageAsync("name desc", null, null, null, 10);
while (true)
{
    // do stuff here using mkioAssetsResult.Results

    if (mkioAssetsResult.NextPageLink == null) break;
    mkioAssetsResult = await client.Assets.ListAsPageNextAsync(mkioAssetsResult.NextPageLink);
}


// ******************************
// Streaming endpoint operations
// ******************************

// get streaming endpoint
var mkse = await client.StreamingEndpoints.GetAsync("streamingendpoint1");

// list streaming endpoints
var mkses = await client.StreamingEndpoints.ListAsync();

// create streaming endpoint
var newSe = await client.StreamingEndpoints.CreateAsync("streamingendpoint2", "francecentral", new StreamingEndpointProperties
            {
                Description = "my description",
                ScaleUnits = 0,
                CdnEnabled = false,
                Sku = new StreamingEndpointsCurrentSku
                {
                    Name = StreamingEndpointSkuType.Standard
                }
            });

// start, stop, delete streaming endpoint
await client.StreamingEndpoints.StartAsync("streamingendpoint1", true);
await client.StreamingEndpoints.StopAsync("streamingendpoint1", true);
await client.StreamingEndpoints.DeleteAsync("streamingendpoint2");

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

About

A .NET client SDK for MediaKind MK.IO

License:MIT License


Languages

Language:C# 99.9%Language:PowerShell 0.1%