1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 10:49:36 +02:00
This commit is contained in:
Daniel Neto 2024-03-21 14:49:24 -03:00
parent 6b8972be8e
commit 12d27b37c7
3 changed files with 49 additions and 25 deletions

View file

@ -223,15 +223,28 @@ function getDirSize($dir, $forceNew = false)
} }
} }
function convertVideoFileWithFFMPEG($fromFileLocation, $toFileLocation, $logFile = '', $try = 0) function convertVideoFileWithFFMPEGIsLockedInfo($toFileLocation){
{
$localFileLock = $toFileLocation. ".lock"; $localFileLock = $toFileLocation. ".lock";
$ageInSeconds = time() - @filemtime($localFileLock); $ageInSeconds = time() - @filemtime($localFileLock);
if ($ageInSeconds > 300) { $isOld = $ageInSeconds > 300;
_error_log("convertVideoFileWithFFMPEG: age: {$ageInSeconds} too long without change, unlock it " . $fromFileLocation. ' '.json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))); $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); @unlink($localFileLock);
} elseif (file_exists($localFileLock)) { } elseif ($f['file_exists']) {
_error_log("convertVideoFileWithFFMPEG: age: {$ageInSeconds} download from CDN There is a process running for {$fromFileLocation} localFileLock=$localFileLock log=$logFile"); _error_log("convertVideoFileWithFFMPEG: age: {$f['ageInSeconds']} download from CDN There is a process running for {$fromFileLocation} localFileLock=$localFileLock log=$logFile");
return false; return false;
} else { } else {
_error_log("convertVideoFileWithFFMPEG: creating file: localFileLock: {$localFileLock} toFileLocation: {$toFileLocation}"); _error_log("convertVideoFileWithFFMPEG: creating file: localFileLock: {$localFileLock} toFileLocation: {$toFileLocation}");

View file

@ -51,10 +51,9 @@ function convertVideoToMP3FileIfNotExists($videos_id)
$paths = Video::getPaths($video['filename']); $paths = Video::getPaths($video['filename']);
$mp3File = "{$paths['path']}{$video['filename']}.mp3"; $mp3File = "{$paths['path']}{$video['filename']}.mp3";
if (file_exists($mp3File) && filesize($mp3File)<100) {
unlink($mp3File);
}
if (!file_exists($mp3File)) { if (!file_exists($mp3File)) {
$f = convertVideoFileWithFFMPEGIsLockedInfo($mp3File);
if ($f['isUnlocked']) {
$sources = getVideosURLOnly($video['filename'], false); $sources = getVideosURLOnly($video['filename'], false);
if (!empty($sources)) { if (!empty($sources)) {
@ -64,6 +63,7 @@ function convertVideoToMP3FileIfNotExists($videos_id)
return Video::getSourceFile($video['filename'], ".mp3", true); return Video::getSourceFile($video['filename'], ".mp3", true);
} }
} }
}
return false; return false;
} else { } else {
return Video::getSourceFile($video['filename'], ".mp3", true); return Video::getSourceFile($video['filename'], ".mp3", true);

View file

@ -377,10 +377,10 @@ class AI extends PluginAbstract
$paths = self::getMP3Path($videos_id); $paths = self::getMP3Path($videos_id);
if (!empty($paths)) { if (!empty($paths)) {
if(filesize($paths['path'])<20){ if (filesize($paths['path']) < 20) {
// it is a dummy file, try the Storage URL // it is a dummy file, try the Storage URL
$duration = getDurationFromFile($paths['url']); $duration = getDurationFromFile($paths['url']);
}else{ } else {
$duration = getDurationFromFile($paths['path']); $duration = getDurationFromFile($paths['path']);
} }
@ -389,6 +389,9 @@ class AI extends PluginAbstract
$videoDuration = $video->getDuration_in_seconds(); $videoDuration = $video->getDuration_in_seconds();
$diff = abs($videoDuration - $durationInSeconds); $diff = abs($videoDuration - $durationInSeconds);
if ($diff > 2) { if ($diff > 2) {
$f = convertVideoFileWithFFMPEGIsLockedInfo($paths['path']);
if ($f['isUnlocked']) {
unlink($paths['path']); unlink($paths['path']);
$response = array( $response = array(
'regular' => $arrayRegular, 'regular' => $arrayRegular,
@ -396,6 +399,14 @@ class AI extends PluginAbstract
'isValid' => false, 'isValid' => false,
'msg' => "Length does not match (Video/MP3) video = {$videoDuration} seconds MP3 = $durationInSeconds seconds", '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; return $response;
} }