<commit_before>const yt = require('ytdl-core');
const streamy = require("stream");
const fs = require('fs');
const request = require("request");
const spawn = require("child_process").spawn

module.exports = Player;

function Player(message) {
	var that = this;

	this.message = message;
	this.channel = message.channel;
	this.voicechannel = message.member.voiceChannel;
	this.playlist = [];
	this.current = {};
	this.pid = null;
	this.stream = new streamy.Writable();
	this.connect = function() {
		this.voicechannel
			.join()
			.then(connection => {
				var looper = function() {

					//Get a new song playing on the stream
					that.play();

					//Start playing that stream.
					const dispatcher = connection.playStream(that.stream);

					//When the stream ends, restart the "looper", which gets a new song on the stream
					dispatcher.on('end', () => {
						looper();
					});
				}
				looper();
			});
	}
	this.play = function() {

		if(this.playlist.length === 0) return this.voicechannel.leave();

		this.current = this.playlist.shift();

		//Make an ffmpeg stream
		let ffmpeg = spawn('ffmpeg', [
			'-i', 'pipe:0',
			'-f', 'wav',
			'pipe:1'
		]);

		this.pid = ffmpeg.pid;

		//Send the correct input to the ffmpeg stream
		switch (this.current.type) {

			//Stream from YouTube
			case "youtube":
				yt(this.current.url, {audioonly: true})
					.pipe(ffmpeg.stdin)
					.on('error', (err) => {
						that.play();
					});

				break;

			//Stream from a local file
			case "local":
				fs.createReadStream(this.current.url)
					.pipe(ffmpeg.stdin)
					.on('error', (err) => {
						that.play();
					});

				break;

			//Stream from the internet!
			case "http":
			case "https":
				request(this.current.url)
					.pipe(ffmpeg.stdin)
					.on('error', (err) => {
						that.play();
					})

				break;
			default:
				this.channel.send(`${this.current.type} is not a valid audio provider.`);
				this.skip();
		}

		this.stream = ffmpeg.stdout;

		ffmpeg.stderr.setEncoding('utf8');
		ffmpeg.stderr.on('data', function(data) {
			if(/^execvp\(\)/.test(data)) {
				console.log('failed to start ' + argv.ffmpeg);
				that.play();
			}
		});
	}
	this.add = function(type, url, title, thumb) {
		//Push a JSON string into the array
		this.playlist.push({
			type: type,
			url: url,
			title: title,
			thumb_url: thumb
		});

		//If the bot is not playing, enter the channel and start playing
		if (!this.voicechannel.connection) {
			this.connect();
		}
	}
	this.skip = function() {
		if (this.pid) process.kill(this.pid, "SIGINT");
		this.pid = null;
	}
	this.stop = function() {
		this.skip();
		this.current = {};
		this.playlist = [];
	}
}

process.on("unhandledRejection", function(err) {
	console.log("Uncaught Promise Error: \n" + err.stack);
});

process.on("uncaughtException", function(err) {
	console.log(err.stack);
});<commit_msg>skip after try<commit_after>const yt = require('ytdl-core');
const streamy = require("stream");
const fs = require('fs');
const request = require("request");
const spawn = require("child_process").spawn

module.exports = Player;

function Player(message) {
	var that = this;

	this.message = message;
	this.channel = message.channel;
	this.voicechannel = message.member.voiceChannel;
	this.playlist = [];
	this.current = {};
	this.pid = null;
	this.stream = new streamy.Writable();
	this.connect = function() {
		this.voicechannel
			.join()
			.then(connection => {
				var looper = function() {

					//Get a new song playing on the stream
					that.play();

					//Start playing that stream.
					const dispatcher = connection.playStream(that.stream);

					//When the stream ends, restart the "looper", which gets a new song on the stream
					dispatcher.on('end', () => {
						looper();
					});
				}
				looper();
			});
	}
	this.play = function() {

		if(this.playlist.length === 0) return this.voicechannel.leave();

		this.current = this.playlist.shift();

		//Make an ffmpeg stream
		let ffmpeg = spawn('ffmpeg', [
			'-i', 'pipe:0',
			'-f', 'wav',
			'pipe:1'
		]);

		this.pid = ffmpeg.pid;

		//Try it! If it fails, it skips it.
		try {
			//Send the correct input to the ffmpeg stream
			switch (this.current.type) {

				//Stream from YouTube
				case "youtube":
					yt(this.current.url, {audioonly: true})
						.pipe(ffmpeg.stdin);
					break;

				//Stream from a local file
				case "local":
					fs.createReadStream(this.current.url)
						.pipe(ffmpeg.stdin);

					break;

				//Stream from the internet!
				case "http":
				case "https":
					request(this.current.url)
						.pipe(ffmpeg.stdin);

					break;
				default:
					this.channel.send(`${this.current.type} is not a valid audio provider.`);
					this.skip();
			}

			this.stream = ffmpeg.stdout;

			ffmpeg.stderr.setEncoding('utf8');
			ffmpeg.stderr.on('data', function(data) {
				if(/^execvp\(\)/.test(data)) {
					console.log('failed to start ' + argv.ffmpeg);
					throw "FFMPEG failed!";
				}
			});
		} catch(e) {
			this.channel.send(`${e.message} - Skipping...`);
			this.play();
		}

	}
	this.add = function(type, url, title, thumb) {
		//Push a JSON string into the array
		this.playlist.push({
			type: type,
			url: url,
			title: title,
			thumb_url: thumb
		});

		//If the bot is not playing, enter the channel and start playing
		if (!this.voicechannel.connection) {
			this.connect();
		}
	}
	this.skip = function() {
		if (this.pid) process.kill(this.pid, "SIGINT");
		this.pid = null;
	}
	this.stop = function() {
		this.skip();
		this.current = {};
		this.playlist = [];
	}
}

process.on("unhandledRejection", function(err) {
	console.log("Uncaught Promise Error: \n" + err.stack);
});
{'fraction_non_alphanumeric': 0.16607836216025415, 'fraction_numerical': 0.0014119308153900459, 'mean_word_length': 2.8577263444520082, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 10, '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': '98404', 'n_tokens_mistral': 2354, 'n_tokens_neox': 1933, 'n_words': 461}