1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 02:39:46 +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,17 +51,17 @@ 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)) {
$sources = getVideosURLOnly($video['filename'], false); $f = convertVideoFileWithFFMPEGIsLockedInfo($mp3File);
if ($f['isUnlocked']) {
$sources = getVideosURLOnly($video['filename'], false);
if (!empty($sources)) { if (!empty($sources)) {
$source = end($sources); $source = end($sources);
convertVideoFileWithFFMPEG($source['url'], $mp3File); convertVideoFileWithFFMPEG($source['url'], $mp3File);
if (file_exists($mp3File)) { if (file_exists($mp3File)) {
return Video::getSourceFile($video['filename'], ".mp3", true); return Video::getSourceFile($video['filename'], ".mp3", true);
}
} }
} }
return false; return false;

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,13 +389,24 @@ 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) {
unlink($paths['path']);
$response = array( $f = convertVideoFileWithFFMPEGIsLockedInfo($paths['path']);
'regular' => $arrayRegular, if ($f['isUnlocked']) {
'lower' => $arrayLower, unlink($paths['path']);
'isValid' => false, $response = array(
'msg' => "Length does not match (Video/MP3) video = {$videoDuration} seconds MP3 = $durationInSeconds seconds", '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; return $response;
} }