Skip to content

Commit

Permalink
Fixes #235
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyLB committed Oct 28, 2024
1 parent 1d148bb commit feb269d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
16 changes: 8 additions & 8 deletions include/function_caller.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ function execCMD($cmd)
$retval = null;
$output = null;

if (isAvailable('system')) {
$output = system($cmd, $retval);
$logger->info('system('.$cmd.') returns '.$output.', retval: '.$retval);
return $retval;
}
else if (isAvailable('exec')) {
if (isAvailable('exec')) {
exec($cmd, $output, $retval);
$outputStr = implode(',', $output);
$logger->info('exec('.$cmd.') returns '.$outputStr.', retval: '.$retval);
$logger->debug('exec('.$cmd.') returns "'.$outputStr.'", retval: '.$retval);
return $retval;
}
else if (isAvailable('system')) {
$output = system($cmd, $retval);
$logger->debug('system('.$cmd.') returns "'.$output.'", retval: '.$retval);
return $retval;
}
return 127;
return -1;
}
47 changes: 29 additions & 18 deletions include/function_dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,51 @@
$warnings[] = "XML library is missing to use mediainfo";
}

// Do the dependencies checks for MediaInfo & FFMPEG & FFPROBE & exiftool
// Do the dependencies checks for MediaInfo & FFmpeg & FFprobe & ExifTool
function check($binary)
{
global $logger;
$retval = 0;
$logger->info(__FUNCTION__.' : checking '.$binary);

$retval = execCMD('exiftool -ver'); // redirect any output
$logger->info(__FUNCTION__.' : checking exiftool -ver, retval: '.$retval);
$retval = execCMD('ffmpeg -version'); // redirect any output
$logger->info(__FUNCTION__.' : checking exiftool -ver, retval: '.$retval);
$retval = execCMD('ffprobe -version'); // redirect any output
$logger->info(__FUNCTION__.' : checking exiftool -ver, retval: '.$retval);

// $logger->debug('checking '.$binary.':');

// Determine appropriate argument
if (str_contains($binary, 'exiftool')) {
$cmd = $binary.' -ver';
}
else if (str_contains($binary, 'ffmpeg') || str_contains($binary, 'ffprobe')) {
$cmd = $binary.' -version';
}
else if (str_contains($binary, 'mediainfo')) {
$cmd = $binary.' --Version';
}
else {
return false;
}

// Execute the test
$retval = 0;
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$retval = execCMD($binary." >NUL 2>NUL"); // redirect any output
} else {
$retval = execCMD($binary." 1>&2 /dev/null"); // redirect any output
$retval = execCMD($cmd.' >NUL 2>NUL'); // redirect any output
}
else {
$retval = execCMD($cmd.' 2>&1 >/dev/null'); // redirect any output
}
if($retval < 2) { // Command found?

// Command found?
if ($retval == 0) {
return true;
} else {
$logger->info(__FUNCTION__.' : system() and exec() unavailable!');
}
else {
$logger->debug('ERROR: Calling '.$binary.' did fail.');
return false;
}
}

/* Concat custom binary directory from local config local/config/config.inc.php */
$sync_binaries = array(
'mediainfo' => isset($conf['vjs_mediainfo_dir']) ? $conf['vjs_mediainfo_dir'].$sync_options['mediainfo'] : $sync_options['mediainfo'],
'exiftool' => isset($conf['vjs_exiftool_dir']) ? $conf['vjs_exiftool_dir'].$sync_options['exiftool'] : $sync_options['exiftool'],
'ffprobe' => isset($conf['vjs_ffprobe_dir']) ? $conf['vjs_ffprobe_dir'].$sync_options['ffprobe'] : $sync_options['ffprobe'],
'ffmpeg' => isset($conf['ffmpeg_dir']) ? $conf['ffmpeg_dir'].$sync_options['ffmpeg'] : $sync_options['ffmpeg'],
'mediainfo' => isset($conf['vjs_mediainfo_dir']) ? $conf['vjs_mediainfo_dir'].$sync_options['mediainfo'] : $sync_options['mediainfo'],
);

// For each external tools try
Expand Down

0 comments on commit feb269d

Please sign in to comment.