<commit_before>var ffmpeg = require('fluent-ffmpeg');
var path = require("path");
var config = require("config");

var TranscodeJobManager = {
	counter: 0,
	running: false,
	jobs: [],
	maxJobs: 1,
	transcode: function(jobConfig) {
		var self = this;
		var fullPath = path.join(config.mythbackend.recordings.path, jobConfig.pathname);
		var outputFilename = makeOutputFilename(jobConfig);
		var outputPath = path.join(config.clips.path, outputFilename);
		console.log(fullPath);
console.log(jobConfig.offset);
console.log(jobConfig.duration);
console.log(outputPath);
		ffmpeg(fullPath).seekInput(jobConfig.offset).duration(jobConfig.duration).audioCodec("aac").videoCodec("libx264").on("end", function() {
			console.log('done with ' + outputPath);
			self.running = false;
			self.runJob();
		}).on("error", function(err) {
			console.log(err);	
		}).save(outputPath);;
	},
	runJob: function() {
		if(this.jobs.length>0 && !this.running) { 
			var job = this.jobs.shift();
			this.running = true;
			this.transcode(job);
		}
		else {
			console.log('all jobs done');
		}
	},
	startJob: function(jobConfig, callback) {
		this.counter++;
		jobConfig.id = this.counter;
		this.jobs.push(jobConfig);
		this.runJob();
		callback(null, {"id":this.counter});
	}
};

function makeOutputFilename(jobConfig) {
	var filename = jobConfig.title.split(" ").join("_") + "-" + jobConfig.starttime + "+" + jobConfig.offset + "+" + jobConfig.duration + ".mp4";
	return filename;
}

module.exports = TranscodeJobManager;
<commit_msg>use uuid for a good time<commit_after>var ffmpeg = require('fluent-ffmpeg');
var path = require("path");
var config = require("config");
var uuid = require("uuid");

var TranscodeJobManager = {
	counter: 0,
	running: false,
	jobs: [],
	maxJobs: 1,
	transcode: function(jobConfig) {
		var self = this;
		var fullPath = path.join(config.mythbackend.recordings.path, jobConfig.pathname);
		var outputFilename = makeOutputFilename(jobConfig);
		var outputPath = path.join(config.clips.path, outputFilename);
		ffmpeg(fullPath).seekInput(jobConfig.offset).duration(jobConfig.duration).audioCodec("aac").videoCodec("libx264").videoBitrate(10000, true).on("end", function() {
			console.log('done with ' + outputPath);
			self.running = false;
			self.runJob();
		}).on("error", function(err) {
			console.log(err);	
		}).save(outputPath);;
	},
	runJob: function() {
		if(this.jobs.length>0 && !this.running) { 
			var job = this.jobs.shift();
			this.running = true;
			this.transcode(job);
		}
		else {
			console.log('all jobs done');
		}
	},
	startJob: function(jobConfig, callback) {
		this.counter++;
		jobConfig.id = uuid.v4();
		this.jobs.push(jobConfig);
		this.runJob();
		callback(null, {"id":jobConfig.id});
	}
};

function makeOutputFilename(jobConfig) {
	return jobConfig.id + ".mp4";
	/*
	var filename = jobConfig.title.split(" ").join("_") + "-" + jobConfig.starttime + "+" + jobConfig.offset + "+" + jobConfig.duration + ".mp4";
	return filename;
	*/
}

module.exports = TranscodeJobManager;

{'fraction_non_alphanumeric': 0.17434537620152468, 'fraction_numerical': 0.0069605568445475635, 'mean_word_length': 4.68361581920904, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '4589428', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1039, 'n_words': 184}