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>Re-transcoding Videos</h2>
  <h3 id="video_data">Video data</h3>

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

  <p>Video data:<br><textarea id="videoData" class="bcls-code">[
  "5713881996001",
  "5769627110001",
  "4752143002001",
  "5771420485001"
]</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> (profile list will update when you chnage the account id above)</p>
      <p><input id="di_Submit" class="bcls-button" type="submit" value="Start Retranscoding" /></p>
      <p>Full request URL for the API call:<br />
        <textarea class="bcls-code" name="url" id="di_url" style="min-height:2em;"></textarea> (automatically generated - for information only)</p>
      <p>API response:<br />
        <textarea class="bcls-code" name="url" id="api_response" style="min-height:2em;"></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...<br> </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 // Ingest Profiles 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,
    videoDataDisplay = document.getElementById("videoData"),
    current_profiles = [],
    live_profiles = ['Live - Standard', 'Live - HD', 'Live - Premium HD'],
    // Dynamic Ingest API stuff
    profilesArray = [
      "multi-platform-extended-static",
      "multi-platform-standard-static"
    ],
    di_url = "https://ingest.api.brightcove.com/v1/accounts/",
    di_url_display = document.getElementById("di_url"),
    di_submit_display = document.getElementById("di_Submit"),
    api_response_display = document.getElementById('api_response'),
    proxyURL =
      "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
    },
    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;
  }

  /**
   * tests to see if a string is json
   * @param {String} str string to test
   * @return {Boolean}
   */
  function isJson(str) {
      try {
          JSON.parse(str);
      } catch (e) {
          return false;
      }
      return true;
  }



  /**
   * determines whether specified item is in an array
   *
   * @param {array} array to check
   * @param {string} item to check for
   * @return {boolean} true if item is in the array, else false
   */
  function arrayContains(arr, item) {
      var i,
          iMax = arr.length;
      for (i = 0; i < iMax; i++) {
          if (arr[i] === item) {
              return true;
          }
      }
      return false;
  }

  /**
   * find index of an object in array of objects
   * based on some property value
   *
   * @param {array} targetArray array to search
   * @param {string} objProperty object property to search
   * @param {string} value of the property to search for
   * @return {integer} index of first instance if found, otherwise returns -1
  */
  function findObjectInArray(targetArray, objProperty, value) {
      var i, totalItems = targetArray.length, objFound = false;
      for (i = 0; i < totalItems; i++) {
          if (targetArray[i][objProperty] === value) {
              objFound = true;
              return i;
          }
      }
      if (objFound === false) {
          return -1;
      }
  }

