Proyectos de Subversion LeadersLinked - Services

Rev

Rev 334 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 334 Rev 345
Línea 1... Línea 1...
1
<?php
1
<?php
2
 
-
 
3
declare(strict_types=1);
2
declare(strict_types = 1);
4
 
-
 
5
namespace LeadersLinked\Command;
3
namespace LeadersLinked\Command;
Línea 6... Línea 4...
6
 
4
 
7
use Symfony\Component\Console\Command\Command;
5
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
10
use Laminas\Db\Adapter\AdapterInterface;
-
 
11
 
8
use Laminas\Db\Adapter\AdapterInterface;
12
use Laminas\Log\LoggerInterface;
9
use Laminas\Log\LoggerInterface;
13
use LeadersLinked\Mapper\VideoConvertMapper;
10
use LeadersLinked\Mapper\VideoConvertMapper;
14
use LeadersLinked\Model\VideoConvert;
11
use LeadersLinked\Model\VideoConvert;
15
use Laminas\Mvc\I18n\Translator;
12
use Laminas\Mvc\I18n\Translator;
16
use LeadersLinked\Cache\CacheInterface;
13
use LeadersLinked\Cache\CacheInterface;
Línea 17... Línea 14...
17
use LeadersLinked\Library\Storage;
14
use LeadersLinked\Library\Storage;
18
 
15
 
-
 
