IWBH_01

MediaMash! fix HLS stream .m3u8 lists back to regular single file media

Oct 9th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.14 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_POST["m3u8"])&&strlen($_POST["m3u8"])){
  4.  
  5.   //https://cf-hls-media.sndcdn.com/playlist/jT6vVCgeToaf.128.mp3/playlist.m3u8
  6.  
  7.   $mpd=file_get_contents($_POST["m3u8"]);
  8.   if(strlen($mpd)>40){
  9.    $lns=explode("\n",$mpd);
  10.    $udat="";
  11.    foreach($lns as $ln){
  12.       if(substr($ln,0,1)!="#"&&strlen($ln)>7)
  13.       $udat.=",".$ln;
  14.    }
  15.    $udat=substr($udat,1);
  16.   }else exit("error: ".$mpd);
  17.  
  18. }elseif(isset($_POST["comu"])&&strlen($_POST["comu"])){
  19.   $udat=$_POST["comu"];
  20. }
  21.  
  22. if(isset($udat)){
  23.   $fns="".dechex(random_int(0 ,14400))."_".dechex(time());
  24.  
  25.   $frst=substr($udat,0,strpos($udat,","));
  26.  
  27.   if($qr=strpos($frst,"?")) $frst=substr($frst,0,$qr);
  28.  
  29.   if($ld=strrpos($frst,".")) $fns.=substr($frst,$ld);
  30.  
  31.   file_put_contents($fns.".csv",$udat);
  32.  
  33.   if($_["SERVER_PORT"]*1==443) $sL="s"; else $sL="";
  34.   echo 'Result file: <a href="http'$sL.'://'.$_SERVER["HTTP_HOST"].'/'.$_SERVER["SCRIPT_NAME"].'/'.$fns.'"> '.$fns.'</a><br><a href="?">back to form</a>';
  35. }elseif(isset($_SERVER["PATH_INFO"])&&strlen($_SERVER["PATH_INFO"])>7){
  36.  $odat="";
  37.  
  38.  $urls=explode(",",file_get_contents(substr($_SERVER["PATH_INFO"],1).'.csv'));
  39.  foreach($urls as $url){
  40.    $odat.=file_get_contents($url);
  41.  }
  42.  
  43.  $file_info = new finfo(FILEINFO_MIME);
  44.  $mime_type = $file_info->buffer($odat);
  45.  
  46.  header("Content-Type: ".$mime_type);
  47.  
  48.  echo $odat;
  49. }else
  50.  
  51.  echo '<html>
  52.  <head>
  53.    <title>MediaMash</title>
  54.  </head>
  55.  <body>
  56.    MediaMash!<br><br>
  57.    This proxy takes those irksome HLS .m3u8 playlists and mashes all those chunks together into one big media file.
  58.    <br>
  59.    It's very basic, it literally just appends their file data together, so don't be surprised if it doesn't work sometimes.
  60.     <br>
  61.     <br>
  62.     <form method="POST" enctype="application/x-form-url-encoded">
  63.     Input url to a HLS stream .m3u8 playlist:
  64.     <input type="text" name="m3u8"><br>
  65.     OR<br>
  66.     Input comma separated individual media urls to mash together (must be same file type and bitrate):
  67.     <br>
  68.     <textarea name="comu" cols=250 rows=50 ></textarea>
  69.     <br>
  70.     <input type="submit" value="mash!">
  71.     </form></body></html>';
  72.  
  73.  
  74. ?>
  75.  
Add Comment
Please, Sign In to add comment