Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section class="bcls-section" id="video_data">
<h2>Ingesting Videos</h2>
  <h3>Video data</h3>

<p>This script expects a data set as a JSON array of objects like this:</p>

<p>Video data:<textarea id="videoData" class="bcls-code" style="height:20em;">[
    {
        "name": "Woodpecker",
        "description": "A bird that hunts insects inside wood",
        "url": "http://learning-services-media.brightcove.com/videos/mp4/Bird_Woodpecker.mp4",
        "reference_id": "Bird_Woodpecker.mp4",
        "tags": ["bird", "air", "nature"]
    },
    {
        "name": "Chickadee",
        "description": "A small friendly bird",
        "url": "http://learning-services-media.brightcove.com/videos/mp4/Bird_Chickadee.mp4",
        "reference_id": "Bird_Chickadee.mp4",
        "tags": ["bird", "air", "nature"]
    },
    {
        "name": "Great Blue Heron",
        "description": "Pair of great blue herons",
        "url": "http://learning-services-media.brightcove.com/videos/mp4/greatblueheron.mp4",
        "reference_id": "greatblueheron.mp4",
        "tags": ["bird", "air", "nature"]
    },
    {
        "name": "Great Horned Owl",
        "description": "Mother and child owls",
        "url": "http://learning-services-media.brightcove.com/videos/mp4/greathornedowl.mp4",
        "reference_id": "greathornedowl.mp4",
        "tags": ["bird", "air", "nature"]
    }
]</textarea></p>

<p>This is the actual data used in this sample. You could include other metadata fields, but you would need to modify the script a little to send those with the first API call. You'll also notice that these are risky values to use for reference ids, especially for a sample like this that will be run multiple times - but I am getting around the duplication issue by appending the current epoch time in milliseconds to whatever is in the data.</p>

<div class="form-wrapper">
<fieldset class="bcls-fieldset"><legend>Inputs for Dynamic Ingest</legend>

<p>Account: (defaults to Brightcove sample account) <input id="account_id" type="text" value="" name="account_id" /></p>

<p>Client id: (defaults to Brightcove sample account) <input id="client_id" type="text" value="" name="client_id" /></p>

<p>Client secret: (defaults to Brightcove sample account) <input id="client_secret" type="text" value="" name="client_secret" /></p>

<p>Ingest profile: <select id="ingest_profile_display"></select><br />
or Custom Profile: <input id="custom_profile_display" type="text" value="" name="custom_profile_display" /> (you must use the name exactly as it appears in the Video Cloud system, or the request will fail)</p>

  <p><input id="di_Submit" class="bcls-button" type="submit" value="Start Ingest" /></p>
<p>Full request URL for the CMS API call:<br />
<textarea class="bcls-code" name="url" id="cms_url"></textarea> (automatically generated - for information only)</p>

<p>Full request URL for the DI API call:<br />
<textarea class="bcls-code" name="url" id="di_url"></textarea> (automatically generated - for information only)</p>


</fieldset>
</div>
</section>

<section class="bcls-section">
<h2 id="logger">Results Log</h2>

<pre class="line-numbers">
<code id="response" class="language-json">Response will appear here...</code></pre>
</section>
              
            
!

CSS

              
                /* * The body style is just for the
 * background color of the codepen.
 * Do not include in your code.
 */
body {
  background-color: #111;
  color: #f5f5f5;
  font-family: sans-serif;
  margin: 2em;
}
/*
 * Styles essential to the sample
 * are below
 */
.bcls-code {
  color: #111;
  font-family: 'Source Code Pro',monospace;
  padding: 1em;
  width: 90%;
  min-height: 5em;
  background-color: #cfcfcf;
  font-size: 1rem;
}
.bcls-button {
  padding: .5em;
  background-color: #333;
  border: 1px yellow solid;
  border-radius: .5em;
  color: yellow;
  cursor: pointer;
}
fieldset {
  color: #64AAB2;
  border: 1px #64AAB2 solid;
  border-radius: .5em;
}
code {
  color: #E4B842;
  font-family: 'Source Code Pro',monospace;
}
              
            
!