16
class ProcessQueueVideoConvertCommand extends Command
19
class ProcessQueueVideoConvertCommand extends Command
17
{
20
{
18
 
21
    /**
19
    /**
22
     *
20
     *
23
     * @var \Laminas\Db\Adapter\AdapterInterface
21
     * @var \Laminas\Db\Adapter\AdapterInterface
24
     */
22
     */
25
    private $adapter;
23
    private $adapter;
26
    
24
 
27
    /**
25
    /**
28
     *
26
     *
29
     * @var \LeadersLinked\Cache\CacheInterface
27
     * @var \LeadersLinked\Cache\CacheInterface
30
     */
-
 
31
    private $cache;
28
     */
32
    
29
    private $cache;
33
    
30
 
34
    /**
31
    /**
35
     *
32
     *
36
     * @var \Laminas\Log\LoggerInterface
33
     * @var \Laminas\Log\LoggerInterface
37
     */
34
     */
38
    private $logger;
35
    private $logger;
39
    
36
 
40
    /**
37
    /**
41
     *
38
     *
42
     * @var array
39
     * @var array
43
     */
-
 
44
    private $config;
40
     */
45
    
41
    private $config;
46
    
42
 
47
    /**
43
    /**
48
     *
44
     *
49
     * @var \Laminas\Mvc\I18n\Translator
45
     * @var \Laminas\Mvc\I18n\Translator
50
     */
-
 
51
    private $translator;
46
     */
52
    
47
    private $translator;
53
    
48
 
54
    /**
49
    /**
55
     *
50
     *
-
 
51
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
56
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
52
     * @param \LeadersLinked\Cache\CacheInterface $cache
57
     * @param \LeadersLinked\Cache\CacheInterface $cache
53
     * @param
58
     * @param \Laminas\Log\LoggerInterface
54
     *            \Laminas\Log\LoggerInterface
59
     * @param array $config
55
     * @param array $config
60
     * @param \Laminas\Mvc\I18n\Translator $translator
56
     * @param \Laminas\Mvc\I18n\Translator $translator
61
     */
57
     */
62
    public function __construct($adapter, $cache, $logger, $config, $translator)
58
    public function __construct($adapter, $cache, $logger, $config, $translator)
63
    {
59
    {
64
        $this->adapter      = $adapter;
60
        $this->adapter = $adapter;
65
        $this->cache        = $cache;
61
        $this->cache = $cache;
66
        $this->logger       = $logger;
62
        $this->logger = $logger;
67
        $this->config       = $config;
63
        $this->config = $config;
68
        $this->translator   = $translator;
64
        $this->translator = $translator;
69
        
65
 
Línea 70... Línea -...
70
        parent::__construct();
-
 
71
    }
66
        parent::__construct();
72
 
67
    }
73
    
-
 
74
    protected function execute(InputInterface $input, OutputInterface $output) : int
-
 
75
    {
68
 
76
 
69
    protected function execute(InputInterface $input, OutputInterface $output): int
77
        
70
    {
78
        $checkExists = true;
-
 
79
        $videos_procesados = 0;
71
        $checkExists = true;
80
        $videos_ignorados = 0;
72
        $videos_procesados = 0;
81
        
73
        $videos_ignorados = 0;
82
        
74
 
83
        $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
75
        $videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
84
        $videos = $videoConvertMapper->fetchBatch();
76
        $videos = $videoConvertMapper->fetchBatch();
85
        
77
 
86
        $storage = Storage::getInstance($this->config, $this->adapter);
-
 
87
        
78
        $storage = Storage::getInstance($this->config, $this->adapter);
88
        foreach($videos as $video)
79
 
89
        {
80
        foreach ($videos as $video) {
90
            
-
 
91
            if($video->type == VideoConvert::TYPE_FEED) {
81
 
92
                $targe_path = $storage->getPathFeed();
82
            if ($video->type == VideoConvert::TYPE_FEED) {
93
            } 
-
 
94
            else if($video->type == VideoConvert::TYPE_MICRO_LEARNING_SLIDES) {
83
                $targe_path = $storage->getPathFeed();
95
                $targe_path = $storage->getPathMicrolearningSlide();
84
            } else if ($video->type == VideoConvert::TYPE_MICRO_LEARNING_SLIDES) {
96
            }
-
 
97
            else if($video->type == VideoConvert::TYPE_MEDIA) {
85
                $targe_path = $storage->getPathMicrolearningSlide();
98
                $targe_path = $storage->getPathMedia();
86
            } else if ($video->type == VideoConvert::TYPE_MEDIA) {
99
            }
87
                $targe_path = $storage->getPathMedia();
100
            else if($video->type == VideoConvert::TYPE_HABIT_CONTENT) {
88
            } else if ($video->type == VideoConvert::TYPE_HABIT_CONTENT) {
101
                    $targe_path = $storage->getPathHabitContent();
89
                $targe_path = $storage->getPathHabitContent();
102
            } else {
90
            } else {
103
                $targe_path = '';
91
                $targe_path = '';
104
            }
92
            }
105
            
93
 
106
            if(empty($targe_path)) {
94
            if (empty($targe_path)) {
107
                $videos_ignorados++;
95
                $videos_ignorados ++;
Línea 108... Línea -...
108
                $videoConvertMapper->delete($video);
-
 
109
                continue;
96
                $videoConvertMapper->delete($video);
110
            }
97
                continue;
111
 
98
            }
112
            
99
 
113
            $directory = $storage->getDirectoryFromDisk($targe_path, $video->uuid);
100
            $directory = $storage->getDirectoryFromDisk($targe_path, $video->uuid);
114
           
101
 
115
            $currentfile = $directory . DIRECTORY_SEPARATOR .  $video->filename;
102
            $currentfile = $directory . DIRECTORY_SEPARATOR . $video->filename;
116
            $posterfile  = $directory . DIRECTORY_SEPARATOR .  substr($video->filename, 0, strrpos($video->filename, '.')).  '.jpg';
103
            $posterfile = $directory . DIRECTORY_SEPARATOR . substr($video->filename, 0, strrpos($video->filename, '.')) . '.jpg';
117
            
104
 
118
            if(!file_exists($currentfile)) {
105
            if (! file_exists($currentfile)) {
119
                $videos_ignorados++;
106
                $videos_ignorados ++;
120
                $videoConvertMapper->delete($video);
107
                $videoConvertMapper->delete($video);
121
                continue;
108
                continue;
122
            }
109
            }
123
            
110
 
124
            $s = explode('.', $video->filename);
111
            $s = explode('.', $video->filename);
125
            
112
 
126
            $tmpfile    = sys_get_temp_dir()  . DIRECTORY_SEPARATOR . $s[0] . '-tmp.' . $s[1];
113
            $tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $s[0] . '-tmp.' . $s[1];
127
            $newfile    = sys_get_temp_dir()  . DIRECTORY_SEPARATOR . $video->filename;
114
            $newfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $video->filename;
128
      
115
 
129
            if(!@copy($currentfile, $tmpfile)) {
-
 
130
                $videos_ignorados++;
116
            if (! @copy($currentfile, $tmpfile)) {
131
                $videoConvertMapper->delete($video);
117
                $videos_ignorados ++;
132
                continue;
118
                $videoConvertMapper->delete($video);
133
                
119
                continue;
134
            }
120
            }
135
            
121
 
136
            if(file_exists($tmpfile)) {
122
            if (file_exists($tmpfile)) {
137
  
123
 
138
                if(!file_exists($posterfile)) {
124
                if (! file_exists($posterfile)) {
139
                    \LeadersLinked\Library\Video::extractPoster($tmpfile, $posterfile);
125
                    \LeadersLinked\Library\Video::extractPoster($tmpfile, $posterfile);
140
                }
126
                }
Línea 141... Línea 127...
141
                
127
 
142
                $cmd = "/usr/bin/ffmpeg -y -i $tmpfile  -preset medium -crf 24 -codec:v libx264 $newfile";  
128
                $cmd = "/usr/bin/ffmpeg -y -i $tmpfile  -preset medium -crf 24 -codec:v libx264 $newfile";
143
                $output->writeln("command  : $cmd" );
129
                $output->writeln("command  : $cmd");
144
                exec($cmd);
130
                exec($cmd);
145
 
131
 
146
                @copy($newfile, $currentfile);
132
                @copy($newfile, $currentfile);
147
                
133
 
148
                @unlink($tmpfile);
-
 
149
                @unlink($newfile);
134
                @unlink($tmpfile);
150
 
135
                @unlink($newfile);
151
                $videos_procesados++;
136
 
152
                $videoConvertMapper->delete($video);
137
                $videos_procesados ++;
153
                
138
                $videoConvertMapper->delete($video);
154
            } else {
139
            } else {
Línea 155... Línea 140...
155
                $videoConvertMapper->delete($video);
140
                $videoConvertMapper->delete($video);
156
                $output->writeln("El video no existe  : " . $video->filename);
141
                $output->writeln("El video no existe  : " . $video->filename);
157
                $videos_ignorados++;
142
                $videos_ignorados ++;
158
            }
143
            }
159
        }
144
        }
160
 
145
 
161
        $output->writeln('Videos procesados:'  . $videos_procesados);
146
        $output->writeln('Videos procesados:' . $videos_procesados);
162
        $output->writeln('Videos ignorados:'  . $videos_ignorados);
-
 
163
        
-
 
164
        $output->writeln('Fin del proceso de la cola de  Videos');
-
 
165
        
147
        $output->writeln('Videos ignorados:' . $videos_ignorados);
166
        return 0;
148