From 8a6a1f448b78d0cfb14587d0d94e936d9f002723 Mon Sep 17 00:00:00 2001 From: Daniel Neto Date: Wed, 20 Nov 2024 11:12:09 -0300 Subject: [PATCH] https://github.com/WWBN/AVideo/issues/9597 --- .gitignore | 4 ++- feed/mrss.php | 49 ++++++++++++++++++++++++----------- objects/Object.php | 2 ++ objects/functions.php | 4 +-- objects/functionsAVideo.php | 19 +++++++++++++- objects/functionsFFMPEG.php | 25 +++++++++++++----- objects/functionsFile.php | 23 +++++++++++++++- objects/functionsSecurity.php | 6 +++++ plugin/Live/Live.php | 4 +-- 9 files changed, 108 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 82445aaf6d..e9ca56c9d7 100644 --- a/.gitignore +++ b/.gitignore @@ -106,4 +106,6 @@ plugin/WebAuthnLogin/ plugin/UserOTPLogin/ test* CreatePlugin/plugins/ -vendor/james-heinrich/getid3/demos/ \ No newline at end of file +vendor/james-heinrich/getid3/demos/ +AVideoStorage/ +plugin/HLSOverlay/ \ No newline at end of file diff --git a/feed/mrss.php b/feed/mrss.php index 4fa5efb0d8..1b7a86cab6 100644 --- a/feed/mrss.php +++ b/feed/mrss.php @@ -5,25 +5,36 @@ header("Content-Type: application/rss+xml;"); $cacheFeedName = "feedCacheMRSS" . json_encode($_REQUEST); $lifetime = 43200; $feed = ObjectYPT::getCache($cacheFeedName, $lifetime); +$link = "{$link}/mrss"; if (empty($feed)) { _ob_start(); echo''; ?> + xmlns:gml="http://www.opengis.net/gml" + xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" + xmlns:atom="http://www.w3.org/2005/Atom" > + " rel="self" type="application/rss+xml" /> + <?php echo feedText($title); ?> - - - <?php echo feedText($title); ?> - - - 144 - 40 - AVideo version rss - + + en-us + + no + + + + + <?php echo feedText($title); ?> + + + 144 + 40 + AVideo version rss + '; + $enclosure = ''; break; } } ?> <?php echo feedText($row['title']); ?> - + ]]> @@ -59,8 +80,6 @@ if (empty($feed)) { ]]> - - diff --git a/objects/Object.php b/objects/Object.php index a8c105f984..2b4e3e76b7 100644 --- a/objects/Object.php +++ b/objects/Object.php @@ -1152,6 +1152,7 @@ abstract class CacheHandler if(isCommandLineInterface()){ echo "public function setCache({$this->suffix}) name=".$name.PHP_EOL; + //echo json_encode(debug_backtrace()); } $return = ObjectYPT::setCacheGlobal($name, $value); /* @@ -1172,6 +1173,7 @@ abstract class CacheHandler $name = $this->getCacheName($this->suffix); if(isCommandLineInterface()){ echo "public function getCache($suffix) name=".$name.PHP_EOL; + //echo json_encode(debug_backtrace()); } if (isset($_getCache[$name])) { if ($logInfo) { diff --git a/objects/functions.php b/objects/functions.php index d9646db413..c02be0b118 100644 --- a/objects/functions.php +++ b/objects/functions.php @@ -959,9 +959,9 @@ function getVideosURLAudio($fileName, $fileNameisThePath = false) return $files; } -function getVideosURL($fileName, $cache = true) +function getVideosURL($fileName, $recreateCache = false) { - return getVideosURL_V2($fileName); // disable this function soon + return getVideosURL_V2($fileName, $recreateCache); // disable this function soon } function getVideosURLMP4Only($fileName) diff --git a/objects/functionsAVideo.php b/objects/functionsAVideo.php index ca94be87ae..be863f5ae8 100644 --- a/objects/functionsAVideo.php +++ b/objects/functionsAVideo.php @@ -162,10 +162,27 @@ function getSelfUserAgent() { global $global, $AVideoStreamer_UA; $agent = $AVideoStreamer_UA . "_"; - $agent .= md5($global['salt']); + $agent .= md5($global['salt'].date('i')); return $agent; } +function isSelfUserAgent() +{ + global $global, $AVideoStreamer_UA; + + // Generate the current and 1-minute previous user agent strings + $currentAgent = $AVideoStreamer_UA . "_" . md5($global['salt'] . date('i')); + $previousAgent = $AVideoStreamer_UA . "_" . md5($global['salt'] . date('i', strtotime('-1 minute'))); + + // Check if the provided user agent matches either the current or previous + if ($_SERVER['HTTP_USER_AGENT'] === $currentAgent || $_SERVER['HTTP_USER_AGENT'] === $previousAgent) { + return true; + } + + return false; +} + + function requestComesFromSameDomainAsMyAVideo() { global $global; diff --git a/objects/functionsFFMPEG.php b/objects/functionsFFMPEG.php index ed45e44520..b43b398d5c 100644 --- a/objects/functionsFFMPEG.php +++ b/objects/functionsFFMPEG.php @@ -37,7 +37,6 @@ function get_ffprobe() function convertVideoToMP3FileIfNotExists($videos_id, $forceTry = 0) { - _error_log("convertVideoToMP3FileIfNotExists: start videos_id=$videos_id try=$forceTry "); global $global; if (!empty($global['disableMP3'])) { _error_log('convertVideoToMP3FileIfNotExists: $global[disableMP3] isset'); @@ -62,6 +61,7 @@ function convertVideoToMP3FileIfNotExists($videos_id, $forceTry = 0) }else { $f = convertVideoFileWithFFMPEGIsLockedInfo($mp3File); if ($f['isUnlocked']) { + _error_log("convertVideoToMP3FileIfNotExists: start videos_id=$videos_id try=$forceTry "); $sources = getVideosURLOnly($video['filename'], false); if (!empty($sources)) { if(!empty($sources['m3u8'])){ @@ -137,14 +137,21 @@ function cleanupDownloadsDirectory($resolution = 720) } } -function m3u8ToMP4($input) +function m3u8ToMP4($input, $makeItPermanent = false) { $videosDir = getVideosDir(); $outputfilename = str_replace($videosDir, "", $input); $parts = explode("/", $outputfilename); $resolution = Video::getResolutionFromFilename($input); - $outputfilename = $parts[0] . "_{$resolution}_.mp4"; - $outputpathDir = "{$videosDir}downloads/"; + $video_filename = $parts[count($parts)-2]; + if($makeItPermanent){ + $outputfilename = "index.mp4"; + $outputpathDir = "{$videosDir}{$video_filename}/"; + }else{ + $outputfilename = $video_filename . "_{$resolution}_.mp4"; + $outputpathDir = "{$videosDir}downloads/"; + } + //var_dump($outputfilename, $parts, $outputpathDir);exit; make_path($outputpathDir); $outputpath = "{$outputpathDir}{$outputfilename}"; $msg = ''; @@ -166,7 +173,7 @@ function m3u8ToMP4($input) $token = getToken(60); $filepath = addQueryStringParameter($filepath, 'globalToken', $token); } else { - $filepath = escapeshellcmd($input); + $filepath = escapeshellcmdURL($input); } if (is_dir($filepath)) { @@ -185,7 +192,13 @@ function m3u8ToMP4($input) _error_log($msg3); return ['error' => $error, 'msg' => $finalMsg]; } else { - return $return; + return [ + 'error' => false, + 'msg' => implode(', ', $return['output']), + 'path' => $return['toFileLocation'], + 'filename' => basename($return['toFileLocation']), + 'return' => $return + ]; } } else { $msg = "downloadHLS: outputpath already exists ({$outputpath})"; diff --git a/objects/functionsFile.php b/objects/functionsFile.php index d648f451be..cbaac4d3d1 100644 --- a/objects/functionsFile.php +++ b/objects/functionsFile.php @@ -1089,4 +1089,25 @@ function getVideosDirectoryUsageInfo() { 'used_percentage' => $usedPercentageFormatted, 'used_percentage_number' => $usedPercentage ]; -} \ No newline at end of file +} + +function findMP4File($folderPath) +{ + // Ensure the folder path ends with a slash + $folderPath = addLastSlash($folderPath); + + // Open the folder and iterate over files + if (is_dir($folderPath)) { + $files = scandir($folderPath); + foreach ($files as $file) { + // Check if the file has a .mp4 extension + if (pathinfo($file, PATHINFO_EXTENSION) === 'mp4') { + // Return the absolute path to the first .mp4 file found + return $folderPath . $file; + } + } + } + + // Return false if no .mp4 file is found + return false; +} diff --git a/objects/functionsSecurity.php b/objects/functionsSecurity.php index 21c092c201..682fd50ed7 100644 --- a/objects/functionsSecurity.php +++ b/objects/functionsSecurity.php @@ -501,3 +501,9 @@ function ddosProtection() return true; } + +function escapeshellcmdURL(string $command) +{ + return str_replace('\?', '?', escapeshellcmd($command)); +} + diff --git a/plugin/Live/Live.php b/plugin/Live/Live.php index 387055d669..a16d649eac 100644 --- a/plugin/Live/Live.php +++ b/plugin/Live/Live.php @@ -48,8 +48,8 @@ class Live extends PluginAbstract $desc .= "
You MUST update your LiveUsers plugin to version 2.0 or greater
"; } } - $desc .= "
Start Self hosted WebRTC server: php {$global['systemRootPath']}plugin/Live/standAloneFiles/WebRTCServer/server.php "; - $desc .= "
Help"; + //$desc .= "
Start Self hosted WebRTC server: php {$global['systemRootPath']}plugin/Live/standAloneFiles/WebRTCServer/server.php "; + //$desc .= "
Help"; return $desc; }