<commit_before>/*jslint node: true */
"use strict";

var Util = require('util');
var child_process = require('child_process');
var Events = require('events');
var fs = require('fs');
var assert = require('assert');
var Path = require('path');
const debug = require('debug')('omxplayer');

var DBus = require('dbus-native');

var invokeSemaphore = require('semaphore')(1);

var NO_CACHE_CONTROL = "no-cache, private, no-store, must-revalidate, max-stale=0, max-age=1, post-check=0, pre-check=0";

var DEFAULT_DBUS_ADDRESS_FILENAME = "/tmp/omxplayerdbus";

var DEFAULT_DESTINATION = 'org.mpris.MediaPlayer2.omxplayer';
var DEFAULT_PATH = '/org/mpris/MediaPlayer2';
var DBUS_INTERFACE_PROPERTIES = 'org.freedesktop.DBus.Properties';
var OMXPLAYER_DBUS_INTERFACE_PLAYER = 'org.mpris.MediaPlayer2.Player';

var dbusIdentifier = 0;

function OMXPlayer(configuration) {
	Events.EventEmitter.call(this);

	configuration = configuration || {};

	this._configuration = configuration;

	this._log = configuration.log || console.log;
	this._error = configuration.error || console.error;

	this.dbusPath = configuration.dbusPath || DEFAULT_PATH;
	this.dbusDestination = configuration.dbusDestination || DEFAULT_DESTINATION;
	this.poolIntervalMs = configuration.poolIntervalMs || 1000;

	configuration.omxPlayerPath = configuration.omxPlayerPath || "omxplayer";

	this._liveProperties = configuration.liveProperties || [ "Volume", "Position", "PlaybackStatus" ];

	configuration.expressPath = configuration.expressPath || "/omx";
	this.express = this._express.bind(this);

	this.properties = {
		Volume: 0,
		Position: -1,
		PlaybackStatus: "Stopped"
	};

	var self = this;
	process.on('exit', function(code) {
		var omxProcess = self._omxProcess;
		if (!omxProcess) {
			return;
		}
		self._omxProcess = undefined;

		self._log("Kill processus");

		try {
			omxProcess.kill('SIGKILL');
			omxProcess.disconnect();
		} catch (x) {
			self._error("EXIT event: kill omxProcess error", x);
		}
	});
}

Util.inherits(OMXPlayer, Events.EventEmitter);
module.exports = OMXPlayer;

OMXPlayer.prototype.stream = function(stream, options, callback) {
	if (!stream) {
		throw new Error("Stream is NULL");
	}
	if (typeof (options) === "function") {
		callback = options;
		options = null;
	}

	if (!options) {
		options = {};
	}

	options.spawnOptions = options.spawnOptions || {};

	options.spawnOptions.stdio = [ stream, "pipe", "pipe" ];

	return this.start("pipe:0", options, callback);
};

OMXPlayer.prototype.start = function(moviePath, options, callback) {
	var configuration = this._configuration;

	if (typeof (options) === "function") {
		callback = options;
		options = null;
	}
	if (!options) {
		options = {};
	}

	var self = this;

	this.stop(function(error) {

		if (!moviePath) {
			if (!callback) {
				return;
			}
			return callback();
		}

		if (configuration.omxPlayerPath) {
			var parameters = [ "--no-keys" ];
			if (configuration.omxPlayerParams) {
				parameters = parameters.concat(configuration.omxPlayerParams);
			}
			if (configuration.blank) {
				parameters.push('-b');
			}
			if (configuration.genlog) {
				parameters.push('--genlog');
			}<commit_msg>Update omxplayer.js<commit_after>/*jslint node: true */
"use strict";

var Util = require('util');
var child_process = require('child_process');
var Events = require('events');
var fs = require('fs');
var assert = require('assert');
var Path = require('path');
const debug = require('debug')('omxplayer');

var DBus = require('dbus-native');

var invokeSemaphore = require('semaphore')(1);

var NO_CACHE_CONTROL = "no-cache, private, no-store, must-revalidate, max-stale=0, max-age=1, post-check=0, pre-check=0";

var DEFAULT_DBUS_ADDRESS_FILENAME = "/tmp/omxplayerdbus";

var DEFAULT_DESTINATION = 'org.mpris.MediaPlayer2.omxplayer';
var DEFAULT_PATH = '/org/mpris/MediaPlayer2';
var DBUS_INTERFACE_PROPERTIES = 'org.freedesktop.DBus.Properties';
var OMXPLAYER_DBUS_INTERFACE_PLAYER = 'org.mpris.MediaPlayer2.Player';

var dbusIdentifier = 0;

function OMXPlayer(configuration) {
	Events.EventEmitter.call(this);

	configuration = configuration || {};

	this._configuration = configuration;

	this._log = configuration.log || console.log;
	this._error = configuration.error || console.error;

	this.dbusPath = configuration.dbusPath || DEFAULT_PATH;
	this.dbusDestination = configuration.dbusDestination || DEFAULT_DESTINATION;
	this.poolIntervalMs = configuration.poolIntervalMs || 1000;

	configuration.omxPlayerPath = configuration.omxPlayerPath || "omxplayer";

	this._liveProperties = configuration.liveProperties || [ "Volume", "Position", "PlaybackStatus" ];

	configuration.expressPath = configuration.expressPath || "/omx";
	this.express = this._express.bind(this);

	this.properties = {
		Volume: 0,
		Position: -1,
		PlaybackStatus: "Stopped"
	};

	var self = this;
	process.on('exit', function(code) {
		var omxProcess = self._omxProcess;
		if (!omxProcess) {
			return;
		}
		self._omxProcess = undefined;

		self._log("Kill processus");

		try {
			omxProcess.kill('SIGKILL');
			omxProcess.disconnect();
		} catch (x) {
			self._error("EXIT event: kill omxProcess error", x);
		}
	});
}

Util.inherits(OMXPlayer, Events.EventEmitter);
module.exports = OMXPlayer;

OMXPlayer.prototype.stream = function(stream, options, callback) {
	if (!stream) {
		throw new Error("Stream is NULL");
	}
	if (typeof (options) === "function") {
		callback = options;
		options = null;
	}

	if (!options) {
		options = {};
	}

	options.spawnOptions = options.spawnOptions || {};

	options.spawnOptions.stdio = [ stream, "pipe", "pipe" ];

	return this.start("pipe:0", options, callback);
};

OMXPlayer.prototype.start = function(moviePath, options, callback) {
	var configuration = this._configuration;

	if (typeof (options) === "function") {
		callback = options;
		options = null;
	}
	if (!options) {
		options = {};
	}

	var self = this;

	this.stop(function(error) {

		if (!moviePath) {
			if (!callback) {
				return;
			}
			return callback();
		}

		if (configuration.omxPlayerPath) {
			var parameters = [ "--no-keys" ];
			if (configuration.omxPlayerParams) {
				parameters = parameters.concat(configuration.omxPlayerParams);
			}
			
			//ADD WINDOW POSITION
			if (configuration.position) {
				parameters.push('--win', '"' + configuration.position + '"');
			}
			
			if (configuration.blank) {
				parameters.push('-b');
			}
			if (configuration.genlog) {
				parameters.push('--genlog');
			}
{'fraction_non_alphanumeric': 0.15082676556946376, 'fraction_numerical': 0.004945139854736517, 'mean_word_length': 4.5316239316239315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6670711', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2107, 'n_words': 424}