Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <fieldset class="bcls-fieldset"><legend>Input</legend>
<p>If you don't include values below, a Brightcove sample account will be used.</p>

<p>Account id: <input type="text" id="account_id_input" style="width:40%;" /></p>

<p>Policy key: <input type="text" id="policy_key_input" style="width:70%;" /></p>

<p>Playlist id: <input type="text" id="playlist_id_input" style="width:40%;" /></p>

<p>Feed description: <input type="text" id="feedDescription" value="My MRSS Feed" />  <span style="color:#FDCD0B;">Required!</span></p>

<p>Site or video portal URL: <input type="text" size="40" id="siteURL" value="https://mysite.com" /> <span style="color:#FDCD0B;">Required!</span></p>

<p>MRSS feed URL (atom link): <input type="text" size="40" id="feedURL" value="https://mysite.com/mrss.xml" /> <span style="color:#FDCD0B;">Required!</span></p>

<button id="showJSON" class="bcls-button">Show JSON</button><button id="showMRSS" class="bcls-button">Show MRSS</button>

<div><textarea id="feed" class="bcls-code" style="height:400px;">Feed will appear here...</textarea></div>

</fieldset>

              
            
!

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 showJSON = document.getElementById("showJSON"),
    showMRSS = document.getElementById("showMRSS"),
    mrssOutput = false,
    feed = document.getElementById("feed"),
    account_id_input = document.getElementById("account_id_input"),
    videoData,
    policy_key_input = document.getElementById("policy_key_input"),
    playlist_id_input = document.getElementById("playlist_id_input"),
    siteURL = document.getElementById('siteURL'),
    feedURL = document.getElementById('feedURL'),
    feedDescription = document.getElementById('feedDescription'),
    account_id,
    policyKey,
    playlist_id,
    feedname,
    // the next three lines are the ones that need to be changed
    account_id_default = "1752604059001",
    policyKey_default =
    "BCpkADawqM3_9ax216PJYuUTLApMLkLJ3apjFlTRKHHS4q0DE33J0XsiDWmc6SfKwrwRAhejCZpTbwljz4-OlUwyqKi64L25Dwy4yhY1eSZ9ZduI-dO0mjSNVcR9C8nz0jtkimOOtzQgswCr",
    playlist_id_default = "5492280057001",
    // vars for MRSS generation
    mrssStr =
    '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns:atom="http://www.w3.org/2005/Atom">',
    sCdata = '<![CDATA[',
    eCdata = ']]>',
    sChannel = "<channel>",
    eChannel = "</channel>",
    sTitle = "<title>",
    eTitle = "</title>",
    sDescription = "<description>",
    eDescription = "</description>",
    sItem = "<item>",
    eItem = "</item>",
    sLink = "<link>",
    eLink = "</link>",
    sPubDate = "<pubDate>",
    ePubDate = "</pubDate>",
    sGuid = '<guid isPermaLink="false">',
    eGuid = '</guid>',
    sMediaContent = "<media:content",
    eMediaContent = " />",
    sMediaPlayer = "<media:player",
    eMediaPlayer = " />",
    sMediaDescription = "<description>",
    eMediaDescription = "</description>",
    sMediaThumbnail = "<media:thumbnail",
    eMediaThumbnail = "/>",
    sMediaTitle = "<title>",
    eMediaTitle = "</title>";

  // event listeners for the buttons
  showJSON.addEventListener("click", function() {
    mrssOutput = false;
    // get media data if we haven't already
    if (!isDefined(videoData)) {
      // check inputs to see if we use those or default values
      if (
        isDefined(account_id_input.value) &&
        isDefined(policy_key_input.value) &&
        isDefined(playlist_id_input.value)
      ) {
        account_id = removeSpaces(account_id_input.value);
        policyKey = removeSpaces(policy_key_input.value);
        playlist_id = removeSpaces(playlist_id_input.value);
      } else {
        account_id = account_id_default;
        policyKey = policyKey_default;
        playlist_id = playlist_id_default;
      }
      getMediaData(function() {
        feed.textContent = JSON.stringify(videoData, null, "  ");
      });
    } else {
      // JSON data to the textarea
      feed.textContent = JSON.stringify(videoData, null, "  ");
    }
  });

  showMRSS.addEventListener("click", function() {
    mrssOutput = true;
    // get media data if we haven't already
    if (!isDefined(videoData)) {
      // check inputs to see if we use those or default values
      if (
        isDefined(account_id_input.value) && isDefined(policy_key_input.value) && isDefined(playlist_id_input.value)
      ) {
        account_id = removeSpaces(account_id_input.value);
        policyKey = removeSpaces(policy_key_input.value);
        playlist_id = removeSpaces(playlist_id_input.value);
      } else {
        account_id = account_id_default;
        policyKey = policyKey_default;
        playlist_id = playlist_id_default;
      }
      getMediaData(function() {
        processMRSS();
      });
    } else {
      processMRSS();
    }
  });

  function processMRSS() {
    var i, iMax, sources;
    iMax = videoData.length;
    for (i = 0; i < iMax; i++) {
      sources = videoData[i].sources;
      if (sources.length > 0) {
        // get the best MP4 rendition
        var source = processSources(sources);
        videoData[i].source = source;
      } else {
        // video has no sources
        videoData[i].source = null;
      }
    }
    // remove videos with no sources
    i = videoData.length;
    while (i > 0) {
      i--;
      if (!isDefined(videoData[i].source)) {
        videoData.splice(i, 1);
      }
    }
    // generate and display the MRSS data
    addItems();
  }

  /**
   * tests for all the ways a variable might be undefined or not have a value
   * @param {String|Number} x the variable to test
   * @return {Boolean} true if variable is defined and has a value
   */
  function isDefined(x) {
    if (x === "" || x === null || x === undefined) {
      return false;
    }
    return true;
  }

  /**
   * remove spaces from a string
   * @param {String} str string to process
   * @return {String} trimmed string
   */
  function removeSpaces(str) {
    str = str.replace(/\s/g, "");
    return str;
  }

  /**
   * sort an array of objects based on an object property
   * @param {array} targetArray - array to be sorted
   * @param {string|number} objProperty - object property to sort on
   * @return sorted array
   */
  function sortArray(targetArray, objProperty) {
    targetArray.sort(function(b, a) {
      var propA = a[objProperty],
        propB = b[objProperty];
      // sort ascending; reverse propA and propB to sort descending
      if (propA < propB) {
        return -1;
      } else if (propA > propB) {
        return 1;
      } else {
        return 0;
      }
    });
    return targetArray;
  }

  /**
   * [processSources gets the highest bitrate source for the MRSS feed
   * @param  {Array} sources array of video sources
   * @return {Object} the highest bitrate MP4 source
   */
  function processSources(sources) {
    var i = sources.length;
    // remove non-MP4 sources
    while (i > 0) {
      i--;
      if (sources[i].container !== "MP4") {
        sources.splice(i, 1);
      } else if (sources[i].hasOwnProperty("stream_name")) {
        sources.splice(i, 1);
      }
    }
    // sort sources by encoding rate
    sortArray(sources, "encoding_rate");
    // return the first item (highest bitrate)
    return sources[0];
  }

  /**
   * add video items to the MRSS feed
   */
  function addItems() {
    var i,
      iMax,
      video,
      pubdate,
      videoURL,
      thumbnailURL,
      doThumbnail = true;
    if (videoData.length > 0) {
      mrssStr += sChannel;
      mrssStr += '<atom:link href="' + feedURL.value.replace(/&/g, '&amp;') + '" rel="self" type="application/rss+xml" />';
      mrssStr += sTitle + feedname + eTitle;
      mrssStr += sDescription + sCdata + feedDescription.value + eCdata + eDescription;
      mrssStr += sLink + siteURL.value.replace(/&/g, "&amp;") + eLink;
      iMax = videoData.length;
      for (i = 0; i < iMax; i += 1) {
        doThumbnail = true;
        video = videoData[i];

        // video may not have a valid source
        if (isDefined(video.source) && isDefined(video.source.src)) {
          videoURL = video.source.src.replace(/&/g, "&amp;");
        } else {
          // no source; skip this videos
          continue;
        }
        // depending on when/how the video was created, it may have different thumbnail properties or none at all
        if (isDefined(video.thumbnail)) {
          thumbnailURL = encodeURI(video.thumbnail.replace(/&/g, "&amp;"));
        } else {
          doThumbnail = false;
        }

        pubdate = new Date(video.created_at).toGMTString();
        mrssStr += sItem;
        mrssStr +=
          sLink +
          "https://players.brightcove.net/" +
          account_id +
          "/default_default/index.html?videoId=" +
          video.id +
          eLink;
        mrssStr += sPubDate + pubdate + ePubDate;
        mrssStr += sGuid + video.id + eGuid;
        mrssStr +=
          sMediaContent +
          ' url="' +
          videoURL +
          '" fileSize="' +
          video.source.size +
          '" type="video/quicktime" medium="video" duration="' +
          video.duration / 1000 +
          '" isDefault="true" height="' +
          video.source.height +
          '" width="' +
          video.source.width +
          '"' + eMediaContent;
        mrssStr +=
          sMediaPlayer +
          ' url="' +
          "https://players.brightcove.net/" +
          account_id +
          "/default_default/index.html?videoId=" +
          video.id +
          '"' +
          eMediaPlayer;
        mrssStr += sMediaTitle + video.name + eMediaTitle;
        mrssStr += sMediaDescription + sCdata + video.description + eCdata + eMediaDescription;
        if (doThumbnail) {
          mrssStr += sMediaThumbnail + ' url="' + thumbnailURL + '"';
          if (isDefined(video.images)) {
            mrssStr +=
              ' height="' +
              video.images.thumbnail.sources[0].height +
              '" width="' +
              video.images.thumbnail.sources[0].width +
              '"' +
              eMediaThumbnail;
          } else {
            mrssStr += eMediaThumbnail;
          }
        }
        mrssStr += eItem;
      }
      mrssStr += eChannel + "</rss>";
      feed.textContent = vkbeautify.xml(mrssStr);
    }
  }

  feed.addEventListener("click", function() {
    feed.select();
  });

  /**
   * makes the request to the Playback API
   */
  function getMediaData(callback) {
    var httpRequest = new XMLHttpRequest(),
      responseData,
      parsedData,
      requestURL =
      "https://edge.api.brightcove.com/playback/v1/accounts/" +
      account_id +
      "/playlists/" +
      playlist_id +
      "?limit=100";
    // response handler
    getResponse = function() {
      try {
        if (httpRequest.readyState === 4) {
          if (httpRequest.status >= 200 && httpRequest.status < 300) {
            responseData = httpRequest.responseText;
            parsedData = JSON.parse(responseData);
            videoData = parsedData.videos;
            feedname = parsedData.name;
            if (mrssOutput) {
              callback();
            } else {
              callback();
            }
          } else {
            alert(
              "There was a problem with the request. Request returned " +
              httpRequest.status
            );
          }
        }
      } catch (e) {
        alert("Caught Exception: " + e);
      }
    };
    // set response handler
    httpRequest.onreadystatechange = getResponse;
    // open the request
    httpRequest.open("GET", requestURL);
    // set headers
    httpRequest.setRequestHeader("Accept", "application/json;pk=" + policyKey);
    // open and send request
    httpRequest.send();
  }
})(window, document);

              
            
!
999px

Console