css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

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

  <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>
            
          
!
            
              /* * 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;
}
            
          
!
            
              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"),
    cms_url = "https://cms.api.brightcove.com/v1/accounts/",
    videoDataDisplay = document.getElementById("videoData"),
    // Dynamic Ingest API stuff
    profilesArray = ['high-resolution', 'screencast-1280', 'single-rendition', 'single-bitrate-high', 'audio-only', 'videocloud-default-v1', 'single-bitrate-standard'],
    di_url_display = document.getElementById("di_url"),
    di_submit_display = document.getElementById("di_Submit"),
    proxyURL = "https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php",
    di_url = 'https://ingest.api.brightcove.com/v1/accounts/',
    response_display = document.getElementById("response"),
    videoData = [],
    requestBody = {},
    totalVideos,
    videoNumber = 0,
    currentJobs = 0,
    t1,
    t2,
    totalIngested = 0,
    defaults = {
      account_id: '57838016001'
    },
    callbacks = ["http://solutions.brightcove.com/bcls/di-api/di-callbacks.php"];

  // is defined
  function isDefined(x) {
    if (x === "" || x === null || x === undefined) {
      return false;
    } else {
      return true;
    }
  }
  // set options for the CMS API request
  function setCMSOptions() {
    var options = {};
    // truncate description if too long
    videoData[videoNumber].description = videoData[videoNumber].description.substr(0, 120) + "...";
    if (isDefined(client_id) && isDefined(client_secret)) {
      options.client_id = client_id;
      options.client_secret = client_secret;
    }
    options.account_id = account_id;
    options.proxyURL = proxyURL;
    requestBody.name = videoData[videoNumber].name;
    requestBody.description = videoData[videoNumber].description;
    requestBody.reference_id = videoData[videoNumber].reference_id;
    requestBody.tags = videoData[videoNumber].tags;
    options.requestBody = JSON.stringify(requestBody);
    options.requestType = "POST";
    options.url = cms_url_display.value;
    // now submit the request
    makeRequest(options, function(response) {
      if (response.indexOf("TIMEOUT") > 0) {
        // videoNumber++;
        t1 = setTimeout(setCMSOptions, 1000);
      } else {
        response = JSON.parse(response);
        di_url_display.value = di_url + account_id + "/videos/" + response.id + "/ingest-requests";
        setDIOptions();
      }
    });
  }
  // set options for the Dynamic Ingest API request
  function setDIOptions() {
    var options = {},
      requestBody = {},
      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;
    }
    if (isDefined(client_id) && isDefined(client_secret)) {
      options.client_id = client_id;
      options.client_secret = client_secret;
    }
    options.account_id = account_id;
    options.proxyURL = proxyURL;
    requestBody.master = {};
    requestBody.master.url = videoData[videoNumber].url;
    requestBody.profile = ingest_profile;
    requestBody.callbacks = callbacks;
    options.requestBody = JSON.stringify(requestBody);
    options.requestType = "POST";
    options.url = di_url_display.value;
    // now submit the request
    makeRequest(options, function(response) {
      response = JSON.parse(response);
      totalIngested++;
      logResponse("totalIngested", totalIngested);
      if (videoNumber < totalVideos - 1) {
        videoNumber++;
        currentJobs++;
        logResponse('Processing video number', videoNumber + 1);
        logResponse('Current jobs: ', currentJobs + 1);
        // 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);
        }
      }
    });
  }
  // function to set the request
  function logResponse(type, data) {
    response_display.textContent += type + ": " + data + ",\n";
  }

  /**
   * send API request to the proxy
   * @param  {Object} options for the request
   * @param  {String} options.url the full API request URL
   * @param  {String="GET","POST","PATCH","PUT","DELETE"} requestData [options.requestType="GET"] HTTP type for the request
   * @param  {String} options.proxyURL proxyURL to send the request to
   * @param  {String} options.client_id client id for the account (default is in the proxy)
   * @param  {String} options.client_secret client secret for the account (default is in the proxy)
   * @param  {JSON} [options.requestBody] Data to be sent in the request body in the form of a JSON string
   * @param  {Function} [callback] callback function that will process the response
   */
  function makeRequest(options, callback) {
    var httpRequest = new XMLHttpRequest(),
      response,
      proxyURL = options.proxyURL,
      // response handler
      getResponse = function() {
        try {
          if (httpRequest.readyState === 4) {
            if (httpRequest.status >= 200 && httpRequest.status < 300) {
              response = httpRequest.responseText;
              // some API requests return '{null}' for empty responses - breaks JSON.parse
              if (response === '{null}') {
                response = null;
              }
              // return the response
              callback(response);
            } else {
              alert('There was a problem with the request. Request returned ' + httpRequest.status);
            }
          }
        } catch (e) {
          alert('Caught Exception: ' + e);
        }
      };
    /**
     * set up request data
     * the proxy used here takes the following request body:
     * JSON.stringify(options)
     */
    // set response handler
    httpRequest.onreadystatechange = getResponse;
    // open the request
    httpRequest.open('POST', proxyURL);
    // set headers if there is a set header line, remove it
    // open and send request
    httpRequest.send(JSON.stringify(options));
  }

  di_submit_display.addEventListener("click", function() {
    var i, now = new Date();
    videoData = JSON.parse(videoDataDisplay.value);
    totalVideos = videoData.length;
    // to insure uniqueness,
    for (i = 0; i < totalVideos; i++) {
      videoData[i].reference_id += "_" + now.toISOString();
    }
    // 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 : null;
    client_secret = isDefined(client_secret_display.value) ? client_secret_display.value : null;
    cms_url_display.value = cms_url + 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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console