<commit_before>var request = require('request');
var xml2js = require('xml2js');
var querystring = require('querystring');
var util = require('util');

var mbBaseURI = 'http://musicbrainz.org/ws/2/';
var mb = exports;

var Resource = function (mbid) {
	this.id = mbid;
};
Resource.prototype.load = function (callback) {
	if (this._loaded) {
		if (typeof callback == 'function') callback();
		return;
	};

	var self = this;
	this._lookup(this.id, function (error, release) {
		for (i in self) {
			self[i] = release[i];
		}

		if (typeof callback == 'function') callback();
	});
};

var Disc = function (discId) {
	this.id = discId;
	this.releases = [];
};

var Release = function (mbid) {
	Resource.call(this);

	this._lookup = mb.lookupRelease;
	this._loaded = false;
	this.id = mbid;
	this.title = null; 
	this.status = null; 
	this.packaging = null;
	this.quality = null;
	this.language = null;
	this.script = null;
	this.date = null;
	this.country = null;
	this.barcode = null;
	this.asin = null;
	this.mediums = [];
	this.releaseGroups = [];
	this.labelInfo = [];
};
util.inherits(Release, Resource);
Release.prototype.loadxxx = function (callback) {
	var self = this;
	if (self._loaded) return;

	mb.lookupRelease(self.id, function (error, release) {
		for (i in self) {
			self[i] = release[i];
		}

		if (typeof callback == 'function') callback();
	});
};

var Medium = function () {
	this.title = null;
	this.position = null;
	this.format = null;
	this.discs = [];
	this.tracks = [];
};

var Track = function () {
	this.position = null; 
	this.length = null;
	this.recording = null;
};

var Recording = function (mbid) {
	Resource.call(this);

	this._lookup = mb.lookupRecording;
	this._loaded = false;
	this.id = mbid;
	this.title = null;
	this.length = null;
	this.artist = null;
	this.producer = null;
	this.vocal = null;
	this.performance = null;
};
util.inherits(Recording, Resource);

var ReleaseGroup = function (mbid) {
	Resource.call(this);

	this._lookup = mb.lookupReleaseGroup;
	this._loaded = false;
	this.id = mbid;
	this.type = null;
	this.title = null;
	this.firstReleaseDate = null;
	this.releases = [];
};
util.inherits(ReleaseGroup, Resource);

var Artist = function (mbid) {
	Resource.call(this);

	this._lookup = mb.lookupArtist;
	this._loaded = false;
	this.id = mbid;
	this.type = null;
	this.name = null;
	this.sortName = null;
	this.lifeSpan = {
		'begin' : null, 
		'end' : null
	};
};
util.inherits(Artist, Resource);

var LabelInfo = function () {
	this.catalogNumber = null;
	this.label = null;
};

var Label = function (mbid) {
	Resource.call(this);

	this._lookup = mb.lookupLabel;
	this._loaded = false;
	this.id = mbid;
	this.name = null;
	this.sortName = null;
	this.labelCode = null;
	this.country = null;
	this.lifeSpan = {
		'begin' : null, 
		'end' : null
	};
	this.releases = [];
};
util.inherits(Label, Resource);

var Work = function (mbid) {
	Resource.call(this);

	this._lookup = mb.lookupWork;
	this._loaded = false;
	this.id = mbid;
	this.type = null;
	this.title = null;
};
util.inherits(Label, Resource);

var Error = function (data) {
	this.message = null;
	if (typeof data.text !== 'undefined') {
		if (!data.text.length) data.text = [data.text];
		this.message = data.text.join("\n");
	}
	this.statusCode = null;
}

