Passed
Push — master ( f7876c...c16b3d )
by Amin
03:17
created

HLS::getHlsListSize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * This file is part of the PHP-FFmpeg-video-streaming package.
5
 *
6
 * (c) Amin Yazdanpanah <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Streaming;
13
14
use Streaming\Filters\HLSFilter;
15
use Streaming\Filters\Filter;
16
17
class HLS extends Streaming
18
{
19
    /** @var string */
20
    private $hls_time = 10;
21
22
    /** @var bool */
23
    private $hls_allow_cache = true;
24
25
    /** @var string */
26
    private $hls_key_info_file = "";
27
28
    /** @var string */
29
    private $ts_sub_directory = "";
30
31
    /** @var string */
32
    private $hls_base_url = "";
33
34
    /** @var int */
35
    private $hls_list_size = 0;
36
37
    /** @var bool */
38
    public $tmp_key_info_file = false;
39
40
    /**
41
     * @return string
42
     */
43
    public function getTsSubDirectory(): string
44
    {
45
        return $this->ts_sub_directory;
46
    }
47
48
    /**
49
     * @param string $ts_sub_directory
50
     * @return HLS
51
     */
52
    public function setTsSubDirectory(string $ts_sub_directory)
53
    {
54
        $this->ts_sub_directory = $ts_sub_directory;
55
        return $this;
56
    }
57
58
    /**
59
     * @param string $hls_time
60
     * @return HLS
61
     */
62
    public function setHlsTime(string $hls_time): HLS
63
    {
64
        $this->hls_time = $hls_time;
65
        return $this;
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getHlsTime(): string
72
    {
73
        return $this->hls_time;
74
    }
75
76
    /**
77
     * @param bool $hls_allow_cache
78
     * @return HLS
79
     */
80
    public function setHlsAllowCache(bool $hls_allow_cache): HLS
81
    {
82
        $this->hls_allow_cache = $hls_allow_cache;
83
        return $this;
84
    }
85
86
    /**
87
     * @return bool
88
     */
89
    public function isHlsAllowCache(): bool
90
    {
91
        return $this->hls_allow_cache;
92
    }
93
94
    /**
95
     * @param string $hls_key_info_file
96
     * @return HLS
97
     */
98
    public function setHlsKeyInfoFile(string $hls_key_info_file): HLS
99
    {
100
        $this->hls_key_info_file = $hls_key_info_file;
101
        return $this;
102
    }
103
104
    /**
105
     * @param string $save_to
106
     * @param string $url
107
     * @param int $length
108
     * @return HLS
109
     */
110
    public function encryption(string $save_to, string $url, int $length = 16): HLS
111
    {
112
        $this->setHlsKeyInfoFile(HLSKeyInfo::generate($save_to, $url, $length));
113
        $this->tmp_key_info_file = true;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    public function getHlsKeyInfoFile(): string
122
    {
123
        return $this->hls_key_info_file;
124
    }
125
126
    /**
127
     * @param string $hls_base_url
128
     * @return HLS
129
     */
130
    public function setHlsBaseUrl(string $hls_base_url): HLS
131
    {
132
        $this->hls_base_url = $hls_base_url;
133
        return $this;
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public function getHlsBaseUrl(): string
140
    {
141
        return $this->hls_base_url;
142
    }
143
144
    /**
145
     * @param int $hls_list_size
146
     * @return HLS
147
     */
148
    public function setHlsListSize(int $hls_list_size): HLS
149
    {
150
        $this->hls_list_size = $hls_list_size;
151
        return $this;
152
    }
153
154
    /**
155
     * @return int
156
     */
157
    public function getHlsListSize(): int
158
    {
159
        return $this->hls_list_size;
160
    }
161
162
    /**
163
     * @return Filter
164
     */
165
    protected function getFilter(): Filter
166
    {
167
        return new HLSFilter($this);
168
    }
169
170
    /**
171
     * @return string
172
     */
173
    protected function getPath(): string
174
    {
175
        $path = $this->getFilePath();
176
        $reps = $this->getRepresentations();
177
178
        HLSPlaylist::save($path . ".m3u8", $reps);
179
180
        return $path . "_" . end($reps)->getHeight() . "p.m3u8";
181
    }
182
}