1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00
Daniel Neto 2024-11-20 11:12:09 -03:00
parent 95d3dfc895
commit 8a6a1f448b
9 changed files with 108 additions and 28 deletions

2
.gitignore vendored
View file

@ -107,3 +107,5 @@ plugin/UserOTPLogin/
test* test*
CreatePlugin/plugins/ CreatePlugin/plugins/
vendor/james-heinrich/getid3/demos/ vendor/james-heinrich/getid3/demos/
AVideoStorage/
plugin/HLSOverlay/

View file

@ -5,16 +5,28 @@ header("Content-Type: application/rss+xml;");
$cacheFeedName = "feedCacheMRSS" . json_encode($_REQUEST); $cacheFeedName = "feedCacheMRSS" . json_encode($_REQUEST);
$lifetime = 43200; $lifetime = 43200;
$feed = ObjectYPT::getCache($cacheFeedName, $lifetime); $feed = ObjectYPT::getCache($cacheFeedName, $lifetime);
$link = "{$link}/mrss";
if (empty($feed)) { if (empty($feed)) {
_ob_start(); _ob_start();
echo'<?xml version="1.0" encoding="UTF-8"?>'; ?> echo'<?xml version="1.0" encoding="UTF-8"?>'; ?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"
xmlns:georss="http://www.georss.org/georss" xmlns:georss="http://www.georss.org/georss"
xmlns:gml="http://www.opengis.net/gml"> 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" >
<channel> <channel>
<atom:link href="<?php echo $global['webSiteRootURL'] . ltrim($_SERVER["REQUEST_URI"], "/"); ?>" rel="self" type="application/rss+xml" />
<title><?php echo feedText($title); ?></title> <title><?php echo feedText($title); ?></title>
<description><?php echo feedText($description); ?></description> <description><?php echo feedText($description); ?></description>
<link><?php echo $link; ?></link> <link><?php echo $global['webSiteRootURL']; ?></link>
<language>en-us</language>
<itunes:image href="<?php echo $logo; ?>" />
<itunes:explicit>no</itunes:explicit>
<itunes:category text="Technology" />
<image> <image>
<title><?php echo feedText($title); ?></title> <title><?php echo feedText($title); ?></title>
<url><?php echo $logo; ?></url> <url><?php echo $logo; ?></url>
@ -23,7 +35,6 @@ if (empty($feed)) {
<height>40</height> <height>40</height>
<description>AVideo version rss</description> <description>AVideo version rss</description>
</image> </image>
<?php <?php
foreach ($rows as $row) { foreach ($rows as $row) {
$video = Video::getVideoFromFileName($row['filename']); $video = Video::getVideoFromFileName($row['filename']);
@ -36,18 +47,28 @@ if (empty($feed)) {
foreach ($files as $value) { foreach ($files as $value) {
if ($value["type"] === "video" && file_exists($value['path'])) { if ($value["type"] === "video" && file_exists($value['path'])) {
$path_parts = pathinfo($value['path']); $path_parts = pathinfo($value['path']);
if($path_parts['extension'] === 'm3u8'){
$resp = VideoHLS::convertM3U8ToMP4($row['id']);
if(!empty($resp)){
$value['url'] = $resp['url'];
$value['path'] = $resp['path'];
$value['mime'] = "video/mp4";
}
}else{
$value['mime'] = "video/{$path_parts['extension']}"; $value['mime'] = "video/{$path_parts['extension']}";
}
$value['size'] = filesize($value['path']); $value['size'] = filesize($value['path']);
// replace to validate // replace to validate
$value['url'] = str_replace("http://", "https://", $value['url']); $value['url'] = str_replace("http://", "https://", $value['url']);
$enclosure = '<enclosure url="' . $value['url'] . '" length="' . $value['size'] . '" type="' . $value['mime'] . '" />'; $enclosure = '<enclosure url="' . str_replace('&', '&amp;', $value['url']) . '" length="' . $value['size'] . '" type="' . $value['mime'] . '" />';
break; break;
} }
} ?> } ?>
<item> <item>
<title><?php echo feedText($row['title']); ?></title> <title><?php echo feedText($row['title']); ?></title>
<description><?php echo feedText($row['title']); ?></description> <description><?php echo feedText($row['title']); ?></description>
<link> <?php echo Video::getLink($row['id'], $row['clean_title']); ?></link> <link><![CDATA[<?php echo Video::getLink($row['id'], $row['clean_title']); ?>]]></link>
<?php echo $enclosure; ?> <?php echo $enclosure; ?>
<pubDate><?php echo date('r', strtotime($row['created'])); ?></pubDate> <pubDate><?php echo date('r', strtotime($row['created'])); ?></pubDate>
<guid isPermaLink="true"><?php echo Video::getLinkToVideo($row['id'], $row['clean_title'], false, "permalink"); ?></guid> <guid isPermaLink="true"><?php echo Video::getLinkToVideo($row['id'], $row['clean_title'], false, "permalink"); ?></guid>
@ -59,8 +80,6 @@ if (empty($feed)) {
<media:description type="html"><![CDATA[<?php echo Video::htmlDescription($row['title']); ?>]]></media:description> <media:description type="html"><![CDATA[<?php echo Video::htmlDescription($row['title']); ?>]]></media:description>
<media:thumbnail url="<?php echo Video::getPoster($row['id']); ?>" /> <media:thumbnail url="<?php echo Video::getPoster($row['id']); ?>" />
</media:content> </media:content>
<media:embed url="<?php echo str_replace('&', '&amp;', Video::getLinkToVideo($row['id'], $row['clean_title'], true)); ?>"/>
<media:status state="active" />
</item> </item>
<?php <?php
} ?> } ?>

View file

@ -1152,6 +1152,7 @@ abstract class CacheHandler
if(isCommandLineInterface()){ if(isCommandLineInterface()){
echo "public function setCache({$this->suffix}) name=".$name.PHP_EOL; echo "public function setCache({$this->suffix}) name=".$name.PHP_EOL;
//echo json_encode(debug_backtrace());
} }
$return = ObjectYPT::setCacheGlobal($name, $value); $return = ObjectYPT::setCacheGlobal($name, $value);
/* /*
@ -1172,6 +1173,7 @@ abstract class CacheHandler
$name = $this->getCacheName($this->suffix); $name = $this->getCacheName($this->suffix);
if(isCommandLineInterface()){ if(isCommandLineInterface()){
echo "public function getCache($suffix) name=".$name.PHP_EOL; echo "public function getCache($suffix) name=".$name.PHP_EOL;
//echo json_encode(debug_backtrace());
} }
if (isset($_getCache[$name])) { if (isset($_getCache[$name])) {
if ($logInfo) { if ($logInfo) {

View file

@ -959,9 +959,9 @@ function getVideosURLAudio($fileName, $fileNameisThePath = false)
return $files; 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) function getVideosURLMP4Only($fileName)

View file

@ -162,10 +162,27 @@ function getSelfUserAgent()
{ {
global $global, $AVideoStreamer_UA; global $global, $AVideoStreamer_UA;
$agent = $AVideoStreamer_UA . "_"; $agent = $AVideoStreamer_UA . "_";
$agent .= md5($global['salt']); $agent .= md5($global['salt'].date('i'));
return $agent; 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() function requestComesFromSameDomainAsMyAVideo()
{ {
global $global; global $global;

View file

@ -37,7 +37,6 @@ function get_ffprobe()
function convertVideoToMP3FileIfNotExists($videos_id, $forceTry = 0) function convertVideoToMP3FileIfNotExists($videos_id, $forceTry = 0)
{ {
_error_log("convertVideoToMP3FileIfNotExists: start videos_id=$videos_id try=$forceTry ");
global $global; global $global;
if (!empty($global['disableMP3'])) { if (!empty($global['disableMP3'])) {
_error_log('convertVideoToMP3FileIfNotExists: $global[disableMP3] isset'); _error_log('convertVideoToMP3FileIfNotExists: $global[disableMP3] isset');
@ -62,6 +61,7 @@ function convertVideoToMP3FileIfNotExists($videos_id, $forceTry = 0)
}else { }else {
$f = convertVideoFileWithFFMPEGIsLockedInfo($mp3File); $f = convertVideoFileWithFFMPEGIsLockedInfo($mp3File);
if ($f['isUnlocked']) { if ($f['isUnlocked']) {
_error_log("convertVideoToMP3FileIfNotExists: start videos_id=$videos_id try=$forceTry ");
$sources = getVideosURLOnly($video['filename'], false); $sources = getVideosURLOnly($video['filename'], false);
if (!empty($sources)) { if (!empty($sources)) {
if(!empty($sources['m3u8'])){ if(!empty($sources['m3u8'])){
@ -137,14 +137,21 @@ function cleanupDownloadsDirectory($resolution = 720)
} }
} }
function m3u8ToMP4($input) function m3u8ToMP4($input, $makeItPermanent = false)
{ {
$videosDir = getVideosDir(); $videosDir = getVideosDir();
$outputfilename = str_replace($videosDir, "", $input); $outputfilename = str_replace($videosDir, "", $input);
$parts = explode("/", $outputfilename); $parts = explode("/", $outputfilename);
$resolution = Video::getResolutionFromFilename($input); $resolution = Video::getResolutionFromFilename($input);
$outputfilename = $parts[0] . "_{$resolution}_.mp4"; $video_filename = $parts[count($parts)-2];
if($makeItPermanent){
$outputfilename = "index.mp4";
$outputpathDir = "{$videosDir}{$video_filename}/";
}else{
$outputfilename = $video_filename . "_{$resolution}_.mp4";
$outputpathDir = "{$videosDir}downloads/"; $outputpathDir = "{$videosDir}downloads/";
}
//var_dump($outputfilename, $parts, $outputpathDir);exit;
make_path($outputpathDir); make_path($outputpathDir);
$outputpath = "{$outputpathDir}{$outputfilename}"; $outputpath = "{$outputpathDir}{$outputfilename}";
$msg = ''; $msg = '';
@ -166,7 +173,7 @@ function m3u8ToMP4($input)
$token = getToken(60); $token = getToken(60);
$filepath = addQueryStringParameter($filepath, 'globalToken', $token); $filepath = addQueryStringParameter($filepath, 'globalToken', $token);
} else { } else {
$filepath = escapeshellcmd($input); $filepath = escapeshellcmdURL($input);
} }
if (is_dir($filepath)) { if (is_dir($filepath)) {
@ -185,7 +192,13 @@ function m3u8ToMP4($input)
_error_log($msg3); _error_log($msg3);
return ['error' => $error, 'msg' => $finalMsg]; return ['error' => $error, 'msg' => $finalMsg];
} else { } else {
return $return; return [
'error' => false,
'msg' => implode(', ', $return['output']),
'path' => $return['toFileLocation'],
'filename' => basename($return['toFileLocation']),
'return' => $return
];
} }
} else { } else {
$msg = "downloadHLS: outputpath already exists ({$outputpath})"; $msg = "downloadHLS: outputpath already exists ({$outputpath})";

View file

@ -1090,3 +1090,24 @@ function getVideosDirectoryUsageInfo() {
'used_percentage_number' => $usedPercentage 'used_percentage_number' => $usedPercentage
]; ];
} }
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;
}

View file

@ -501,3 +501,9 @@ function ddosProtection()
return true; return true;
} }
function escapeshellcmdURL(string $command)
{
return str_replace('\?', '?', escapeshellcmd($command));
}

View file

@ -48,8 +48,8 @@ class Live extends PluginAbstract
$desc .= "<div class='alert alert-danger'>You MUST update your LiveUsers plugin to version 2.0 or greater</div>"; $desc .= "<div class='alert alert-danger'>You MUST update your LiveUsers plugin to version 2.0 or greater</div>";
} }
} }
$desc .= "<br><strong>Start Self hosted WebRTC server:</strong> <code>php {$global['systemRootPath']}plugin/Live/standAloneFiles/WebRTCServer/server.php</code> "; //$desc .= "<br><strong>Start Self hosted WebRTC server:</strong> <code>php {$global['systemRootPath']}plugin/Live/standAloneFiles/WebRTCServer/server.php</code> ";
$desc .= "<br><small><a href='https://github.com/WWBN/AVideo/wiki/WebRTC-Server' target='_blank'><i class='fas fa-question-circle'></i> Help</a></small>"; //$desc .= "<br><small><a href='https://github.com/WWBN/AVideo/wiki/WebRTC-Server' target='_blank'><i class='fas fa-question-circle'></i> Help</a></small>";
return $desc; return $desc;
} }