/**
 * remove or add obsolete profiles from the current profiles list
 */
  function toggleObsoleteProfiles() {
    // below are the obsolete profiles - you just have to know their names
    var deprecated_profiles = ['balanced-nextgen-player', 'Express Standard', 'mp4-only', 'balanced-high-definition', 'low-bandwidth-devices', 'balanced-standard-definition', 'single-rendition', 'Live - Standard', 'high-bandwidth-devices', 'Live - Premium HD', 'Live - HD', 'videocloud-default-trial', 'screencast'];
      i = current_profiles.length;
      while (i > 0) {
        i--;
        if (arrayContains(deprecated_profiles, current_profiles[i].name)) {
          current_profiles.splice(i, 1);
        }
    }
    return;
  }

  /**
   * displays the filtered list of profiles
   */
  function displayFilteredProfiles() {
    var option,
      fragment = document.createDocumentFragment(),
      i,
      iMax;
    iMax = current_profiles.length;
    for (i = 0; i < iMax; i++) {
      option = document.createElement('option');
      option.textContent = current_profiles[i].name;
      option.value = current_profiles[i].name;
      fragment.appendChild(option);
    }
    ingest_profile_display.innerHTML = '';
    ingest_profile_display.appendChild(fragment);
    return;
  }



  // set options for the Dynamic Ingest API request
  function createRequest(type) {
    var options = {},
      reqBody = {};

      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;

    switch (type) {
      case 'getProfiles':
      var i;
      endpoint = '/profiles';
      options.url = 'https://ingestion.api.brightcove.com/v1/accounts/' + account_id + endpoint;
      options.requestType = 'GET';
      makeRequest(options, function(response) {
        if (isJson(response)) {
          current_profiles = JSON.parse(response);
          toggleObsoleteProfiles();
          // hide legacy profiles
          i = current_profiles.length;
          while (i > 0) {
            i--;
            if (!current_profiles[i].hasOwnProperty('dynamic_origin')) {
              current_profiles.splice(i, 1);
            }
          }

          displayFilteredProfiles();
        } else {
          api_response.textContent = response;
          console.log('The get all profiles operation failed; see the API Response for the error');
          return;
        }
      });
        break;
      case 'transcodeVideos':
      // get the ingest profile
        ingest_profile =
        ingest_profile_display.options[ingest_profile_display.selectedIndex]
        .value;
      reqBody.master = {};
      reqBody.master.use_archived_master = true;
      reqBody.profile = ingest_profile;
      reqBody.callbacks = callbacks;
      options.requestBody = JSON.stringify(reqBody);
      options.requestType = "POST";
      options.url = 'https://ingest.api.brightcove.com/v1/accounts/' + account_id + '/videos/' + videoData[videoNumber] + '/ingest-requests';
      di_url_display = options.url;
      // now submit the request
      makeRequest(options, function(response) {
        response = JSON.parse(response);
        api_response_display.textContent = JSON.stringify(response, null, '  ');
        totalIngested++;
        logResponse("total transcoded", 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 5 min before resuming
            t2 = setTimeout(createRequest('transcodeVideos'), 30000);
          } else {
            // pause slightly to reduce change of hitting jobs overload
            t2 = setTimeout(createRequest('transcodeVideos'), 1000);
          }
        }
      });

    }
  }
  // function to set the request
  function logResponse(type, data) {
    response.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
              console.log(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));
  }

  // event listeners
  videoDataDisplay.addEventListener('click', function() {
    this.select();
  });

  account_id_display.addEventListener('blur', function() {
    account_id = account_id_display.value;
    client_id = client_id_display.value;
    client_secret = client_secret_display.value;
    if (isDefined(account_id) && isDefined(client_id) && isDefined(client_secret)) {
      // refresh Profiles
      createRequest('getProfiles');
      logResponse('New account info...', 'updating profiles list');
    }
  })

  client_id_display.addEventListener('blur', function() {
    account_id = account_id_display.value;
    client_id = client_id_display.value;
    client_secret = client_secret_display.value;
    if (isDefined(account_id) && isDefined(client_id) && isDefined(client_secret)) {
      // refresh Profiles
      createRequest('getProfiles');
      logResponse('New account info...', 'updating profiles list');
    }
  })

  client_secret_display.addEventListener('blur', function() {
    account_id = account_id_display.value;
    client_id = client_id_display.value;
    client_secret = client_secret_display.value;
    if (isDefined(account_id) && isDefined(client_id) && isDefined(client_secret)) {
      // refresh Profiles
      createRequest('getProfiles');
      logResponse('New account info...', 'updating profiles list');
    }
  })

  di_submit_display.addEventListener("click", function() {
    var i,
      now = new Date().valueOf();
    videoData = JSON.parse(videoDataDisplay.value);
    totalVideos = videoData.length;
    // 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;
    di_url_display.value =
      di_url +
      account_id +
      "/videos/" +
      videoData[videoNumber] +
      "/ingest-requests";

    // set DI API options for first video
    createRequest('transcodeVideos');
  });
  // initialize
  function init() {
    // default account id
    account_id = defaults.account_id;
    // get account profiles
    createRequest('getProfiles');
  }
  // 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