Created
January 16, 2024 10:24
-
-
Save OkoyaUsman/42b6e48f73641888f716a2f7b9b50283 to your computer and use it in GitHub Desktop.
Self pulling-pushing streaming server in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RewriteEngine on | |
| RewriteCond %{HTTP_REFERER} !^https://(www\.)?streamtent.xyz[NC] | |
| RewriteCond %{HTTP_REFERER} !^https://(www\.)?streamtent.xyz.*$ [NC] | |
| RewriteRule \.(m3u8|ts|php|html|css|js|mp4|png|jpg|gif|jpeg|mov)$ - [F] | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteRule ^([^.]+)\.m3u8$ server.php?m3u8=$1 [QSA,L] | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteRule ^([^.]+)\.ts server.php?ts=$1 [QSA,L] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| session_start(); | |
| define("BASE_URL", "https://streamtent.xyz/tv/"); | |
| if(isset($_SESSION['whoami'])){ | |
| function removeFilename($url){ | |
| $file_info = pathinfo($url); | |
| return isset($file_info['extension']) ? str_replace($file_info['filename'] . "." . $file_info['extension'], "", $url) : $url; | |
| } | |
| if($_SESSION['whoami'] == "guest"){ | |
| //do guest work | |
| } | |
| if(!isset($_REQUEST["m3u8"]) && !isset($_REQUEST["ts"])){ | |
| die('Unauthorized Access'); | |
| } | |
| $useragent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/7.0.185.1002 Safari/537.36"; | |
| $referral = "https://drogon.tv/"; | |
| if(isset($_REQUEST["ts"])){ | |
| $ts = strrev(base64_decode(strrev($_REQUEST["ts"]))); | |
| $ch = curl_init($ts); | |
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_VERBOSE, true); | |
| curl_setopt($ch, CURLOPT_TIMEOUT, 222222); | |
| curl_setopt($ch, CURLOPT_HEADER, false); | |
| curl_setopt($ch, CURLOPT_NOBODY, false); | |
| curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); | |
| curl_setopt($ch, CURLOPT_USERAGENT, $useragent); | |
| curl_setopt($ch, CURLOPT_REFERER, $referral); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
| curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($curl, $header){ | |
| header($header); | |
| return strlen($header); | |
| }); | |
| curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $body){ | |
| echo $body; | |
| return strlen($body); | |
| }); | |
| }else{ | |
| $m3u8 = strrev(base64_decode(strrev($_REQUEST["m3u8"]))); | |
| $ch = curl_init($m3u8); | |
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_VERBOSE, true); | |
| curl_setopt($ch, CURLOPT_TIMEOUT, 222222); | |
| curl_setopt($ch, CURLOPT_HEADER, false); | |
| curl_setopt($ch, CURLOPT_NOBODY, false); | |
| curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); | |
| curl_setopt($ch, CURLOPT_USERAGENT, $useragent); | |
| curl_setopt($ch, CURLOPT_REFERER, $referral); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
| curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($curl, $header){ | |
| header($header); | |
| return strlen($header); | |
| }); | |
| curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $body){ | |
| global $m3u8; | |
| $n = explode("\n", $body); | |
| foreach($n as $line){ | |
| if(strpos($line, ".ts") !== false && strpos($line, "http") !== false){ | |
| $body = str_replace($line, BASE_URL.'live/'.strrev(base64_encode(strrev(trim($line)))).'.ts', $body); | |
| }elseif(strpos($line, ".ts") !== false){ | |
| $body = str_replace($line, BASE_URL.'live/'.strrev(base64_encode(strrev(trim(removeFilename($m3u8).$line)))).'.ts', $body); | |
| } | |
| } | |
| echo $body; | |
| return strlen($body); | |
| }); | |
| } | |
| $response = curl_exec($ch); | |
| curl_close($ch); | |
| exit; | |
| }else{ | |
| http_response_code(403); | |
| die("Unauthorized Access."); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment