Proyectos de Subversion LeadersLinked - Services

Rev

Rev 333 | Rev 345 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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