JS

              
                var BCLS = (function(window, document) {
  var // CMS API stuff
    account_id_display = document.getElementById('account_id'),
    account_id,
    client_id_display = document.getElementById('client_id'),
    client_id,
    client_secret_display = document.getElementById('client_secret'),
    client_secret,
    ingest_profile_display = document.getElementById('ingest_profile_display'),
    ingest_profile,
    custom_profile_display = document.getElementById('custom_profile_display'),
    cms_url_display = document.getElementById('cms_url'),
    videoDataDisplay = document.getElementById('videoData'),
    // Dynamic Ingest API stuff
    profilesArray = ['multi-platform-extended-static', 'multi-platform-standard-static'],
    di_url_display = document.getElementById('di_url'),
    di_submit_display = document.getElementById('di_Submit'),
    diURL = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php',
    response = document.getElementById('response'),
    videoData = [],
    totalVideos,
    videoNumber = 0,
    currentJobs = 0,
    t1,
    t2,
    totalIngested = 0,
    defaults = {
      account_id: 57838016001,
      client_id: '37cd3c5d-6f18-4702-bfb6-4fbc1cd095f1',
      client_secret: 'gLSQANqe6A2PzJce_6xA4bTNu844up5-CSrC-jxNfur4EaOgWKRcqq_GTxKjhMpPSflMdNEhFdBmNe0qsTIZSQ'
    },
    callbacks = ["http://solutions.brightcove.com/bcls/dynamic-delivery/di-callbacks.php"];


  // is defined
  function isDefined(x) {
    if (x === '' || x === null || x === undefined) {
      return false;
    }
    return true;
  }
  // set options for the CMS API request
  function setCMSOptions() {
    var options = {},
      reqBody = {};
    // truncate description if too long
    videoData[videoNumber].description = videoData[videoNumber].description.substr(0, 120) + '...';
    options.client_id = client_id;
    options.client_secret = client_secret;
    reqBody.name = videoData[videoNumber].name;
    reqBody.description = videoData[videoNumber].description;
    reqBody.reference_id = videoData[videoNumber].reference_id;
    reqBody.tags = videoData[videoNumber].tags;
    options.requestBody = JSON.stringify(reqBody);
    options.requestType = 'POST';
    options.url = cms_url_display.value;
    // now submit the request
    submitRequest(options, diURL, 'cms');
  }
  // set options for the Dynamic Ingest API request
  function setDIOptions() {
    var options = {},
      reqBody = {};
      custom_profile_display_value = custom_profile_display.value;
    // get the ingest profile
    if (isDefined(custom_profile_display_value)) {
      ingest_profile = custom_profile_display_value;
    } else {
      ingest_profile = ingest_profile_display.options[ingest_profile_display.selectedIndex].value;
    }
    options.client_id = client_id;
    options.client_secret = client_secret;
    reqBody.master = {};
    reqBody.master.url = videoData[videoNumber].url;
    reqBody.profile = ingest_profile;
    reqBody.callbacks = callbacks;
    options.requestBody = JSON.stringify(reqBody);
    options.requestType = 'POST';
    options.url = di_url_display.value;
    // now submit the request
    submitRequest(options, diURL, 'di');
  }
  // function to set the request
  function logResponse(type, data) {
    response.textContent += type + ': ' + data + ',\n';
  }

  // function to submit Request
  function submitRequest(options, proxyURL, type) {
    var httpRequest = new XMLHttpRequest(),
      requestData,
      responseData,
      parsedData,
      getResponse = function() {
        try {
          if (httpRequest.readyState === 4) {
            if (httpRequest.status >= 200 && httpRequest.status < 300) {
              logResponse(type, httpRequest.responseText);
              responseData = httpRequest.responseText;
              switch (type) {
                case 'cms':
                  if (responseData.indexOf('TIMEOUT') > 0) {
                    // videoNumber++;
                    t1 = setTimeout(setCMSOptions, 1000);
                  } else {
                    parsedData = JSON.parse(responseData);
                    di_url_display.value = 'https://ingest.api.brightcove.com/v1/accounts/' + account_id + '/videos/' + parsedData.id + '/ingest-requests';
                    setDIOptions();
                  }
                  break;
                case 'di':
                  totalIngested++;
                  logResponse('totalIngested', totalIngested);
                  if (videoNumber < totalVideos - 1) {
                    videoNumber++;
                    currentJobs++;
                    logResponse('Processing video number', videoNumber);
                    logResponse('Current jobs: ', currentJobs);
                    // if currentJobs is > 99, need to pause
                    if (currentJobs > 99) {
                      // reset currentJobs
                      currentJobs = 0;
                      // wait 30 min before resuming
                      t2 = setTimeout(setCMSOptions, 1800000);
                    } else {
                      // pause to avoid CMS API timeouts
                      t2 = setTimeout(setCMSOptions, 1000);
                    }
                  }
                  break;
              }
            } else {
              alert('There was a problem with the request. Request returned ' + httpRequest.status);
            }
          }
        } catch (e) {
          alert('Caught Exception: ' + e);
        }
      };
    // set up request data
    // set response handler
    httpRequest.onreadystatechange = getResponse;
    // open the request
    httpRequest.open('POST', proxyURL);
    // set headers
    httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    // open and send request
    httpRequest.send(JSON.stringify(options));
  }
  di_submit_display.addEventListener('click', function() {
    var i, now = new Date().valueOf();
    videoData = JSON.parse(videoDataDisplay.value);
    totalVideos = videoData.length;
    // to insure uniqueness,
    for (i = 0; i < totalVideos; i++) {
      videoData[i].reference_id += '_' + now.toString();
    }
    // in case of stop/start, reset videoNumber to 0
    videoNumber = 0;
    // get account inputs
    account_id = isDefined(account_id_display.value) ? account_id_display.value : defaults.account_id;
    client_id = isDefined(client_id_display.value) ? client_id_display.value : defaults.client_id;
    client_secret = isDefined(client_secret_display.value) ? client_secret_display.value : defaults.client_secret;
    cms_url_display.value = 'https://cms.api.brightcove.com/v1/accounts/' + account_id + '/videos';
    // set CMS API options for first video
    setCMSOptions();
  });
  // initialize
  function init() {
    var i,
      iMax = profilesArray.length,
      newOpt;
    // add options for standard ingest profiles
    for (i = 0; i < iMax; i++) {
      newOpt = new Option(profilesArray[i]);
      ingest_profile_display.add(newOpt);
    }
  }
  // call init to set things up
  init();
})(window, document);

              
            
!
999px

Console