Advertisement
programmingjob

Untitled

Jan 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * To change this license header, choose License Headers in Project Properties.
  5. * To change this template file, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8.  
  9. namespace Dmcl\AppBundle\Command;
  10.  
  11. /**
  12. * Description of AnuciosCommand
  13. *
  14. * @author dani
  15. */
  16. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand,
  17. Symfony\Component\Console\Input\InputInterface,
  18. Symfony\Component\Console\Input\InputOption,
  19. Symfony\Component\Console\Output\OutputInterface
  20.  
  21. ;
  22.  
  23. class ScreenshotCommand extends ContainerAwareCommand {
  24.  
  25. protected $container;
  26.  
  27. protected function configure() {
  28. $this->setName('webpanel:screenshot');
  29. }
  30.  
  31. protected function execute(InputInterface $input, OutputInterface $output) {
  32. $this->container = $this->getContainer();
  33. $em = $this->container->get('doctrine')->getManager();
  34. $d = new \DateTime("now");
  35. if(file_exists($this->container->getParameter('kernel.logs_dir')."/.lastScreenshot")){
  36. try {
  37. $d = new \DateTime(file_get_contents($this->container->getParameter('kernel.logs_dir')."/.lastScreenshot"));
  38. } catch (\Exception $e) {
  39. $d = new \DateTime("now");
  40. }
  41. }else{
  42. file_put_contents($this->container->getParameter('kernel.logs_dir')."/.lastScreenshot",$d->format("Y/m/d h:i:s"));
  43. }
  44.  
  45.  
  46.  
  47. // $fr->$format("Y/m/d")
  48.  
  49. $errorReport = "";
  50. $config = $em->getRepository('AppBundle:Config')->findOneBy(array());
  51. if($config){
  52.  
  53. $screenShotIntervals=$config->getScreenshot();
  54. $now = new \
  55. DateTime("now");
  56. $diff = $now->diff($d);
  57. if($diff->i >= $screenShotIntervals){
  58. $now = new \DateTime("now");
  59. file_put_contents($this->container->getParameter('kernel.logs_dir')."/.lastScreenshot",$now->format("Y/m/d h:i:s"));
  60. $channels = $em->getRepository('AppBundle:Channels')->findAll();
  61.  
  62. // $folder = $config->getScreenshotPath() . "webpanel-screenshot/".$now->format("Y-m-d-h-i-s");
  63. $folder = $this->container->getParameter('uploadLogo')."snapshots/";
  64. if(!is_dir($folder)){
  65. mkdir($folder);
  66. }
  67. foreach ($channels as $entity) {
  68. if($entity->getScreenshot()){
  69. if (file_exists($this->container->getParameter('kernel.logs_dir') . "/cmd_output/" . trim($entity->_getName()) . "/" . trim($entity->_getName()) . ".pid")) {
  70. $pid = @file_get_contents($this->container->getParameter('kernel.logs_dir') . "/cmd_output/" . trim($entity->_getName()) . "/" . trim($entity->_getName()) . ".pid");
  71. $pid = str_replace("\n", "", $pid);
  72. $pid+=0;
  73. if (file_exists("/proc/$pid") && $pid != "") {
  74. if(!is_dir($folder)){
  75. mkdir($folder);
  76. }
  77. @exec("/usr/share/webpanel/libs/ffmpeg/ffmpeg -i ".trim($entity->getOutputurl())." -ss 00:00:10 -vframes 1 -s 470X380 -y $folder".$entity->getId().".png > /dev/null 2>&1 &");
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84.  
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement