<?php
// voiceover.php
// RJM Programming
// May, 2023
//set_time_limit(1200);
ini_set('max_execution_time', 60000); 

if (isset($_GET['infilegetsize'])) {
   if (strlen($_GET['infilegetsize']) > 0) {
//file_put_contents('x.x','1');
     if (strpos(strtolower(str_replace('+',' ',urldecode($_GET['infilegetsize']))), '.txt') !== false) {
//file_put_contents('x.x','11 ' . strtolower(str_replace('+',' ',urldecode($_GET['infilegetsize']))));
       if (strpos(strtolower(str_replace('+',' ',urldecode($_GET['infilegetsize']))), '.txt;') !== false) {
//file_put_contents('x.xx','111');
       if (!file_exists(explode(';', str_replace('+',' ',urldecode($_GET['infilegetsize'])))[0])) {
//file_put_contents('x.xxx','1111');
       file_put_contents(explode(';', str_replace('+',' ',urldecode($_GET['infilegetsize'])))[0], '');
       }
//file_put_contents('x.xxxx','11111');
       if (strpos(explode(';', str_replace('"','',str_replace('+',' ',urldecode($_GET['infilegetsize']))))[1], '.') !== false) {
       if (strpos(file_get_contents(explode(';', str_replace('+',' ',urldecode($_GET['infilegetsize'])))[0]), "" . basename(explode(';', str_replace('"','',str_replace('+',' ',urldecode($_GET['infilegetsize']))))[1]) . "'") === false) {
       file_put_contents(explode(';', str_replace('+',' ',urldecode($_GET['infilegetsize'])))[0], file_get_contents(explode(';', str_replace('+',' ',urldecode($_GET['infilegetsize'])))[0]) . "file '" . explode(';', str_replace('"','',str_replace('+',' ',urldecode($_GET['infilegetsize']))))[1] . "'" . "\n");
       }
       }
       } else {
//file_put_contents('x.xxxx','111111');
       file_put_contents(str_replace('+',' ',urldecode($_GET['infilegetsize'])), '');
      }
     } else {
//file_put_contents('x.xxxx','111111');
       file_put_contents(str_replace('+',' ',urldecode($_GET['infilegetsize'])), '');
     }
   }
   exit;
}

$rs='';
$outf='';
if (isset($_GET['fcommand'])) {
   if (PHP_OS == "Darwin") {
    putenv('PATH=/usr/local/bin');
   }
//file_put_contents('x.x', str_replace('+',' ',urldecode($_GET['fcommand'])));
   $cmdis=str_replace('+',' ',urldecode($_GET['fcommand']));
//file_put_contents('x7.x7', $cmdis);
   $precmd=explode('>', $cmdis);
   if (strpos($precmd[0], '.ass') !== false && file_exists('sub.ass')) { unlink('sub.ass');  }
   if (strpos($precmd[0], ' list.txt ') !== false && file_exists('list.txt')) { file_put_contents('list.txt', str_replace("'file '", "'" . "\n" . "file '", file_get_contents('list.txt')));  }
   $subcmd=explode('-shortest ', trim(str_replace(' -c COPY -',' -c copy -',str_replace('.ass ','.ass-shortest ',str_replace(' -c copy ',' -c copy -shortest ',str_replace(' -c copy -',' -c COPY -',$precmd[0]))))));
   if (sizeof($subcmd) > 1) {
      $outf=$subcmd[1];
//file_put_contents('x777.x777', $outf);
      if (file_exists($outf)) { 
       $wassuff='';
       while (file_exists($outf . '_was' . $wassuff)) {
//file_put_contents('x77777.x77777', $outf . '_was' . $wassuff);
         if ($wassuff == '') {
           $wassuff='0';
         } else {
           $wassuff='' . (1 + intval('' . $wassuff));
         }
       }
//file_put_contents('x7777.x7777', $outf . '_was' . $wassuff);
       rename($outf, $outf . '_was' . $wassuff); 
      }
   }
//file_put_contents('x77.x77', $cmdis);
   if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
     $cmdis=str_replace(' > ', ' 2> ', $cmdis);
   } 
//file_put_contents('x.x', $cmdis);
   $rs=shell_exec($cmdis);
//file_put_contents('xx.xx', $rs);
   if ($outf != '') {
     if (file_exists($outf)) {
       $rs.='<br><br><video title="' . $cmdis . '" controls><source src="' . $outf . '?rand=' . rand(0,7654532) . '" type="video/' . strtolower(explode('.', $outf)[-1 + sizeof(explode('.', $outf))]) . '"></source></video>';  
if (PHP_OS == "Darwin") {
   $rs.='<br><br><details style=background-color:yellow;><summary style=background-color:lightblue;>Video and Audio Files ...</summary><br>' . str_replace("\n","<br>",yourshell_exec("file *.* | egrep -B 0 'ISO Media|Audio|WebM|Matroska|.ts:|.srt:'")) . '</details>';
} else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
   $rs.='<br><br><details style=background-color:yellow;><summary style=background-color:lightblue;>Video and Audio Files ...</summary><br>' . str_replace("\n","<br>",yourshell_exec('"C:\\Program Files (x86)\\GnuWin32\\bin\\file.exe" *.*')) . '</details>';
}
     }
   }
} else if (PHP_OS == "Darwin") {
   $rs='<details style=background-color:yellow;><summary style=background-color:lightblue;>Video and Audio Files ...</summary><br>' . str_replace("\n","<br>",yourshell_exec("file *.* | egrep -B 0 'ISO Media|Audio|WebM|Matroska|.ts:|.srt:'")) . '</details>';
} else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
   $rs='<details style=background-color:yellow;><summary style=background-color:lightblue;>Video and Audio Files ...</summary><br>' . str_replace("\n","<br>",yourshell_exec('"C:\\Program Files (x86)\\GnuWin32\\bin\\file.exe" *.*')) . '</details>';
}


if (isset($_GET['ffmpeg'])) {
  $fnd=false;
  if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
    if (file_exists('./ffmpeg.txt')) {
      $pplace=file_get_contents('./ffmpeg.txt');
      if (strpos($pplace, 'ffmpeg.exe') !== false) {
        $fnd=true;
      }
    }
    if (!$fnd) {
     $huhexe=shell_exec("where ffmpeg.exe");
     if ($huhexe == '') {
      $huhexes=rglob("C:\\ffmpeg.exe"); //shell_exec("where pdfimages.exe");
      if (sizeof($huhexes) > 0) {
       file_put_contents('./ffmpeg.txt', $huhexes[0]);
       if (strpos($huhexes[0], ' ') !== false) { 
       $huhexes[0]=str_replace('"','',$huhexes[0]);
       echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"fcommand\")) { if (1 == 1) { parent.document.getElementById(\"fcommand\").value=parent.document.getElementById(\"fcommand\").value.replace(parent.document.getElementById(\"fcommand\").value.split(\"ffmpeg.exe\")[0] + \"ffmpeg.exe\", String.fromCharCode(34) + \"" . str_replace("\\","\\\\",explode('ffmpeg.exe',$huhexes[0])[0]) . "ffmpeg.exe\").replace('.exe ','.exe' + String.fromCharCode(34) + ' '); } } }'></body></html>";
       } else {
       $huhexes[0]=str_replace('"','',$huhexes[0]);
       echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"fcommand\")) { if (1 == 1) { parent.document.getElementById(\"fcommand\").value=parent.document.getElementById(\"fcommand\").value.replace(parent.document.getElementById(\"fcommand\").value.split(\"ffmpeg.exe\")[0] + \"ffmpeg.exe\", \"" . str_replace("\\","\\\\",explode('ffmpeg.exe',$huhexes[0])[0]) . "ffmpeg.exe\").replace('.exe' + String.fromCharCode(34) + ' ', '.exe '); } } }'></body></html>";
       }
      }
     }
    }
  }
  exit;
}

