|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the PhpM3u8 package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Chrisyue <http://chrisyue.com/> |
|
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 Chrisyue\PhpM3u8\Tag; |
|
13
|
|
|
|
|
14
|
|
|
class StreamTag extends AbstractTag |
|
15
|
|
|
{ |
|
16
|
|
|
use SingleValueTagTrait; |
|
17
|
|
|
|
|
18
|
|
|
const TAG_IDENTIFIER = '#EXT-X-STREAM-INF'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $programId; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $bandwidth; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $resolution; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
private $codecs; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param string |
|
42
|
|
|
* |
|
43
|
|
|
* @return self |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setProgramId($programId) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->programId = $programId; |
|
48
|
|
|
|
|
49
|
|
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function getProgramId() |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->programId; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param string |
|
62
|
|
|
* |
|
63
|
|
|
* @return self |
|
64
|
|
|
*/ |
|
65
|
|
|
public function setBandwidth($bandwidth) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->bandwidth = $bandwidth; |
|
68
|
|
|
|
|
69
|
|
|
return $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getBandwidth() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->bandwidth; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param string |
|
82
|
|
|
* |
|
83
|
|
|
* @return self |
|
84
|
|
|
*/ |
|
85
|
|
|
public function setResolution($resolution) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->resolution = $resolution; |
|
88
|
|
|
|
|
89
|
|
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getResolution() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->resolution; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param string |
|
102
|
|
|
* |
|
103
|
|
|
* @return self |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setCodecs($codecs) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->codecs = $codecs; |
|
108
|
|
|
|
|
109
|
|
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return string |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getCodecs() |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->codecs; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function dump() |
|
121
|
|
|
{ |
|
122
|
|
|
$attrs = []; |
|
123
|
|
|
foreach (get_object_vars($this) as $prop => $value) { |
|
124
|
|
|
if (empty($value)) { |
|
125
|
|
|
continue; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
if ('codecs' === $prop) { |
|
129
|
|
|
$attrs[] = sprintf('%s="%s"', strtoupper($prop), $value); |
|
130
|
|
|
continue; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
if ('programId' === $prop) { |
|
134
|
|
|
$attrs[] = sprintf('%s=%s', 'PROGRAM-ID', $value); |
|
135
|
|
|
continue; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
$attrs[] = sprintf('%s=%s', strtoupper($prop), $value); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
if (empty($attrs)) { |
|
142
|
|
|
return; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
return sprintf('%s:%s', self::TAG_IDENTIFIER, implode(',', $attrs)); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
protected function read($line) |
|
149
|
|
|
{ |
|
150
|
|
|
$attrs = preg_split("/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/", self::extractValue($line)); |
|
151
|
|
|
$attributes = []; |
|
152
|
|
View Code Duplication |
foreach ($attrs as $attr) { |
|
|
|
|
|
|
153
|
|
|
list($key, $value) = explode('=', $attr); |
|
154
|
|
|
$attributes[$key] = trim($value); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
foreach (get_object_vars($this) as $prop => $value) { |
|
158
|
|
|
$key = strtoupper($prop); |
|
159
|
|
|
if (isset($attributes[$key])) { |
|
160
|
|
|
if ('codecs' === $prop) { |
|
161
|
|
|
$this->$prop = trim($attributes[$key], '",'); |
|
162
|
|
|
continue; |
|
163
|
|
|
} |
|
164
|
|
|
$this->$prop = trim($attributes[$key], ','); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
if (isset($attributes['PROGRAM-ID'])) { |
|
168
|
|
|
$this->programId = trim($attributes['PROGRAM-ID'], ','); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.