<commit_before>var request = require('request');

var MediaUpload = function (oauth_options) {
	if (typeof oauth_options !== 'object') {
		throw new Error('You have to provide oauth_options');
	}

	this.oauth_options = oauth_options;
};

MediaUpload.SUPPORTED_TYPES = ['image', 'video'];
MediaUpload.UPLOAD_ENDPOINT = 'https://upload.twitter.com/1.1/media/upload.json';

MediaUpload.prototype.uploadImageSet = function (images, callback) {
	throw new Error('Not implemented yet!');
};

MediaUpload.prototype.uploadMedia = function (type, media, callback) {
	var self = this;

	if (MediaUpload.SUPPORTED_TYPES.indexOf(type) === -1) {
		return callback(new Error('Unsupported media type ' + type));
	}

	if (!Buffer.isBuffer(media)) {
		return callback(new Error('Media has to be a Buffer instance'));
	}

	if (type === 'image') {
		this._uploadImage(media, callback);
	} else {
		this._uploadVideo(media, callback);
	}
};

MediaUpload.prototype._uploadImage = function (media, callback) {
	this._postRequest({
		formData: {
			media: media
		},
		url: MediaUpload.UPLOAD_ENDPOINT,
		json: true
	}, function (err, response, body) {
		if (err) {
			return callback(err);
		}
		if (response.statusCode >= 200 && response.statusCode < 300) {
			return callback(null, body.media_id_string, body);
		} else return callback(new Error('Error occured while uploading media'));
	});
};

MediaUpload.prototype._uploadVideo = function (media, callback) {
	var self = this;

	// lil' callback hell
	this._initUpload(type, media, function (err, media_id) {
		self._appendMedia(media_id, media, function (err) {
			self._finalizeUpload(media_id, callback);
		});
	});
};

MediaUpload.prototype._postRequest = function (params, callback) {
	params = params || {};
	params.oauth = params.oauth || this.oauth_options;

	request.post(params, function (err, response, body) {
		callback(err, response, body);<commit_msg>fixed uploading videos<commit_after>var request = require('request');

var MediaUpload = function (oauth_options) {
	if (typeof oauth_options !== 'object') {
		throw new Error('You have to provide oauth_options');
	}

	this.oauth_options = oauth_options;
};

MediaUpload.SUPPORTED_TYPES = ['image', 'video'];
MediaUpload.UPLOAD_ENDPOINT = 'https://upload.twitter.com/1.1/media/upload.json';

MediaUpload.prototype.uploadImageSet = function (images, callback) {
	throw new Error('Not implemented yet!');
};

MediaUpload.prototype.uploadMedia = function (type, media, callback) {
	var self = this;

	if (MediaUpload.SUPPORTED_TYPES.indexOf(type) === -1) {
		return callback(new Error('Unsupported media type ' + type));
	}

	if (!Buffer.isBuffer(media)) {
		return callback(new Error('Media has to be a Buffer instance'));
	}

	if (type === 'image') {
		this._uploadImage(media, callback);
	} else {
		this._uploadVideo(media, callback);
	}
};

MediaUpload.prototype._uploadImage = function (media, callback) {
	this._postRequest({
		formData: {
			media: media
		},
		url: MediaUpload.UPLOAD_ENDPOINT,
		json: true
	}, function (err, response, body) {
		if (err) {
			return callback(err);
		}
		if (response.statusCode >= 200 && response.statusCode < 300) {
			return callback(null, body.media_id_string, body);
		} else return callback(new Error('Error occured while uploading media'));
	});
};

MediaUpload.prototype._uploadVideo = function (media, callback) {
	var self = this;

	// lil' callback hell
	this._initUpload(media, function (err, media_id) {
		self._appendMedia(media_id, media, function (err) {
			self._finalizeUpload(media_id, callback);
		});
	});
};

MediaUpload.prototype._postRequest = function (params, callback) {
	params = params || {};
	params.oauth = params.oauth || this.oauth_options;

	request.post(params, function (err, response, body) {
		callback(err, response, body);
{'fraction_non_alphanumeric': 0.14443567482241515, 'fraction_numerical': 0.004735595895816891, 'mean_word_length': 4.813455657492355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '3056576', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1212, 'n_words': 290}