mb.lookup = function (resource, mbid, inc, callback) {
	var uri = mbBaseURI + resource + '/' + mbid;
	if (inc) uri += '?inc=' + inc.join('+');

	request({
		'method' : 'GET', 
		'uri' : uri

	}, function (error, response, body) {
		var parser = new xml2js.Parser();

		if (!error && response.statusCode == 200) {<commit_msg>Using util.inherits to save some code<commit_after>var request = require('request');
var xml2js = require('xml2js');
var querystring = require('querystring');
var util = require('util');

var mbBaseURI = 'http://musicbrainz.org/ws/2/';
var mb = exports;

var Resource = function (mbid) {
	this._loaded = false;
	this.id = mbid;
};
Resource.prototype._lookup = function () {};
Resource.prototype.load = function (callback) {
	if (this._loaded) {
		if (typeof callback == 'function') callback();
		return;
	};

	if (typeof this._lookup !== 'function') return;

	var self = this;
	this._lookup(this.id, function (error, resource) {
		if (error) console.log(error);
		for (i in self) {
			self[i] = resource[i];
		}

		if (typeof callback == 'function') callback();
	});
};

var Disc = function (discId) {
	this.id = discId;
	this.releases = [];
};

var Release = function (mbid) {
	Resource.call(this, mbid);

	this.title = null; 
	this.status = null; 
	this.packaging = null;
	this.quality = null;
	this.language = null;
	this.script = null;
	this.date = null;
	this.country = null;
	this.barcode = null;
	this.asin = null;
	this.mediums = [];
	this.releaseGroups = [];
	this.labelInfo = [];

	this._lookup = mb.lookupRelease;
};
util.inherits(Release, Resource);

var Medium = function () {
	this.title = null;
	this.position = null;
	this.format = null;
	this.discs = [];
	this.tracks = [];
};

var Track = function () {
	this.position = null; 
	this.length = null;
	this.recording = null;
};

var Recording = function (mbid) {
	Resource.call(this, mbid);

	this.title = null;
	this.length = null;
	this.artist = null;
	this.producer = null;
	this.vocal = null;
	this.performance = null;

	this._lookup = mb.lookupRecording;
};
util.inherits(Recording, Resource);

var ReleaseGroup = function (mbid) {
	Resource.call(this, mbid);

	this.type = null;
	this.title = null;
	this.firstReleaseDate = null;
	this.releases = [];

	this._lookup = mb.lookupReleaseGroup;
};
util.inherits(ReleaseGroup, Resource);

var Artist = function (mbid) {
	Resource.call(this, mbid);

	this.type = null;
	this.name = null;
	this.sortName = null;
	this.lifeSpan = {
		'begin' : null, 
		'end' : null
	};

	this._lookup = mb.lookupArtist;
};
util.inherits(Artist, Resource);

var LabelInfo = function () {
	this.catalogNumber = null;
	this.label = null;
};

var Label = function (mbid) {
	Resource.call(this, mbid);

	this.name = null;
	this.sortName = null;
	this.labelCode = null;
	this.country = null;
	this.lifeSpan = {
		'begin' : null, 
		'end' : null
	};
	this.releases = [];

	this._lookup = mb.lookupLabel;
};

var Work = function (mbid) {
	Resource.call(this, mbid);

	this.type = null;
	this.title = null;

	this._lookup = mb.lookupWork;
};
util.inherits(Work, Resource);

var Error = function (data) {
	this.message = null;
	if (typeof data.text !== 'undefined') {
		if (!data.text.length) data.text = [data.text];
		this.message = data.text.join("\n");
	}
	this.statusCode = null;
}

mb.lookup = function (resource, mbid, inc, callback) {
	var uri = mbBaseURI + resource + '/' + mbid;
	if (inc) uri += '?inc=' + inc.join('+');

	request({
		'method' : 'GET', 
		'uri' : uri

	}, function (error, response, body) {
		var parser = new xml2js.Parser();

		if (!error && response.statusCode == 200) {
{'fraction_non_alphanumeric': 0.16787685158292187, 'fraction_numerical': 0.0020331106593087424, 'mean_word_length': 3.7138945927446954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '2836375', 'n_tokens_mistral': 2596, 'n_tokens_neox': 2478, 'n_words': 595}