From 12d27b37c77eb66e94c35a024eca122067b2724f Mon Sep 17 00:00:00 2001 From: Daniel Neto Date: Thu, 21 Mar 2024 14:49:24 -0300 Subject: [PATCH] Update --- objects/functionsExec.php | 25 +++++++++++++++++++------ objects/functionsFFMPEG.php | 20 ++++++++++---------- plugin/AI/AI.php | 29 ++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/objects/functionsExec.php b/objects/functionsExec.php index 5f2dc88066..72824b42ab 100644 --- a/objects/functionsExec.php +++ b/objects/functionsExec.php @@ -223,15 +223,28 @@ function getDirSize($dir, $forceNew = false) } } -function convertVideoFileWithFFMPEG($fromFileLocation, $toFileLocation, $logFile = '', $try = 0) -{ +function convertVideoFileWithFFMPEGIsLockedInfo($toFileLocation){ $localFileLock = $toFileLocation. ".lock"; $ageInSeconds = time() - @filemtime($localFileLock); - if ($ageInSeconds > 300) { - _error_log("convertVideoFileWithFFMPEG: age: {$ageInSeconds} too long without change, unlock it " . $fromFileLocation. ' '.json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))); + $isOld = $ageInSeconds > 300; + $file_exists = file_exists($localFileLock); + return array( + 'ageInSeconds'=>$ageInSeconds, + 'isOld'=>$isOld , + 'file_exists'=>file_exists($localFileLock), + 'localFileLock'=>$localFileLock, + 'isUnlocked'=>$isOld || !$file_exists, + ); +} +function convertVideoFileWithFFMPEG($fromFileLocation, $toFileLocation, $logFile = '', $try = 0) +{ + $f = convertVideoFileWithFFMPEGIsLockedInfo($toFileLocation); + $localFileLock = $f['localFileLock']; + if ($f['isOld']) { + _error_log("convertVideoFileWithFFMPEG: age: {$f['ageInSeconds']} too long without change, unlock it " . $fromFileLocation. ' '.json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))); @unlink($localFileLock); - } elseif (file_exists($localFileLock)) { - _error_log("convertVideoFileWithFFMPEG: age: {$ageInSeconds} download from CDN There is a process running for {$fromFileLocation} localFileLock=$localFileLock log=$logFile"); + } elseif ($f['file_exists']) { + _error_log("convertVideoFileWithFFMPEG: age: {$f['ageInSeconds']} download from CDN There is a process running for {$fromFileLocation} localFileLock=$localFileLock log=$logFile"); return false; } else { _error_log("convertVideoFileWithFFMPEG: creating file: localFileLock: {$localFileLock} toFileLocation: {$toFileLocation}"); diff --git a/objects/functionsFFMPEG.php b/objects/functionsFFMPEG.php index fca79bec61..4054eed97d 100644 --- a/objects/functionsFFMPEG.php +++ b/objects/functionsFFMPEG.php @@ -51,17 +51,17 @@ function convertVideoToMP3FileIfNotExists($videos_id) $paths = Video::getPaths($video['filename']); $mp3File = "{$paths['path']}{$video['filename']}.mp3"; - if (file_exists($mp3File) && filesize($mp3File)<100) { - unlink($mp3File); - } if (!file_exists($mp3File)) { - $sources = getVideosURLOnly($video['filename'], false); - - if (!empty($sources)) { - $source = end($sources); - convertVideoFileWithFFMPEG($source['url'], $mp3File); - if (file_exists($mp3File)) { - return Video::getSourceFile($video['filename'], ".mp3", true); + $f = convertVideoFileWithFFMPEGIsLockedInfo($mp3File); + if ($f['isUnlocked']) { + $sources = getVideosURLOnly($video['filename'], false); + + if (!empty($sources)) { + $source = end($sources); + convertVideoFileWithFFMPEG($source['url'], $mp3File); + if (file_exists($mp3File)) { + return Video::getSourceFile($video['filename'], ".mp3", true); + } } } return false; diff --git a/plugin/AI/AI.php b/plugin/AI/AI.php index 1fe102f9a2..0bfa3950df 100644 --- a/plugin/AI/AI.php +++ b/plugin/AI/AI.php @@ -377,10 +377,10 @@ class AI extends PluginAbstract $paths = self::getMP3Path($videos_id); if (!empty($paths)) { - if(filesize($paths['path'])<20){ + if (filesize($paths['path']) < 20) { // it is a dummy file, try the Storage URL $duration = getDurationFromFile($paths['url']); - }else{ + } else { $duration = getDurationFromFile($paths['path']); } @@ -389,13 +389,24 @@ class AI extends PluginAbstract $videoDuration = $video->getDuration_in_seconds(); $diff = abs($videoDuration - $durationInSeconds); if ($diff > 2) { - unlink($paths['path']); - $response = array( - 'regular' => $arrayRegular, - 'lower' => $arrayLower, - 'isValid' => false, - 'msg' => "Length does not match (Video/MP3) video = {$videoDuration} seconds MP3 = $durationInSeconds seconds", - ); + + $f = convertVideoFileWithFFMPEGIsLockedInfo($paths['path']); + if ($f['isUnlocked']) { + unlink($paths['path']); + $response = array( + 'regular' => $arrayRegular, + 'lower' => $arrayLower, + 'isValid' => false, + 'msg' => "Length does not match (Video/MP3) video = {$videoDuration} seconds MP3 = $durationInSeconds seconds", + ); + } else { + $response = array( + 'regular' => $arrayRegular, + 'lower' => $arrayLower, + 'isValid' => true, + 'msg' => "The MP3 file is processing", + ); + } return $response; }