<commit_before>const ytdl = require('ytdl-core');
const fs = require('fs');
const search = require('youtube-search')
const youtubeAPI = require('../config/botLogin').youtubeAPI;

module.exports.search = function(message, callback) {
	var opts = {
	  maxResults: 5,
	  key: youtubeAPI
	};
	 
	search(message, opts, function(error, results) {
	 	if(err) return callback(error);
	 		 	
	 	if(results){
			var firstResult = results[0];
			callback(null, firstResult.id, firstResult.title, firstResult.link);
	 	}
	});
	
}

var ytdl_options = {
	quality: 'highest',
	filter: 'audioonly'
}

module.exports.getInfo = function(url, callback){
	ytdl.getInfo(url, ytdl_options, (error, rawData) =>{
		if(error) return callback(error);
		callback(null, rawData, rawData.video_id, rawData.title, rawData.length_seconds);
	});
}

	
module.exports.getStream = function(url,callback){
	callback(ytdl(url, ytdl_options));
}

module.exports.getFile = function(error, url, path, callback){
	try{
		if(fs.existsSync(path)){
			callback(null);
		}else{
			ytdl(url, ytdl_options).pipe(fs.createWriteStream(path))
			 .on('finish', ()=>{
				callback(null);
			 });
		}	
	} catch(error){
		if(error) return callback(error);
	}
}<commit_msg>Fixed YT module<commit_after>const ytdl = require('ytdl-core');
const fs = require('fs');
const path = require('path');
const search = require('youtube-search')
const youtubeAPI = require(path.join(path.resolve(__dirname, '..'), 'config/botLogin')).youtubeAPI;

module.exports.search = function(message, callback) {
	var opts = {
	  maxResults: 5,
	  key: youtubeAPI
	};
	 
	search(message, opts, function(error, results) {
	 	if(error) callback(error);
	 		 	
	 	if(results){
			var firstResult = results[0];
			callback(null, firstResult.id, firstResult.title, firstResult.link);
	 	}
	});
	
}

var ytdl_options = {
	quality: 'highest',
	filter: 'audioonly'
}

module.exports.getInfo = function(url, callback){
	ytdl.getInfo(url, ytdl_options, (error, rawData) =>{
		if(error) return callback(error);
		callback(null, rawData, rawData.video_id, rawData.title, rawData.length_seconds);
	});
}

	
module.exports.getStream = function(url,callback){
	callback(ytdl(url, ytdl_options));
}

module.exports.getFile = function(url, path, callback){
	if(fs.existsSync(path)){
		callback();
	}else{
		ytdl(url, ytdl_options).pipe(fs.createWriteStream(path))
		 .on('finish', ()=>{
			callback();
		 });
	}	
}
{'fraction_non_alphanumeric': 0.1649441918147995, 'fraction_numerical': 0.0016535758577924762, 'mean_word_length': 4.761904761904762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3782192', 'n_tokens_mistral': 928, 'n_tokens_neox': 834, 'n_words': 155}