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.

            
              <h2 id="accountInput">Schema Generator</h2>

<p class="text-warning"><span style="color:#990000;">All fields are <strong>required</strong></span>. Default values are included from the Brightcove Learning Services demo account to allow you to test the tool — you must replace all of these to get a schema for your own video.</p>

<div id="inputFields" class="input-fields">
<fieldset class="bcls-fieldset"><legend>Account Information</legend>

<div id="accountInfo">
<table class="bcls-table">
	<tbody class="bcls-table__body">
		<tr>
			<td>Video Cloud Account ID:</td>
			<td><input id="accountID" type="text" size="60" placeholder="1752604059001" /></td>
		</tr>
		<tr>
			<td>Client id:</td>
			<td><input id="clientID" type="text" size="60" /></td>
		</tr>
		<tr>
			<td>Client secret:</td>
			<td><input id="clientSecret" type="text" size="60" /></td>
		</tr>
	</tbody>
</table>
</div>
</fieldset>
</div>
<fieldset class="bcls-fieldset"><legend>Player Information</legend>

<div id="playerInfo">
<p class="BCL-aside">Note: use a single video player</p>

<table class="bcls-table">
	<tbody class="bcls-table__body">
		<tr>
			<td>Video ID</td>
			<td><input id="videoId" type="text" size="60" placeholder="4454620113001" /></td>
		</tr>
		<tr>
			<td>Player ID (from Publishing Module or publishing code):</td>
			<td><input id="playerID" size="60" placeholder="28e29e6d-bed3-4db9-8d70-8d55b8aa3091" /></td>
		</tr>
		<tr>
			<td>Player width:</td>
			<td><input id="playerWidth" type="text" size="60" placeholder="480" /></td>
		</tr>
		<tr>
			<td>Player height:</td>
			<td><input id="playerHeight" type="text" size="60" placeholder="270" /></td>
		</tr>
	</tbody>
</table>
</div>

<p><button id="generateMicrodata" class="bcls-button">Generate Microdata Schema</button><button id="generateJSON_ld" class="bcls-button">Generate JSON-LD Schema</button></p>
</fieldset>
<div id="publishingCodeWrapper">
<fieldset class="bcls-fieldset"><legend>Publishing Code</legend><textarea id="publishingCode" class="bcls-code"></textarea></fieldset>
</div>

            
          
