<commit_before>var metafetch = require("metafetch");
var url = require("url");

// we prepend a zero-width char because of a weird fucking
// bug on mobile safari where if the embed is the first child,
// the video player will not show. This causes issues with
// inline elements displaying (adds extra space) solution needed
// that doesn't disrupt page layout...
function template(url, width, height, ratio) {
  return (
    '<div style="width:0;height:0"> </div><div class="videoContainer bandcamp" style="padding-bottom: ' +
    ratio +
    '%"><iframe width="' +
    width +
    '" height="' +
    height +
    '" src="' +
    url +
    '" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>'
  );
}

var FAIL = "Could not retrieve song properties";

module.exports = function (href, callback) {
  // Before loading anything, check that the path starts with
  // /album or /track
  var path, paths;
  try {
    path = url.parse(href).pathname;
  } catch (e) {
    return next();
  }

  // Trim trailing slash if applicable
  if (path.slice(-1) === "/") path = path.slice(0, -1);

  paths = path.split("/");

  if (paths.length < 1) {
    return callback(new Error(FAIL));
  }

  var category = paths[1];
  if (category !== "track" && category !== "album") {
    return callback(new Error(FAIL));
  }

  var height, width, ratio;

  metafetch.fetch(href, function (error, data) {
    if (error || !data) return callback(new Error(FAIL));

    var meta = data.meta;
    height = Number(meta["og:video:height"]);
    width = Number(meta["og:video:width"]);
    html = meta["og:video"];

    if (height == NaN || width == NaN) {
      return callback(new Error(FAIL));
    }

    ratio = (height / width) * 100;

    return callback(null, template(html, width, height, ratio));
  });
};<commit_msg>Add extra err check`<commit_after>var metafetch = require("metafetch");
var url = require("url");

// we prepend a zero-width char because of a weird fucking
// bug on mobile safari where if the embed is the first child,
// the video player will not show. This causes issues with
// inline elements displaying (adds extra space) solution needed
// that doesn't disrupt page layout...
function template(url, width, height, ratio) {
  return (
    '<div style="width:0;height:0"> </div><div class="videoContainer bandcamp" style="padding-bottom: ' +
    ratio +
    '%"><iframe width="' +
    width +
    '" height="' +
    height +
    '" src="' +
    url +
    '" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>'
  );
}

var FAIL = "Could not retrieve song properties";

module.exports = function (href, callback) {
  // Before loading anything, check that the path starts with
  // /album or /track
  var path, paths;
  try {
    path = url.parse(href).pathname;
  } catch (e) {
    return next();
  }

  // Trim trailing slash if applicable
  if (path.slice(-1) === "/") path = path.slice(0, -1);

  paths = path.split("/");

  if (paths.length < 1) {
    return callback(new Error(FAIL));
  }

  var category = paths[1];
  if (category !== "track" && category !== "album") {
    return callback(new Error(FAIL));
  }

  var height, width, ratio;

  metafetch.fetch(href, function (error, data) {
    if (error || !data) return callback(new Error(FAIL));

    var meta = data.meta;
    height = Number(meta["og:video:height"]);
    width = Number(meta["og:video:width"]);
    html = meta["og:video"];

    if (!html || height == NaN || width == NaN) {
      return callback(new Error(FAIL));
    }

    ratio = (height / width) * 100;

    return callback(null, template(html, width, height, ratio));
  });
};
{'fraction_non_alphanumeric': 0.15726681127982647, 'fraction_numerical': 0.00596529284164859, 'mean_word_length': 3.2995337995337994, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4926559', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1112, 'n_words': 360}