src/Controller/PlayController.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\Persistence\ManagerRegistry;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Cerebro\Cerebro;
  11. use App\Entity\Media;
  12. class PlayController extends AbstractController
  13. {
  14.     private $device;
  15.     private $filename;
  16.     private $file;
  17.     protected $session;
  18.     protected $registry;
  19.     protected $em;
  20.     protected $path;
  21.     public function __construct(SessionInterface $sessionManagerRegistry $registry)
  22.     {
  23.         $this->session $session;
  24.         $this->registry $registry;
  25.         $this->em $registry->getManager();
  26.         $this->path "/var/www/html/urconnex/public";
  27.         $cerebro = new Cerebro();
  28.         $this->device $cerebro->findDeviceProperties();
  29.     }
  30.     /**
  31.      * @Route("/play/index/{filename}", name="app_play_index")
  32.      */
  33.     public function index(Request $requeststring $filename): Response
  34.     {
  35.         // Fetch the media from the database
  36.         $media $this->em->getRepository(Media::class)->findByViews(1);
  37.         
  38.         if ($this->device['reswidth'] < 500 || $this->device['resheight'] < 500) {
  39.             return $this->render('play/index.html.twig', [
  40.                 'mediafiles' => $media,
  41.                 'filename' => $filename,
  42.             ]);
  43.         }else{
  44.             return $this->render('play/index.html.twig', [
  45.                 'mediafiles' => $media,
  46.                 'filename' => $filename,
  47.                 'desktop' => 1
  48.             ]);
  49.         }
  50.         // Render the template with the media passed as a variable
  51.         
  52.     }
  53.     /**
  54.      * @Route("/play/process", name="app_play_process")
  55.      */
  56.     public function process(Request $request$filename): JsonResponse
  57.     {
  58.         //$this->em = $registry->getManager();
  59.         //$filename = $request->query->get('filename');
  60.         $file $this->em->getRepository(Media::class)->findOneBy(['filename' => $filename]);
  61.         //$gp = MediaManager::convertTo3gp($this->path, $this->device['reswidth'], $this->device['resheight']);
  62.         //echo $this->path;
  63.         //var_dump(get_class_methods($file));
  64.         
  65.         
  66.         if (!$file) {
  67.             return new JsonResponse(['error' => 'File not found'], 404);
  68.         }
  69.         
  70.         if ($this->device['reswidth'] < 500 || $this->device['resheight'] < 500) {
  71.             $gp "https://urconnex.com/media/files/".$this->getMobileBuild($this->path.$file->getFilepath(), $file->getFilename());
  72.             $streamlink "https://urconnex.com/media/files/".$this->device['reswidth'].$filename.".3gp";
  73.             $stream "https://urconnex.com/".$file->getFilepath();
  74.             $data = [
  75.                 'stream' => $stream,
  76.                 'mp4' => $stream,
  77.                 'gp' => $gp,
  78.             ];
  79.             
  80.         }else{
  81.             $f $this->getDesktopBuild($this->path.$file->getFilepath(), $file->getFilename());
  82.             $webm "https://urconnex.com/media/files/".$file->getFilename().".webm";
  83.             $poster $file->getThumbnail();
  84.             $data = [
  85.                 'webm' => $webm,
  86.                 'poster' => $poster,
  87.                 'desktop' => 1
  88.             ];
  89.         }
  90.         $seotag 'Watching ' $file->getFilename();
  91.         
  92.         // Return the links
  93.         
  94.         return new JsonResponse($data);
  95.     }
  96.     private function getMobileBuild($newpath$filename) {
  97.         $desktop 0;
  98.         $newfile $this->path."/media/files/".$this->device['reswidth'].$filename.".3gp";
  99.         if($this->device['reswidth'] > 1000){
  100.             $cmd "/usr/bin/ffmpeg -i ".$newpath." -r 20 -vb 400k -acodec aac -strict experimental -ac 1 -ar 8000 -ab 24k -s 1408x1152 ".$newfile;
  101.         }
  102.         if($this->device['reswidth'] < 800 && $this->device['reswidth'] > 600){
  103.             $cmd "/usr/bin/ffmpeg -i ".$newpath." -r 20 -vb 400k -acodec aac -strict experimental -ac 1 -ar 8000 -ab 24k -s 704x576 ".$newfile;
  104.         }
  105.         if($this->device['reswidth'] < 600 && $this->device['reswidth'] > 300){
  106.             $cmd "/usr/bin/ffmpeg -i ".$newpath." -r 20 -vb 400k -acodec aac -strict experimental -ac 1 -ar 8000 -ab 24k -s 352x288 ".$newfile;
  107.         }
  108.         if($this->device['reswidth'] < 250 && $this->device['reswidth'] > 150){
  109.             $cmd "/usr/bin/ffmpeg -i ".$newpath." -r 20 -vb 400k -acodec aac -strict experimental -ac 1 -ar 8000 -ab 24k -s 176x144 ".$newfile;
  110.         }
  111.         if($this->device['reswidth'] < 130 && $this->device['reswidth'] > 90){
  112.             $cmd "/usr/bin/ffmpeg -i ".$newpath." -r 20 -vb 400k -acodec aac -strict experimental -ac 1 -ar 8000 -ab 24k -s 128x96 ".$newfile;
  113.         }
  114.         shell_exec($cmd);
  115.         if(file_exists($newfile)){
  116.             return $this->device['reswidth'].$filename.".3gp";
  117.         }else{
  118.             return "101";
  119.         }
  120.     }
  121.     private function getDesktopBuild($newpath$filename){
  122.         //build versions for desktop player
  123.         $newfile $this->path."/media/files/".$filename.".webm";
  124.         $cmd "/usr/bin/ffmpeg -i ".$newpath." -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus -s ".$this->device['reswidth']."x".$this->device['resheight']." ".$newfile;
  125.         shell_exec($cmd);
  126.         if(file_exists($newfile)){
  127.             return $filename.".webm";
  128.         }else{
  129.             return "102";
  130.         }
  131.     }
  132. }