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