$dn='';
$ffmpegpre='';
$ffmpegsuf='';
$whereffmpeg="?infilegetsize=";
if (PHP_OS == "Darwin") {
  $dn=' /dev/null';
} else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {
  $ffmpegpre="\"C:\\Program Files\\ImageMagick-7.1.0-Q16-HDRI\\";
  $ffmpegsuf=".exe\"";
  if (!file_exists($ffmpegpre . 'ffmpeg' . $ffmpegsuf)) {
   if (file_exists('./ffmpeg.txt')) {
     if (!file_exists(file_get_contents('./ffmpeg.txt'))) {
       unlink('./ffmpeg.txt');
       $whereffmpeg="?ffmpeg=where";
     } else {
       $ffmpegpre="\"" . str_replace('ffmpeg.exe','',file_get_contents('./ffmpeg.txt')) . "\"";
     }
   }
   if (file_exists('ffmpeg' . $ffmpegsuf)) {
    $ffmpegpre="";
   } else if (!file_exists('./ffmpeg.txt')) {
     $huhexe=shell_exec("where ffmpeg.exe");
     if (strpos($huhexe, 'ffmpeg.exe') === false) {
       $whereffmpeg="?ffmpeg=where";
     } else {
       $ffmpegpre=str_replace('ffmpeg.exe','',$huhexe);
     }
   }
  }
  $pdfimagespre="\"C:\\MAMP\\htdocs\\xpdf-tools-win-4.04\\bin32\\";
  $pdfimagessuf=".exe\"";
  if (!file_exists($pdfimagespre . 'pdfimages' . $pdfimagessuf)) {
   if (file_exists('./pdfimages.txt')) {
     if (!file_exists(file_get_contents('./pdfimages.txt'))) {
       unlink('./pdfimages.txt');
       $wherepdfimages="?pdfimages=where";
     } else {
       $pdfimagespre="\"" . str_replace('pdfimages.exe','',file_get_contents('./pdfimages.txt')) . "\"";
     }
   }
   if (file_exists('pdfimages' . $pdfimagessuf)) {
     $pdfimagespre="";
   } else if (!file_exists('./pdfimages.txt')) {
     $huhexe=shell_exec("where pdfimages.exe");
     if (strpos($huhexe, 'pdfimages.exe') === false) {
       $wherepdfimages="?pdfimages=where";
     } else {
       $pdfimagespre=str_replace('pdfimages.exe','',$huhexe);
     }
   }
  }
}


function scandir_through($dir, $bname, $bsize) { // thanks to https://www.php.net/manual/en/function.glob.php
    $ds=substr((DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR),0,1);
    if (strpos(('!@' . strtoupper($dir)), '!@C:') !== false) { $dir=str_replace('/','',$dir);  }
    if (substr(strrev($dir),0,1) == substr((DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR),0,1)) {
      $ds='';
    }
    $items = glob($dir . $ds . str_replace(' ','*',$bname));

    for ($i = 0; $i < count($items); $i++) {
        if (is_dir($items[$i])) {
            $add = glob($items[$i] . $ds . str_replace(' ','*',$bname));
            if (filesize($add) == $bsize) {
            //echo $add;
            $items = array_merge($items, $add);
            } //else {
            //echo 'x' . $add . 'x';
            //}
        }
    }

    return $items;
}

function yourshell_exec($incm) {
//file_put_contents('xx.xx', $incm);
  $blurblines=shell_exec($incm);
//file_put_contents('xxx.xxx', $blurblines);
  $outblurb="";
  $obs=explode("\n", $blurblines);
  for ($iobs=0; $iobs<sizeof($obs); $iobs++) {
   if ((PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') && strpos(str_replace(".srt;", "ISO Media", $obs[$iobs]), "ISO Media") === false) {
     $iobs=$iobs;
   } else {
     if (strpos($obs[$iobs], ';') !== false && strpos($obs[$iobs], ':') !== false) {
        if (strpos($obs[$iobs], ';') < strpos($obs[$iobs], ':')) {
       $outblurb.=str_replace(explode(';',$obs[$iobs])[0] . ';','<a title="Click to slot in above" style=cursor:pointer;text-decoration:underline; data-href=# onclick=spanfill("' . explode(';',$obs[$iobs])[0] . '");>' . explode(';',$obs[$iobs])[0] . '</a>;',$obs[$iobs]) . "\n";
        } else {
       $outblurb.=str_replace(explode(':',$obs[$iobs])[0] . ':','<a title="Click to slot in above" style=cursor:pointer;text-decoration:underline; data-href=# onclick=spanfill("' . explode(':',$obs[$iobs])[0] . '");>' . explode(':',$obs[$iobs])[0] . '</a>;',$obs[$iobs]) . "\n";
        }
     } else if (strpos($obs[$iobs], ';') !== false) {
       $outblurb.=str_replace(explode(';',$obs[$iobs])[0] . ';','<a title="Click to slot in above" style=cursor:pointer;text-decoration:underline; data-href=# onclick=spanfill("' . explode(';',$obs[$iobs])[0] . '");>' . explode(';',$obs[$iobs])[0] . '</a>;',$obs[$iobs]) . "\n";
     } else if (strpos($obs[$iobs], ':') !== false) {
       $outblurb.=str_replace(explode(':',$obs[$iobs])[0] . ':','<a title="Click to slot in above" style=cursor:pointer;text-decoration:underline; data-href=# onclick=spanfill("' . explode(':',$obs[$iobs])[0] . '");>' . explode(':',$obs[$iobs])[0] . '</a>;',$obs[$iobs]) . "\n";
     } else {
       $outblurb.=$obs[$iobs] . "\n";
     }
   }
  }
  return $outblurb;
}

function ourshell_exec($onea, $twoa = NULL, $threea = NULL) {
   $folder='';
   $pattern=''; 
   $size='';
   $filesa=[];
   if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows' || (strpos(('~@!' . $onea), '~@!forfiles /P "') !== false && strpos(('~@!' . $onea), '/M "') !== false && strpos(('~@!' . $onea), 'find "') !== false)) {
     $folder=explode('"', explode('forfiles /P "', $onea)[1])[0]; // . substr(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, 0, 1);
     if (7 == 7) { 
       $folder=explode('"', explode('forfiles /P "', $onea)[1])[0]; // . substr(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, 0, 1);
       $pattern=explode('"', explode('/M "', $onea)[1])[0];
       $size=explode('"', explode('find "', $onea)[1])[0];
       $thiscmd=trim(explode(" | find ", $onea)[0]);
       if (strpos($pattern, ' ') === false) {  $thiscmd=str_replace('/M "' . $pattern . '"', '/M ' . $pattern, $thiscmd);  }
       if (strpos($folder, ' ') === false) {  $thiscmd=str_replace('/P "' . $folder . '"', '/P ' . $folder, $thiscmd);  }
       if (strpos($thiscmd, '"cmd /c ') !== false && substr($thiscmd,-1,1) != '"') { $thiscmd.='"'; }
       if (strpos($thiscmd, "/P C:\\ ") !== false) {         
            if (strpos($thiscmd, "/P C:\\ ") !== false) {   
                     if (strpos($pattern, " ") === false) {       
                            $thiscmd="DIR C:\\" . $pattern . " /S /-C";
                     } else {
                            $thiscmd="DIR \"C:\\" . $pattern . "\" /S /-C";
                     }    
            }
       }
//file_put_contents('xxx.xxx',file_get_contents('xxx.xxx'). "\n" . '' . $size . ' ' . $thiscmd);
       $nofind=shell_exec($thiscmd . ' 2> nul');

//file_put_contents('xxxx.xxxx',file_get_contents('xxxx.xxxx'). "\n" . '' . $size . ' ' . $nofind);
//exit;
       $findings=explode("\n", $nofind);
       $bitbefore='';
       for ($ifindgs=0; $ifindgs<sizeof($findings); $ifindgs++) {
         if (strpos(str_replace("\r","",$findings[$ifindgs]), 'Directory of ') !== false) {
             $bitbefore=explode('Directory of ', str_replace("\r","",$findings[$ifindgs]))[1] . "\\";
         }
         if (strpos((str_replace("\r","",$findings[$ifindgs]) . '~'), $size . '~') !== false) {
            return str_replace('~','',str_replace($size . '~', '', (str_replace("\r","",$findings[$ifindgs]) . '~')));
         } else if (strpos((str_replace("\r","",$findings[$ifindgs]) . ''), $size . ' ') !== false) {
//file_put_contents('xxxxx.xxxxx',$bitbefore . explode($size . ' ', (str_replace("\r","",$findings[$ifindgs]) . ''))[1]);
           return $bitbefore . explode($size . ' ', (str_replace("\r","",$findings[$ifindgs]) . ''))[1];
         }
       }
       if ($folder == "C:\\") { return ''; } 
     } 
     if (strpos(('~@!' . $onea), '~@!forfiles /P "') !== false && strpos(('~@!' . $onea), '/M "') !== false && strpos(('~@!' . $onea), 'find "') !== false) {
       $folder=explode('"', explode('forfiles /P "', $onea)[1])[0] . substr(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, 0, 1);
       if (strpos($folder, ' ') !== false) {  $folder='"' . $folder . '"';  }
       $pattern=explode('"', explode('/M "', $onea)[1])[0];
       if (strpos($pattern, ' ') !== false || substr(($folder . ' '),0,1) == '"') {  $pattern='"' . $pattern . '"'; if (substr(($folder . ' '),0,1) != '"') {  $folder='"' . $folder . '"';  }  }
       $size=explode('"', explode('find "', $onea)[1])[0];
       //$basis=str_replace('""','',$folder . str_replace(str_replace('"','',explode('.',$pattern)[0]),'*',$pattern));
       $basis=str_replace('""','',$folder . str_replace(str_replace('"','',explode('.',$pattern)[0]),str_replace(' ','*',str_replace('"','',explode('.',$pattern)[0])),$pattern));

       if (strpos($basis, ' ') === false) { $basis=str_replace('"','',$basis);  }
// file_put_contents('xs23.xs23', "swqzzui " . str_replace('""','',$folder . str_replace(str_replace('"','',explode('.',$pattern)[0]),'*',$pattern)) . ' ... ' . $basis . ' --- ' . str_replace('"','',$folder) . ' ' . str_replace('"','',$pattern) . ' ' . $size);
// exit;
       $filesa=scandir_through(str_replace('"','',$folder), str_replace('"','',$pattern), $size);
// file_put_contents('xs423.xs423', "swqzzui " . str_replace('""','',$folder . str_replace(str_replace('"','',explode('.',$pattern)[0]),'*',$pattern)) . ' ... ' . $basis . ' --- ' . str_replace('"','',$folder) . ' ' . str_replace('"','',$pattern) . ' ' . $size);
       if (sizeof($filesa) == 0) { return ''; }
// file_put_contents('xs4423.xs4423', "swqzzui " . str_replace('""','',$folder . str_replace(str_replace('"','',explode('.',$pattern)[0]),'*',$pattern)) . ' ... ' . $basis . ' --- ' . str_replace('"','',$folder) . ' ' . str_replace('"','',$pattern) . ' ' . $size);
       return $filesa[0];
       
       if (4 == 5) {
       
echo "bzmbvzqsswqzzui " . $filesa[0];
 exit;

       $slookfor=str_replace('"','',('' . $pattern));
       //$filesa=foreach (glob('{' . $basis . '}'),GLOB_BRACE);
 echo "zmbvzqsswqzzui " . $filesa[0];
 exit;
      foreach (glob($basis) as $file) {
        $chfile='' . $file;
 echo "mbvzqsswqzzui " . $chfile . ' ' . $slookfor;
 exit;
        if (strpos($chfile, $slookfor) !== false) {
 echo "vzqsswqzzui " . $file;
 exit;
        if (filesize($file) == $size) {
 echo "zqsswqzzui " . $file;
 exit;
    file_put_contents('xm3.xm3', $file . ' ' . $size);
           return $file;
           
        }
        
        }
        }
       }
     }
   }
   return shell_exec($onea, $twoa, $threea);
}

