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; |
13
|
|
|
|
14
|
|
|
class M3u8 extends AbstractContainer |
15
|
|
|
{ |
16
|
|
|
private $m3uTag; |
17
|
|
|
|
18
|
|
|
private $versionTag; |
19
|
|
|
|
20
|
|
|
private $playlistTypeTag; |
21
|
|
|
|
22
|
|
|
private $targetDurationTag; |
23
|
|
|
|
24
|
|
|
private $mediaSequenceTag; |
25
|
|
|
|
26
|
|
|
private $discontinuitySequenceTag; |
27
|
|
|
|
28
|
|
|
private $segments; |
29
|
|
|
|
30
|
|
|
private $endlistTag; |
31
|
|
|
|
32
|
2 |
|
public function __construct() |
33
|
|
|
{ |
34
|
2 |
|
$this->m3uTag = new Tag\M3uTag(); |
35
|
2 |
|
$this->versionTag = new Tag\VersionTag(); |
36
|
2 |
|
$this->playlistTypeTag = new Tag\PlaylistTypeTag(); |
37
|
2 |
|
$this->targetDurationTag = new Tag\TargetDurationTag(); |
38
|
2 |
|
$this->mediaSequenceTag = new Tag\MediaSequenceTag(); |
39
|
2 |
|
$this->discontinuitySequenceTag = new Tag\DiscontinuitySequenceTag(); |
40
|
2 |
|
$this->segments = new Segments($this); |
41
|
2 |
|
$this->endlistTag = new Tag\EndlistTag(); |
42
|
2 |
|
} |
43
|
|
|
|
44
|
1 |
|
public function read($string) |
45
|
|
|
{ |
46
|
1 |
|
$lines = self::split($string); |
47
|
|
|
|
48
|
1 |
|
$this->readLines($lines); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
1 |
|
public function getVersionTag() |
52
|
|
|
{ |
53
|
1 |
|
return $this->versionTag; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
public function getVersion() |
57
|
|
|
{ |
58
|
1 |
|
return $this->versionTag->getVersion(); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
public function getPlaylistTypeTag() |
62
|
|
|
{ |
63
|
1 |
|
return $this->playlistTypeTag; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getPlaylistType() |
67
|
|
|
{ |
68
|
|
|
return $this->playlistTypeTag->getPlaylistType(); |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
public function getTargetDurationTag() |
72
|
|
|
{ |
73
|
1 |
|
return $this->targetDurationTag; |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public function getTargetDuration() |
77
|
|
|
{ |
78
|
1 |
|
return $this->targetDurationTag->getTargetDuration(); |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
public function getMediaSequenceTag() |
82
|
|
|
{ |
83
|
1 |
|
return $this->mediaSequenceTag; |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
public function getMediaSequence() |
87
|
|
|
{ |
88
|
1 |
|
return $this->mediaSequenceTag->getMediaSequence(); |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
public function getDiscontinuitySequenceTag() |
92
|
|
|
{ |
93
|
1 |
|
return $this->discontinuitySequenceTag; |
94
|
|
|
} |
95
|
|
|
|
96
|
1 |
|
public function getDiscontinuitySequence() |
97
|
|
|
{ |
98
|
1 |
|
return $this->discontinuitySequenceTag->getDiscontinuitySequence(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return Chrisyue\PhpM3u8\Segments |
103
|
|
|
*/ |
104
|
2 |
|
public function getSegments() |
105
|
|
|
{ |
106
|
2 |
|
return $this->segments; |
107
|
|
|
} |
108
|
|
|
|
109
|
1 |
|
public function getEndlistTag() |
110
|
|
|
{ |
111
|
1 |
|
return $this->endlistTag; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function isEndless() |
115
|
|
|
{ |
116
|
|
|
return $this->endlistTag->isEndless(); |
117
|
|
|
} |
118
|
|
|
|
119
|
1 |
|
public function getDuration() |
120
|
|
|
{ |
121
|
1 |
|
return $this->segments->getDuration(); |
122
|
|
|
} |
123
|
|
|
|
124
|
2 |
|
protected function getComponents() |
125
|
|
|
{ |
126
|
|
|
return [ |
127
|
2 |
|
$this->m3uTag, |
128
|
2 |
|
$this->versionTag, |
129
|
2 |
|
$this->targetDurationTag, |
130
|
2 |
|
$this->mediaSequenceTag, |
131
|
2 |
|
$this->discontinuitySequenceTag, |
132
|
2 |
|
$this->playlistTypeTag, |
133
|
2 |
|
$this->segments, |
134
|
2 |
|
$this->endlistTag, |
135
|
2 |
|
]; |
136
|
|
|
} |
137
|
|
|
|
138
|
1 |
|
private static function split($string) |
139
|
|
|
{ |
140
|
1 |
|
$lines = explode("\n", $string); |
141
|
1 |
|
$lines = array_map('trim', $lines); |
142
|
|
|
|
143
|
1 |
|
return array_filter($lines); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|