!
            
              /* * 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) {
    "use strict";
    var proxyURL = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php',
        accountID = document.getElementById('accountID'),
        account_id,
        clientID = document.getElementById('clientID'),
        clientSecret = document.getElementById('clientSecret'),
        playerID = document.getElementById('playerID'),
        playerWidth = document.getElementById('playerWidth'),
        playerHeight = document.getElementById('playerHeight'),
        videoId = document.getElementById('videoId'),
        video_id,
        generateMicrodata = document.getElementById('generateMicrodata'),
        generateJSON_ld = document.getElementById('generateJSON_ld'),
        publishingCode = document.getElementById('publishingCode'),
        videoData = null,
        defaults = {};

    /**
     * determines whether a var has value
     * @param  {*}  x var to evaluate - note that if x = {} or [], true will be returned
     * @return {Boolean}   whether var has a value
     */
    function isDefined(x) {
        if (x === '' || x === null || x === undefined) {
            return false;
        }
        return true;
    }

    /**
     * utility to extract h/m/s from seconds
     * @param {number} secs - seconds to convert to Thh:mm:ss
     * @return {String} ISO 8601 time string
     */
    function secondsToTime(secs) {
        var hours = Math.floor(secs / (60 * 60)),
            divisor_for_minutes = secs % (60 * 60),
            minutes = Math.floor(divisor_for_minutes / 60),
            divisor_for_seconds = divisor_for_minutes % 60,
            seconds = Math.ceil(divisor_for_seconds);

        if (hours < 10) {
            hours = '0' + hours.toString();
        } else {
            hours = hours.toString();
        }

        if (minutes < 10) {
            minutes = '0' + minutes.toString();
        } else {
            minutes = minutes.toString();
        }

        if (seconds < 10) {
            seconds = '0' + seconds.toString();
        } else {
            seconds = seconds.toString();
        }

        return 'T' + hours + ':' + minutes + ':' + seconds;
    }

    /**
     * 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));
    }

    function generateSchema(type) {
      var microData,
        json_ld,
        object_ld;
        // insert other data that the schema needs
        videoData.playerID = isDefined(playerID.textContent) ? playerID.textContent : defaults.playerID;
        videoData.playerWidth = isDefined(playerWidth.textContent) ? playerWidth.textContent : defaults.playerWidth;
        videoData.playerHeight = isDefined(playerHeight.textContent) ? playerHeight.textContent : defaults.playerHeight;
        // convert the duration to ISO format schema needs
        videoData.duration = secondsToTime(videoData.duration / 1000);
        microData = '<!-- Start Schema Code --> \n <div id="content"> \n <div itemscope itemtype="http://schema.org/VideoObject"> \n <meta itemprop="name" content="';
        microData += videoData.name + '"> \n <meta itemprop="description" content="';
        microData += videoData.description + '"> \n <meta itemprop="videoId" content="';
        microData += videoData.id + '"> \n <meta itemprop="duration" content="';
        microData += videoData.duration + '"> \n <link itemprop="thumbnail" href="';
        microData += videoData.images.thumbnail.src + '"> \n <link itemprop="embedURL" href="http://players.brightcove.net/';
        microData += videoData.account_id + '/';
        microData += videoData.playerID + '_default/index.html?videoId=';
        microData += videoData.id + '"> \n <meta itemprop="width" content="';
        microData += videoData.playerWidth + '"> \n <meta itemprop="height" content="';
        microData += videoData.playerHeight + '"> \n <!-- End Schema Code --> \n <!-- Start Player Code --> \n <iframe src="//players.brightcove.net/';
        microData += videoData.accountID + '/default_default/index.html?videoId=';
        microData += videoData.id + '" style="width:';
        microData += videoData.playerWidth + ';height:';
        microData += videoData.playerHeight + '" allowfullscreen webkitallowfullscreen mozallowfullscreen><\/iframe>  \n <!-- End Player Code --> \n <\/div> \n <\/div>';
        json_ld = '<!-- Start Schema Code --> \n <script type="application/ld+json"> \n';
        object_ld = {"@context": "http://schema.org/","@type": "VideoObject","name": videoData.name, "@id": videoData.url, "datePublished": videoData.created_at, "interactionStatistic": [ {"@type": "InteractionCounter", "interactionType": "http://schema.org/WatchAction", "userInteractionCount": videoData.total_plays}]};
        json_ld += JSON.stringify(object_ld) + ' \n';
        json_ld += '\</script\> \n <!-- End Schema Code --> \n';
        json_ld += '<!-- Start Player Code --> \n <iframe src="//players.brightcove.net/';
        json_ld += videoData.accountID + '/default_default/index.html?videoId=';
        json_ld += videoData.id + '" style="width:';
        json_ld += videoData.playerWidth + ';height:';
        json_ld += videoData.playerHeight + '" allowfullscreen webkitallowfullscreen mozallowfullscreen><\/iframe> \n <!-- End Player Code --> \n ';
        switch (type) {
          case 'microdata':
            publishingCode.textContent = microData;
            break;
          case 'json_ld':
            publishingCode.textContent = json_ld;
            break;
          default:
            break;
        }
    }

    // set listeners for buttons
    generateMicrodata.addEventListener("click", function () {
        // data setup
        var options = {};
        options.client_id = (isDefined(clientID.value)) ? clientID.value : defaults.client_id;
        options.client_secret = (isDefined(clientSecret.value)) ? clientSecret.value : defaults.client_secret;
        account_id = (isDefined(accountID.value)) ? accountID.value : defaults.account_id;
        video_id = (isDefined(videoId.value)) ? videoId.value : defaults.videoId;
        options.url = 'https://cms.api.brightcove.com/v1/accounts/' + account_id + '/videos/' + video_id;
        options.proxyURL = proxyURL;
        options.requestType = "GET";
        makeRequest(options, function(response) {
            videoData = JSON.parse(response);
            videoData.url = 'http://http://players.brightcove.net/' + account_id + '/default_default/index.html';
            options.url = 'https://analytics.api.brightcove.com/v1/alltime/accounts/' + account_id + '/videos/' + video_id;
            makeRequest(options, function(response) {
                response = JSON.parse(response);
                videoData.total_plays = response.alltime_video_views;
                generateSchema('microdata');
            });
        });
    });

    generateJSON_ld.addEventListener("click", function () {
        // data setup
        var options = {};
        options.client_id = (isDefined(clientID.value)) ? clientID.value : defaults.client_id;
        options.client_secret = (isDefined(clientSecret.value)) ? clientSecret.value : defaults.client_secret;
        account_id = (isDefined(accountID.value)) ? accountID.value : defaults.account_id;
        video_id = (isDefined(videoId.value)) ? videoId.value : defaults.videoId;
        options.url = 'https://cms.api.brightcove.com/v1/accounts/' + account_id + '/videos/' + video_id;
        options.proxyURL = proxyURL;
        options.requestType = "GET";
        makeRequest(options, function(response) {
            videoData = JSON.parse(response);
            videoData.url = 'http://http://players.brightcove.net/' + account_id + '/default_default/index.html';
            options.url = 'https://analytics.api.brightcove.com/v1/alltime/accounts/' + account_id + '/videos/' + video_id;
            makeRequest(options, function(response) {
                response = JSON.parse(response);
                videoData.total_plays = response.alltime_video_views;
                generateSchema('json_ld');
            });
        });
    });

    publishingCode.addEventListener('click', function() {
        publishingCode.select();
    });

    function init() {
        defaults.account_id = '1752604059001';
        defaults.playerID = 'default';
        defaults.videoId = '5625780785001';
        defaults.playerWidth = '480';
        defaults.playerHeight = '270';
        // proxy has credentials for the default account, so no need to send them
        defaults.client_id = '';
        defaults.client_secret = '';
    }

    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