function rsearch($folder, $pattern, $size) { // thanks, anyway, to https://stackoverflow.com/questions/17160696/php-glob-scan-in-subfolders-for-a-file
    $didea='';
    $outputa=[]; 
    $retz='';
    if (PHP_OS == "Darwin") {

      //file_put_contents("x.ksh", "find " . $folder . " -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
      //if ($folder == substr((DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR),0,1)) {
        $didea=shell_exec("find \$HOME/Downloads -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
      //file_put_contents("xx.ksh", $didea);
        if ($didea != '') { return $didea; }
        $didea=shell_exec("find " . rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR  . " -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
      //file_put_contents("xxx.ksh", $didea);
        if ($didea != '') { return $didea; }

        $xc=getenv('HOME');
      if ($xc == '') {
      $dirsa = glob('/Users/*', GLOB_ONLYDIR);
      for ($ia=0; $ia<sizeof($dirsa); $ia++) {
      //echo "2:" . $dirsa[$ia] . str_replace('//','/',DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . "Downloads";
   //exit;
        if ($didea == '') {
         //$didea=ourshell_exec("forfiles /P \"" . $dirsa[$ia] . "Downloads\" /S /M \"" . $pattern . "\" /C \"cmd /c echo @path@fsize | find \"" . $size . "\" 2>&1", $outputa, $retz);
         $didea=ourshell_exec("forfiles /P \"" . str_replace('//','/',$dirsa[$ia] . "/") . "Downloads\" /S /M \"" . $pattern . "\" /C \"cmd /c echo @path@fsize | find \"" . $size . "\" 2>&1", $outputa, $retz);
       if ($didea != '') { return $didea; }
       }
      }
      if ($didea != '') { return $didea; }
      } else {
        $didea=ourshell_exec("forfiles /P \"" . $xc . str_replace('//','/',DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . "Downloads\" /S /M \"" . $pattern . "\" /C \"cmd /c echo @path@fsize | find \"" . $size . "\" 2>&1", $outputa, $retz);
        if ($didea != '') { return $didea; }
      }

      return shell_exec("find " . $folder . " -type f -name \"" . $pattern . "\" 2> /dev/null -exec wc -c {} + | egrep '^ " . $size . " ' | sed '/ " . $size . " /s///g'");
    } else if (PHP_OS =='WINNT' || PHP_OS =='WIN32' || PHP_OS =='Windows') {

//file_put_contents('xs8.xs8', '');
      $xc=getenv('HOMEDRIVE') . getenv('HOMEPATH');
 //file_put_contents('xs88.xs88', $xc);
      if ($xc == '') { $xc=getenv('USERPROFILE');  }
 //file_put_contents('xs888.xs888', $xc);
      $xc='';
      if ($xc == '') {
 //file_put_contents('xs8888.xs8888', $xc);
      $dirsa = glob("C:\\Users\\*", GLOB_ONLYDIR);
      for ($ia=0; $ia<sizeof($dirsa); $ia++) {
 //file_put_contents('xs9.xs9', $dirsa[$ia] . ' ' . sizeof($dirsa));
        if ($didea == '') {
 //file_put_contents('xs99.xs99',  file_get_contents('xs99.xs99') . "\n" . $dirsa[$ia] . "\\Downloads");
         $didea=ourshell_exec("forfiles /P \"" . $dirsa[$ia] . "\\Downloads\" /S /M \"" . $pattern . "\" /C \"cmd /c echo @path@fsize\" | find \"" . $size . "\" 2>&1", $outputa, $retz);
      if ($didea != '') { return $didea; }
 //file_put_contents('xs999.xs999',  $dirsa[$ia] . "\\Downloads");
        }
      }
      if ($didea != '') { return $didea; }
      } else {
      $didea=ourshell_exec("forfiles /P \"" . $xc . str_replace('//','/',DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . "Downloads\" /S /M \"" . $pattern . "\" /C \"cmd /c echo @path@fsize\" | find \"" . $size . "\" 2>&1", $outputa, $retz);
      if ($didea != '') { return $didea; }
      }
      if ($didea != '') { return $didea; }
 //file_put_contents('xs29.xs29', $_SERVER['DOCUMENT_ROOT']);
     $didea=ourshell_exec("forfiles /P \"" . $_SERVER['DOCUMENT_ROOT'] . "\" /S /M \"" . $pattern . "\" /C \"cmd /c echo @path@fsize\" | find \"" . $size . "\" 2>&1", $outputa);
      if ($didea != '') { return $didea; }
 //file_put_contents('xs39.xs39', 'userp');
      $didea=ourshell_exec("forfiles /P \"%USERPROFILE%" . str_replace('//','/',DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . "Downloads\" /S /M \"" . $pattern . "\" /C \“cmd /c echo @path@fsize | find \"" . $size . "\" 2>&1", $outputa, $retz);
      if ($didea != '') { return $didea; }
      //$didea=shell_exec('forfiles /P C:' . substr("\\",0,1) . 'Downloads /S /M * /C “cmd /c if @fsize EQU ' . $size . ' if @file EQU ' . $pattern . " echo @path");
      //if ($didea != '') { return $didea; }
      //$didea=shell_exec('forfiles /P C:' . substr("\\",0,1) . ' /S /M * /C “cmd /c if @fsize EQU ' . $size . ' if @file EQU ' . $pattern . " echo @path 2>nul");
 //file_put_contents('xs49.xs49', 'root');
      //$didea=ourshell_exec("forfiles /P \"C:" . substr("\\",0,1) . "\" /S /M \"" . $pattern . "\" /C \"cmd /c echo @path@fsize\" | find \"" . $size . "\" 2>&1");
      //if ($didea != '') { return $didea; }
      $didea=ourshell_exec("forfiles /P \"" . "C:\\\" /S /M \"" . $pattern . "\" /C \"cmd /c echo @path@fsize\" | find \"" . $size . "\" 2>&1", $outputa, $retz);
      if ($didea != '') { return $didea; }
 //file_put_contents('xs59.xs59', 'noroot');
    }
//  echo "QQghfjhg";
  //echo "forfiles /P \"" . $_SERVER['DOCUMENT_ROOT'] . "\" /S /M \"" . $pattern . "\" /C \“cmd /c echo @path@fsize | find \"" . $size . "\" 2>&1";
//  exit;
    //$iti = new RecursiveDirectoryIterator($folder);
    //foreach (new RecursiveIteratorIterator($iti) as $file) {
    //foreach (glob($folder . $pattern) as $file) {
    //     if (strpos($file , $pattern) !== false && filesize($file) == $size) {
    //        return $file;
    //     }
    //}
    return '';
}

// Does not support flag GLOB_BRACE
function rglob($pattern, $flags = 0) { // thanks to https://stackoverflow.com/questions/17160696/php-glob-scan-in-subfolders-for-a-file
    $files = glob($pattern, $flags); 
    foreach (glob(str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR,dirname($pattern).DIRECTORY_SEPARATOR).'*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
        $files = array_merge(
            [],
            [$files, rglob($dir . DIRECTORY_SEPARATOR . basename($pattern), $flags)]
        );
    }
    return $files;
}

function ourbasename($inb) {
   return basename(str_replace(' ','_',$inb));
}

function ourrealpath($inb) {
   return realpath(str_replace(' ','_',$inb));
}

$substthis='';

if (isset($_GET['filename']) && isset($_GET['filesize']) && !isset($_GET['filepath'])) {
  if (isset($_GET['concat'])) {
    if (isset($_GET['haveasleep'])) {
      if ($_GET['haveasleep'] != '0') {
        sleep(intval('' . $_GET['haveasleep']));
      }
    }
//file_put_contents('xj100.xj100',file_get_contents('xj100.xj100') . "\n" . $_GET['filename'] . ' ' . $_GET['filesize']);
    $substthis=basename(str_replace('"','',str_replace('+',' ',urldecode($_GET['filename'])))) . "'" . "\n";
    if (strpos(file_get_contents(str_replace('+',' ',urldecode($_GET['concat']))), $substthis) !== false) {
      exit;
    }
    $substthis="file '" . str_replace('"','',str_replace('+',' ',urldecode($_GET['filename']))) . "'" . "\n";
    file_put_contents(str_replace('+',' ',urldecode($_GET['concat'])), file_get_contents(str_replace('+',' ',urldecode($_GET['concat']))) . "file '" . str_replace('"','',str_replace('+',' ',urldecode($_GET['filename']))) . "'" . "\n");
  } //else {
//file_put_contents('xj100.xj100',file_get_contents('xj100.xj100') . "\n... " . $_GET['filename'] . ' ' . $_GET['filesize']);
  //}
//file_put_contents('xj1.xj1','');
  if (file_exists(str_replace('+',' ',urldecode($_GET['filename'])))) {
    if (filesize(str_replace('+',' ',urldecode($_GET['filename']))) == $_GET['filesize']) {
      $filepath=rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['filename']));
//file_put_contents('xj11.xj11','');
    }
  }
  if ($filepath == '') {
    $filepath = rsearch(DIRECTORY_SEPARATOR, str_replace('+',' ',urldecode($_GET['filename'])), $_GET['filesize']);
//file_put_contents('xj111.xj111',$filepath);
  }
  $filepath=str_replace("\n","",$filepath);
  if (strpos($filepath, ' ') !== false) {
     $filepath='"' . str_replace('"','',$filepath) . '"';
//file_put_contents('xj1111.xj1111','');
  }
  if (!isset($_GET['inpath'])) {
 // echo "<html><body onload=\"if (parent.document.getElementById('path').value == '') { parent.document.getElementById('path').value='" . str_replace('"','',explode(str_replace('+',' ',urldecode($_GET['filename'])), $filepath)[0]) . "'; }\"></body></html>";
  if (isset($_GET['concat'])) {
  //file_put_contents('xj11111.xj11111', str_replace("'file '","'" . "\n" . "file '",str_replace("file '" . str_replace('"','',str_replace('+',' ',urldecode($_GET['filename']))) . "'","file '" . str_replace('"','',$filepath) . "'",file_get_contents(str_replace('+',' ',urldecode($_GET['concat']))))) . "\n" . str_replace("file '" . str_replace('"','',str_replace('+',' ',urldecode($_GET['filename']))) . "'","file '" . str_replace('"','',$filepath) . "'",file_get_contents(str_replace('+',' ',urldecode($_GET['concat']))))); 
  if (strpos(file_get_contents(str_replace('+',' ',urldecode($_GET['concat']))), "file '" . str_replace('"','',$filepath) . "'") === false) {
  if ($substthis != '') {
  if (strpos(file_get_contents(str_replace('+',' ',urldecode($_GET['concat']))), $substthis) !== false) {
  file_put_contents(str_replace('+',' ',urldecode($_GET['concat'])), str_replace($substthis,"file '" . str_replace('"','',$filepath) . "'" . "\n", file_get_contents(str_replace('+',' ',urldecode($_GET['concat'])))));
  } else {
  file_put_contents(str_replace('+',' ',urldecode($_GET['concat'])), str_replace($substthis,'',str_replace("'file '","'" . "\n" . "file '",str_replace("file '" . str_replace('"','',str_replace('+',' ',urldecode($_GET['filename']))) . "'","file '" . str_replace('"','',$filepath) . "'",file_get_contents(str_replace('+',' ',urldecode($_GET['concat'])))))));
  }
  } else {
  file_put_contents(str_replace('+',' ',urldecode($_GET['concat'])), str_replace("'file '","'" . "\n" . "file '",str_replace("file '" . str_replace('"','',str_replace('+',' ',urldecode($_GET['filename']))) . "'","file '" . str_replace('"','',$filepath) . "'",file_get_contents(str_replace('+',' ',urldecode($_GET['concat']))))));
  if ($substthis != '') {
  if (strpos(file_get_contents(str_replace('+',' ',urldecode($_GET['concat']))), $substthis) !== false) {
  file_put_contents(str_replace('+',' ',urldecode($_GET['concat'])), str_replace($substthis,"", file_get_contents(str_replace('+',' ',urldecode($_GET['concat'])))));
  } 
  }
  }
  }

  if (isset($_GET['concat'])) {
    echo "<html><body onload='parent.takeoffone();'></body></html>";
    exit;
  }

  } else if (isset($_GET['left'])) {
//file_put_contents('xj11111.xj11111',str_replace("\\","\\\\",$filepath));
//file_put_contents('xj111111.xj111111', "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbi\")) { if (1 == 1) { parent.document.getElementById(\"scbi\").innerHTML=\"" . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>");
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbi\")) { if (1 == 1) { parent.document.getElementById(\"scbi\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  } else {
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbix\")) { if (1 == 1) { parent.document.getElementById(\"scbix\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  }
  exit;
  } else {
  $_GET['inpath']=urlencode(str_replace('"','',explode(str_replace('+',' ',urldecode($_GET['filename'])), $filepath)[0]));
  //$_GET['convertthis']=$_GET['filename'];
  }
} else if (isset($_GET['filename']) && isset($_GET['filesize']) && $_GET['filepath'] == '') {
//file_put_contents('xs0.xs0', '');
  if (file_exists(str_replace('+',' ',urldecode($_GET['filename'])))) {
//file_put_contents('xs.xs', '');
    if (filesize(str_replace('+',' ',urldecode($_GET['filename']))) == $_GET['filesize']) {
      $filepath=rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_GET['filename']));
//file_put_contents('xs.xs1', $filepath);
    }
  }
  if ($filepath == '') {
//file_put_contents('xs.xs3', '');
    $filepath = rsearch(DIRECTORY_SEPARATOR, str_replace('+',' ',urldecode($_GET['filename'])), $_GET['filesize']);
//file_put_contents('xs.xs4', $filepath);
  }
  $filepath=str_replace("\n","",$filepath);
  if (strpos($filepath, ' ') !== false) {
     $filepath='"' . str_replace('"','',$filepath) . '"';
  }
  if (!isset($_GET['inpath'])) {
  if (isset($_GET['left'])) {
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbi\")) { if (1 == 1) { parent.document.getElementById(\"scbi\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  } else {
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbix\")) { if (1 == 1) { parent.document.getElementById(\"scbix\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  }
  exit;
  } else {
  $_GET['inpath']=urlencode(explode(str_replace('+',' ',urldecode($_GET['filename'])), $filepath)[0]);
  //$_GET['convertthis']=$_GET['filename'];
  }
} else if (isset($_GET['filename']) && isset($_GET['filesize']) && isset($_GET['filepath'])) {
  $anyextrac='';
  if (substr(str_replace('+',' ',urldecode($_GET['filepath'])), -1, 1) != DIRECTORY_SEPARATOR) {
    $anyextrac=DIRECTORY_SEPARATOR;
  }
  $filepath=str_replace("\n","",$filepath);
  if (strpos($filepath, ' ') !== false) {
     $filepath='"' . str_replace('"','',$filepath) . '"';
  }
  if (!isset($_GET['inpath'])) {
  if (isset($_GET['left'])) {
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbi\")) { if (1 == 1) { parent.document.getElementById(\"scbi\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  } else {
  echo "<html><body onload='if (window.parent) { if (parent.document.getElementById(\"scbix\")) { if (1 == 1) { parent.document.getElementById(\"scbix\").innerHTML=\" " . str_replace("\\","\\\\",$filepath) . "\"; } } }'></body></html>";
  }
  exit;
  } else {
  $_GET['inpath']=urlencode(str_replace('+',' ',urldecode($_GET['filepath'])) . $anyextac);
  //$_GET['convertthis']=$_GET['filename'];
  }
}

if ($ffmpegpre != '' && strpos($ffmpegpre, ' ') === false) {
  $ffmpegsuf=str_replace('"','',$ffmpegsuf);
  $ffmpegpre=str_replace('"','',$ffmpegpre);
}

$crlf="\r\n";
$cr="\r";
$lf="\n";

echo "<html>
<head>
<title>Add Voiceover Audio to Video via ffmpeg - RJM Programming - May, 2023</title>
<script type=text/javascript>
  var voaf='', voaftwo='', nonx=false, dox=false;
  var wo=null;
  var togglespan='scbi', ww='', origval='', firstdivih='', firstbutval='';
  var ifile=0, ibfile=0;
  var listtxt='list.txt';
  
  function getvb() {
    wo=window.open('','_blank','left=100,top=100,width=500,height=500');
    wo.document.write('<html><head><title>ffm.bad</title></head><body><pre>' + '" . str_replace("'",'`',str_replace('"','`',str_replace($cr,'',str_replace($lf,'<br>',str_replace($crlf,'<br>',file_get_contents('ffm.bad')))))) . "' + '</pre></body></html>');
  }
  
  function keeptrying() {
    if (document.getElementById(togglespan)) {
      document.getElementsByTagName('details')[0].style.cursor='pointer';
      spanfill(ww);
    } else {
      setTimeout(keeptrying, 3000);
    }
  }
  
  function spanfill(withwhat) {
     if (document.getElementById('mydefopt').title == 'Concat demuxer') {
     //alert('Here with ' + withwhat);
    document.getElementById('ifs').innerHTML+='<iframe id=voaskfor' + ifile + ' style=display:none; src=\"./voiceover.php?infilegetsize=' + encodeURIComponent(listtxt + ';' + withwhat) + '\"></iframe>';
    ifile++;
    if (document.getElementById('moreb').title.indexOf(\"file '\" + withwhat.replace(String.fromCharCode(34),'').replace(String.fromCharCode(34),'') + \"'\") == -1) {
    document.getElementById('moreb').title+=String.fromCharCode(10) + \"file '\" + withwhat.replace(String.fromCharCode(34),'').replace(String.fromCharCode(34),'') + \"'\";
    }
     } else {
     if (!document.getElementById(togglespan)) {
       document.getElementsByTagName('details')[0].style.cursor='progress';
       ww=withwhat;
       setTimeout(keeptrying, 3000);
       return '';
     }
     if (withwhat.indexOf(' ') != -1 && withwhat.indexOf(String.fromCharCode(34)) == -1) {
     document.getElementById(togglespan).innerHTML=String.fromCharCode(34) + withwhat + String.fromCharCode(34);
     } else {
     document.getElementById(togglespan).innerHTML=withwhat;
     }
     if (togglespan == 'scbi') {
       togglespan='scbix';
     } else {
       togglespan='scbi';
     }
     }
  }
  
  function checkif(iois, ival) {
    if (iois.src.indexOf('?d=6') != -1) {
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
       if (aconto.document) { aconto = aconto.document; }
       if (aconto.getElementById('files')) {
         if (voaf == '') {
         voaf=iois.src;
         iois.setAttribute('data-parentspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         document.getElementById('myh1').title='s' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix');
         document.getElementById('myh1').setAttribute('data-url', iois.src);
         setInterval(voaff, 1000);
         } else if (voaftwo == '') {
         voaftwo=iois.src;
         iois.setAttribute('data-parentspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         document.getElementById('myh3').title='s' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix');
         document.getElementById('myh3').setAttribute('data-url', iois.src);
         //alert(iois.id + ' data-parentspan=' + iois.getAttribute('data-parentspan'));
         }
         //alert(iois.id + ' data-parentspan=' + iois.getAttribute('data-parentspan'));
         aconto.getElementsByTagName('h1')[0].style.opacity='0.0';
         //alert('here');
         aconto.getElementById('files').style.position='absolute';
         aconto.getElementById('files').style.left='0px';
         aconto.getElementById('files').style.top='0px';
         aconto.getElementById('files').style.zIndex='99';
         aconto.getElementById('files').style.marginLeft='10px';
         aconto.getElementById('files').style.marginTop='8px';
         aconto.getElementById('files').style.visibility='visible';
         aconto.getElementById('files').style.display='block';
         aconto.getElementById('files').style.backgroundColor='#eeeeee';
         aconto.getElementById('files').setAttribute('data-hostcont', ival);
         aconto.getElementById('files').setAttribute('data-hostspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         aconto.getElementById('files').oncontextmenu = function(event) { if (document.getElementById('mydefopt').title == 'Concat demuxer') { document.getElementById('scbi').innerHTML=listtxt; } else { var suf=event.target.getAttribute('data-hostspan');  parent.document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + event.target.getAttribute('data-hostcont'); } };
         if (ival == 'inv.mp4') {
           aconto.getElementById('files').accept='video/*';
           aconto.getElementById('files').title='Click to browse for video else right click or two finger gesture to make disappear.';
         } else if (ival.indexOf(listtxt) == 0) {
           aconto.getElementById('files').accept='video/*';
           aconto.getElementById('files').title='Click to browse for video else right click or two finger gesture to make disappear.';
           document.getElementById('moreb').title='Click to browse for video else right click or two finger gesture to make disappear.  Filenames file ' + listtxt + ' currently contains ...';
         } else if (ival.indexOf('sub.srt') == 0) {
           aconto.getElementById('files').accept='text/srt,text/vtt';
           aconto.getElementById('files').title='Click to browse for srt or vtt subtitles file.';
         } else {
           aconto.getElementById('files').accept='video/*,audio/*';
           aconto.getElementById('files').title='Click to browse for video or audio else right click or two finger gesture to make disappear.';
         }
         //alert('there');
         aconto.getElementById('dwstyle').innerHTML+=\"<style> #files::before { content: '\" + ival + \"'; } </style>\";
       }
    }
    }
  }   
  
  function checkiftwo(iois, ival) {
    if (iois.src.indexOf('?d=6') != -1) {
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
       if (aconto.document) { aconto = aconto.document; }
       if (aconto.getElementById('files')) {
         //if (voaf == '') {
         //voaf=iois.src;
         //iois.setAttribute('data-parentspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         //document.getElementById('myh1').title='s' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix');
         //setInterval(voaff, 4000);
         //} else if (voaftwo == '') {
         if (voaftwo == '') {
         voaftwo=iois.src;
         iois.setAttribute('data-parentspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         document.getElementById('myh3').title='s' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix');
         document.getElementById('myh3').setAttribute('data-url', iois.src);
         //alert(iois.id + ' data-parentspan=' + iois.getAttribute('data-parentspan'));
         }
         //alert(iois.id + ' data-parentspan=' + iois.getAttribute('data-parentspan'));
         aconto.getElementsByTagName('h1')[0].style.opacity='0.0';
         //alert('here');
         aconto.getElementById('files').style.position='absolute';
         aconto.getElementById('files').style.left='0px';
         aconto.getElementById('files').style.top='0px';
         aconto.getElementById('files').style.zIndex='99';
         aconto.getElementById('files').style.marginLeft='10px';
         aconto.getElementById('files').style.marginTop='8px';
         aconto.getElementById('files').style.visibility='visible';
         aconto.getElementById('files').style.display='block';
         aconto.getElementById('files').style.backgroundColor='#eeeeee';
         aconto.getElementById('files').setAttribute('data-hostcont', ival);
         aconto.getElementById('files').setAttribute('data-hostspan', 's' + ival.replace('inv.mp4','cbi').replace('inva.mp4','cbix'));
         //aconto.getElementById('files').oncontextmenu = function(event) { var suf=event.target.getAttribute('data-hostspan');  parent.document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + event.target.getAttribute('data-hostcont');  }
         aconto.getElementById('files').oncontextmenu = function(event) { if (document.getElementById('mydefopt').title == 'Concat demuxer') { document.getElementById('scbi').innerHTML=listtxt; } else { var suf=event.target.getAttribute('data-hostspan');  parent.document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + event.target.getAttribute('data-hostcont'); } };
         if (ival == 'inv.mp4') {
           aconto.getElementById('files').accept='video/*';
           aconto.getElementById('files').title='Click to browse for video else right click or two finger gesture to make disappear.';
         } else if (ival.indexOf(listtxt) == 0) {
           aconto.getElementById('files').accept='video/*';
           aconto.getElementById('files').title='Click to browse for video else right click or two finger gesture to make disappear.';
           document.getElementById('moreb').title='Click to browse for video else right click or two finger gesture to make disappear.  Filenames file ' + listtxt + ' currently contains ...';
         } else if (ival.indexOf('sub.srt') == 0) {
           aconto.getElementById('files').accept='text/srt,text/vtt';
           aconto.getElementById('files').title='Click to browse for srt or vtt subtitles file.';
         } else {
           aconto.getElementById('files').accept='video/*,audio/*';
           aconto.getElementById('files').title='Click to browse for video or audio else right click or two finger gesture to make disappear.';
         }
         //alert('there');
         aconto.getElementById('dwstyle').innerHTML+=\"<style> #files::before { content: '\" + ival + \"'; } </style>\";
       }
    }
    }
  }   
  
  function voaff() {
     var suf='';
     if (voaftwo.indexOf('?d=6') != -1 && document.getElementById('voiceoveraskfortwo').src.indexOf('right=') != -1 && voaftwo != document.getElementById('voiceoveraskfortwo').src && voaftwo != '' && document.getElementById('voiceoveraskfortwo').src.indexOf('?infilegetsize=') == -1) {
 //alert('Why1');
     //if (togglespan == 'scbi') {
     //  togglespan='scbix';
     //} else {
       togglespan='scbi';
     //}
       voaftwo=document.getElementById('voiceoveraskfortwo').src;
       suf=document.getElementById('myh3').title; //document.getElementById('voiceoveraskfortwo').getAttribute('data-parentspan');  
       document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + suf.replace('scbix',decodeURIComponent(voaftwo.split('filename=')[1].split('&')[0])).replace('scbi',decodeURIComponent(voaftwo.split('filename=')[1].split('&')[0]));
     } else if (voaftwo.indexOf('?d=6') != -1 && document.getElementById('voiceoveraskfortwo').src.indexOf('right=') != -1 && voaftwo != document.getElementById('voiceoveraskfor').src && voaftwo != '' && document.getElementById('voiceoveraskfor').src.indexOf('?infilegetsize=') == -1) {
 //alert('Why2');
     //if (togglespan == 'scbi') {
     //  togglespan='scbix';
     //} else {
       togglespan='scbi';
     //}
       voaftwo=document.getElementById('voiceoveraskfor').src;
       suf=document.getElementById('myh3').title; //document.getElementById('voiceoveraskfor').getAttribute('data-parentspan');  
       document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + suf.replace('scbix',decodeURIComponent(voaftwo.split('filename=')[1].split('&')[0])).replace('scbi',decodeURIComponent(voaftwo.split('filename=')[1].split('&')[0]));
     } else if (voaf != document.getElementById('voiceoveraskfor').src && document.getElementById('voiceoveraskfor').src.indexOf('left=') != -1 && voaf != '' && document.getElementById('voiceoveraskfor').src.indexOf('?infilegetsize=') == -1) {
 //alert('Why3 ' + voaf + ' ' + document.getElementById('voiceoveraskfor').src);
       //voaf=document.getElementById('voiceoveraskfor').src;
       suf=document.getElementById('myh1').title; //document.getElementById('voiceoveraskfor').getAttribute('data-parentspan');  
       //alert('suf=' + suf + ' voaf=' + voaf);
       if (nonx || (suf.indexOf('x') != -1 && !document.getElementById(suf.replace('s','')) && document.getElementById(suf.replace('s','').replace('x','')))) {
//alert('Why3 ' + voaf + ' ' + document.getElementById('voiceoveraskfor').src);
       voaf=document.getElementById('voiceoveraskfor').src;
       //alert('Suf=' + suf + ' voaf=' + voaf);
       if (document.getElementById(suf.replace('x','')).innerHTML.indexOf(' ') != 0) {
     //if (togglespan == 'scbi') {
       togglespan='scbix';
     //} else {
     //  togglespan='scbi';
     //}
       document.getElementById(suf.replace('x','')).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + suf.replace('scbix',decodeURIComponent(voaf.split('filename=')[1].split('&')[0])).replace('scbi',decodeURIComponent(voaf.split('filename=')[1].split('&')[0]));
       }
       } else if (dox || (!document.getElementById(suf.replace('s','')) && document.getElementById(suf.replace('s','') + 'x'))) {
       if (document.getElementById('voiceoveraskfor').src.indexOf('left=') == -1) {
//alert('WhY3 ' + voaf + ' ' + document.getElementById('voiceoveraskfor').src);
       voaf=document.getElementById('voiceoveraskfor').src;
       //alert('SUf=' + suf + ' voaf=' + voaf);
       if (document.getElementById(suf + 'x').innerHTML.indexOf(' ') != 0) {
     //if (togglespan == 'scbi') {
     //  togglespan='scbix';
     //} else {
       togglespan='scbi';
     //}
       document.getElementById(suf + 'x').innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + suf.replace('scbix',decodeURIComponent(voaf.split('filename=')[1].split('&')[0])).replace('scbi',decodeURIComponent(voaf.split('filename=')[1].split('&')[0]));
       }
       }
       } else {
//alert('WHY3 ' + voaf + ' ' + document.getElementById('voiceoveraskfor').src);
       voaf=document.getElementById('voiceoveraskfor').src;
       //alert('SUF=' + suf + ' voaf=' + voaf);
       if (document.getElementById(suf).innerHTML.indexOf(' ') != 0) {
     //if (togglespan == 'scbi') {
       togglespan='scbix';
     //} else {
     //  togglespan='scbi';
     //}
       document.getElementById(suf).innerHTML=\"" . str_replace("\\","\\\\",dirname(__FILE__) . DIRECTORY_SEPARATOR) . "\" + suf.replace('scbix',decodeURIComponent(voaf.split('filename=')[1].split('&')[0])).replace('scbi',decodeURIComponent(voaf.split('filename=')[1].split('&')[0]));
       }
       }
     }
  }
          
  function overlay() {
   origval=document.getElementById('schoices').value;
   var rect=document.getElementById('fcommand').getBoundingClientRect();
   document.getElementById('moreb').style.position='absolute';
   document.getElementById('moreb').style.left='' + rect.left + 'px';
   document.getElementById('moreb').style.top='' + rect.top + 'px';
   document.getElementById('moreb').style.width='96%'; //' + rect.width + 'px';
   document.getElementById('moreb').style.height='' + rect.height + 'px';
   document.getElementById('moreb').style.border='1px solid black';
   document.getElementById('moreb').style.paddingLeft='20px';
   document.getElementById('moreb').style.backgroundColor='#f9f9f9';
   document.getElementById('fcommand').style.opacity='0.0';
   document.getElementById('fcommand').style.cursor='pointer';
   document.getElementById('moreb').innerHTML='<span id=precmds></span><span id=verb>ffmpeg" . $ffmpegsuf . "</span> <span id=prescbi></span><span id=minusi> -i </span><span id=scbi><iframe onload=checkif(this,\"inv.mp4\"); scrolling=no frameborder=0 id=cbi data-type=file data-value=inv.mp4 data-accept=\"video/*\" style=\"display:inline-block;height:40px;width:92px;vertical-align:middle;\" src=\"/HTMLCSS/client_browsing.htm?d=69075964842271&left=y\"></iframe></span> <span id=betweenis></span> <span id=secondi>-i <span id=scbix><iframe onload=checkiftwo(this,\"inva.mp4\"); scrolling=no frameborder=0 id=cbix data-type=file data-value=inva.mp4 data-accept=\"video/*\" style=\"display:inline-block;height:40px;width:106px;vertical-align:middle;\" src=\"/HTMLCSS/client_browsing.htm?d=69075964842271&right=y\"></iframe></span></span> <span id=sswitches>-c copy -map 0:v:0 -map 1:a:0 -shortest</span> out.mp4 &gt; <a target=_blank title=ffm.bad onclick=getvb(); style=cursor:pointer;text-decoration:underline; data-href=./ffm.bad>ffm.bad</a>';
   if (firstdivih == '') { firstdivih=document.getElementById('moreb').innerHTML; }
   if (firstbutval == '') { firstbutval=document.getElementById('mysub').value; }
   document.getElementById('schoices').style.display='inline-block';
  }
  
  function mergechanges() {
     if (document.getElementById('mydefopt').title == 'Concat demuxer') {
       document.getElementById('scbi').innerHTML=listtxt;
     }
     if (document.getElementById('scbi').innerHTML.indexOf('<') == -1) {
       if (document.getElementById('precmds').innerHTML != '') {
       if (document.getElementById('mydefopt').title == 'Concat demuxer') {
        document.getElementById('precmds').innerHTML=document.getElementById('precmds').innerHTML.trim();
       }
       document.getElementById('fcommand').value=document.getElementById('moreb').innerText;
       } else {
       document.getElementById('fcommand').value=document.getElementById('fcommand').value.replace(' inv.mp4 ', ' ' + document.getElementById('scbi').innerHTML + ' ');
       }
       //alert('not oops ' + document.getElementById('fcommand').value);
     } //else {
       //alert('oops');
     //}
     if (document.getElementById('scbix')) {
     if (document.getElementById('scbix').innerHTML.indexOf('<') == -1) {
       //alert('zoops');
       document.getElementById('fcommand').value=document.getElementById('fcommand').value.replace(' inva.mp4 ', ' ' + document.getElementById('scbix').innerHTML + ' ');
     }
     }
     if (document.getElementById('moreb').innerText.indexOf(' -c ') != -1 && document.getElementById('fcommand').value.indexOf(' -c ') != -1) {
      //alert('azoops');
      if (document.getElementById('moreb').innerText.split(' -c ')[1] != document.getElementById('fcommand').value.split(' -c ')[1]) {
       //alert('bzoops');
       document.getElementById('fcommand').value=document.getElementById('fcommand').value.split(' -c ')[0] + ' -c ' + document.getElementById('moreb').innerText.split(' -c ')[1];
      }
     }
     return true;
  }
  
  function process(tv, tvo) {
    var newval='';
    if (origval == '') { origval=document.getElementById('mydefopt').title;  }
    if (tv == '') {
      document.getElementById('mainspan').innerHTML=document.getElementById('mydefopt').title;
    } else {
      document.getElementById('mydefopt').title=tv;
      document.getElementById('mainspan').innerHTML=document.getElementById('mydefopt').title;
      document.getElementById('schoices').value='';
    }
    newval=document.getElementById('mydefopt').title;
    //alert('origval,newval=' + origval + ' ' + newval);
    if (newval != origval) {
      origval=newval;
      wentfrom(origval, newval);
    } else {
      origval=newval;
    }
  }
  
  function putbackonblur() {
       document.getElementById('scbi').onblur=function(event) {  if (document.getElementById('mydefopt').title == 'Concat demuxer') {  if (event.target.innerHTML.replace(/\&nbsp\;/g,' ').trim() == '') { event.target.innerHTML=listtxt;  } if (event.target.innerHTML.toLowerCase().indexOf('.txt') == -1) {  if (event.target.innerHTML.indexOf('.') != -1) { document.getElementById('ifs').innerHTML+='<iframe id=voaskfor' + ifile + ' style=display:none; src=\"./voiceover.php?infilegetsize=' + encodeURIComponent(listtxt + ';' + event.target.innerHTML) + '\"></iframe>';  ifile++;    if (document.getElementById('moreb').title.indexOf(\"file '\" + event.target.innerHTML.replace(String.fromCharCode(34),'').replace(String.fromCharCode(34),'') + \"'\") == -1) {     document.getElementById('moreb').title+=String.fromCharCode(10) + \"file '\" + event.target.innerHTML.replace(String.fromCharCode(34),'').replace(String.fromCharCode(34),'') + \"'\"; } } } event.target.innerHTML=listtxt; if (document.getElementById('minusi')) { document.getElementById('minusi').innerHTML=' -i ';  }  }  };
  }
  
  function wentfrom(oldv, newv) {
    if (newv == 'Burn subtitles') {
       document.getElementById('moreb').innerHTML=firstdivih;
       //document.getElementById('precmds').innerHTML=document.getElementById('verb').innerHTML + ' ' + document.getElementById('secondi').innerHTML.replace(/inva\.mp4/g,'sub.srt      ') + ' sub.ass; ';
       document.getElementById('precmds').innerHTML=document.getElementById('verb').innerHTML + ' ' + document.getElementById('secondi').innerHTML.replace(/inva\.mp4/g,'sub.srt      ') + ' <span id=subass contenteditable=false>sub.ass;</span> ';
       document.getElementById('secondi').innerHTML='';
       //document.getElementById('sswitches').innerHTML='-vf ass=sub.ass';
       document.getElementById('sswitches').innerHTML='-vf<span id=asssubass contenteditable=false> ass=sub.ass </span>';
       document.getElementById('mysub').value=newv;
    } else if (newv == 'Concat demuxer') {
       document.getElementById('precmds').innerHTML=' ';
       document.getElementById('secondi').innerHTML='';
       document.getElementById('prescbi').innerHTML=' -f concat -safe 0 ';
       document.getElementById('scbi').innerHTML=document.getElementById('scbi').innerHTML.replace(/inv\.mp4/g,listtxt + '      ').replace('left=y','concat=' + encodeURIComponent(listtxt));
       document.getElementById('scbi').setAttribute('contenteditable', true);
       document.getElementById('scbi').onblur=function(event) {  if (document.getElementById('mydefopt').title == 'Concat demuxer') {  if (event.target.innerHTML.replace(/\&nbsp\;/g,' ').trim() == '') { event.target.innerHTML=listtxt;  } if (event.target.innerHTML.toLowerCase().indexOf('.txt') == -1) {  if (event.target.innerHTML.indexOf('.') != -1) { document.getElementById('ifs').innerHTML+='<iframe id=voaskfor' + ifile + ' style=display:none; src=\"./voiceover.php?infilegetsize=' + encodeURIComponent(listtxt + ';' + event.target.innerHTML) + '\"></iframe>';  ifile++;    if (document.getElementById('moreb').title.indexOf(\"file '\" + event.target.innerHTML.replace(String.fromCharCode(34),'').replace(String.fromCharCode(34),'') + \"'\") == -1) {     document.getElementById('moreb').title+=String.fromCharCode(10) + \"file '\" + event.target.innerHTML.replace(String.fromCharCode(34),'').replace(String.fromCharCode(34),'') + \"'\"; } } } event.target.innerHTML=listtxt; if (document.getElementById('minusi')) { document.getElementById('minusi').innerHTML=' -i ';  }  }  };
       document.getElementById('moreb').onblur=function(event) {  if (document.getElementById('mydefopt').title == 'Concat demuxer') {  if (document.getElementById('minusi')) { var thingos=document.getElementById('minusi').innerHTML.replace(/\&nbsp\;/g,' ').trim().split('-i '); if (thingos.length > 1) { if (thingos[1].trim() != '' && (thingos[1] + '~').toLowerCase().indexOf('.txt~') == -1) { spanfill(thingos[1]); }  } document.getElementById('minusi').innerHTML=' -i ';  }  if (!document.getElementById('scbi')) { event.target.innerHTML=event.target.innerHTML.replace('<span id=\"between', '<span id=scbi contenteditable=true>' + listtxt + '</span> <span id=\"between');  putbackonblur(); if (event.target.innerHTML.indexOf('> -i </span><span id=\"scbi\"') == -1) { event.target.innerHTML=event.target.innerHTML.replace('</span>' + event.target.innerHTML.split('<span id=\"scbi\"')[0].split('</span>')[-1 + eval(event.target.innerHTML.split('<span id=\"scbi\"')[0].split('</span>').length)],'</span>');   } } }  };
       document.getElementById('sswitches').innerHTML='-c copy';
       document.getElementById('mysub').value=newv;
   //alert('./voiceover.php" . $whereffmpeg . "' + encodeURIComponent(listtxt));
       document.getElementById('ffmwhere').src='./voiceover.php" . $whereffmpeg . "' + encodeURIComponent(listtxt);
   //alert('voiceover.php" . $whereffmpeg . "' + encodeURIComponent(listtxt));
    } else if (newv == 'Add Voiceover Audio to Video') {
       document.getElementById('moreb').innerHTML=firstdivih;
       document.getElementById('mysub').value=firstbutval;
    }
  }
  
  function takeoffone() {
    ibfile--;
    if (ibfile <= 0) {
      document.getElementById('mysub').style.cursor='pointer';
    } else {
      document.getElementById('mysub').style.cursor='progress';
    }
  }
  
  function organizefilenamesize(fn, fs) {
    document.getElementById('ifs').innerHTML+='<iframe id=voaskfor' + ifile + ' style=display:none; src=\"./voiceover.php?concat=' + encodeURIComponent('list.txt') + '&filename=' + encodeURIComponent(fn) + '&haveasleep=' + eval(3 * eval('' + ifile)) + '&filesize=' + fs + '\"></iframe>';
    if (ibfile == 0) {
      document.getElementById('mysub').style.cursor='progress';
    }
    ifile++;
    ibfile++;
    if (document.getElementById('moreb').title.indexOf(\"file '\" + fn.replace(String.fromCharCode(34),'').replace(String.fromCharCode(34),'') + \"'\") == -1) {
    document.getElementById('moreb').title+=String.fromCharCode(10) + \"file '\" + fn.replace(String.fromCharCode(34),'').replace(String.fromCharCode(34),'') + \"'\";
    }
  }
</script>
</head>
<body onload=\" document.getElementById('mainspan').title=document.getElementById('schoices').innerText.replace(/\ \ /g,', ');  overlay(); if (document.URL.indexOf('rjmprogramming.com.au/') != -1) {   if (('' + window.navigator.platform).toLowerCase().indexOf('mac') == 0) { window.open('HTTP://localhost:8888/voiceover.php','_blank','top=50,left=50,width=' + eval(0.8 * screen.width) + ',height=600'); } else {  window.open('HTTP://localhost/voiceover.php','_blank','top=50,left=50,width=' + eval(0.8 * screen.width) + ',height=600');  }  }\">
<h1 id=myh1><span id=mainspan>Add Voiceover Audio to Video</span> via <a target=_blank title=ffmpeg href='//ffmpeg.org'>ffmpeg</a>&nbsp<select onchange=process(this.value,this); style=display:none; id=schoices><option id=mydefopt title='Add Voiceover Audio to Video' value=''>&#10549;</option><option value='Add Voiceover Audio to Video'> Add Voiceover Audio to Video</option><option value='Burn subtitles'>  Burn subtitles</option><option value='Concat demuxer'>  Concat demuxer</option></select></h1>
<h3 id=myh3>RJM Programming <a target=_self title=Rerun href='./voiceover.php'>-</a> May, 2023</h3>
<form onsubmit='return mergechanges();' method=GET action=./voiceover.php>
<textarea id=fcommand name=fcommand value='' style='cursor:progress;width:98%;height:50px;'>
" . $ffmpegpre . "ffmpeg" . $ffmpegsuf . " -i inv.mp4 -i inva.mp4 -c copy -map 0:v:0 -map 1:a:0 -shortest out.mp4 > ffm.bad
</textarea><br><br>
<input id=mysub type=submit value='Create New Video with Audio Voiceover' style='background-color:lightgreen;'></input>
</form>
<br><br><hr></hr><br><br>
<div>" . $rs . "</div><br>
<div id=moreb contenteditable=true></div>
<iframe id=voaskfor style=display:none; src=./voiceover.php?infilegetsize=></iframe>
<iframe id=voiceoveraskfor style=display:none; src=./voiceover.php?infilegetsize=></iframe>
<iframe id=voiceoveraskfortwo style=display:none; src=./voiceover.php?infilegetsize=></iframe>
<iframe id=ffmwhere style=display:none; src=./voiceover.php" . $whereffmpeg . "></iframe>
<div id=ifs style=display:none;></div>
</body>
</html>";

?>