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 ExtinfTag extends AbstractSegmentTag |
15
|
|
|
{ |
16
|
|
|
private $duration; |
17
|
|
|
private $title; |
18
|
|
|
private $m3u8Version; |
19
|
|
|
|
20
|
|
|
const TAG_IDENTIFIER = '#EXTINF'; |
21
|
|
|
|
22
|
2 |
|
public function __construct($m3u8Version = 3) |
23
|
|
|
{ |
24
|
2 |
|
$this->m3u8Version = $m3u8Version; |
25
|
2 |
|
} |
26
|
|
|
|
27
|
1 |
|
public function setDuration($duration) |
28
|
|
|
{ |
29
|
1 |
|
$this->duration = $duration; |
30
|
|
|
|
31
|
1 |
|
return $this; |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
|
public function getDuration() |
35
|
|
|
{ |
36
|
1 |
|
return $this->duration; |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
public function setTitle($title) |
40
|
|
|
{ |
41
|
1 |
|
$this->title = $title; |
42
|
|
|
|
43
|
1 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
public function getTitle() |
47
|
|
|
{ |
48
|
1 |
|
return $this->title; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public function dump() |
52
|
|
|
{ |
53
|
1 |
|
if (null === $this->duration) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
if (3 > $this->m3u8Version) { |
58
|
|
|
return sprintf('%s:%d,%s', self::TAG_IDENTIFIER, round($this->duration), $this->title); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
return sprintf('%s:%.3f,%s', self::TAG_IDENTIFIER, round($this->duration, 3), $this->title); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
protected function read($line) |
65
|
|
|
{ |
66
|
1 |
|
preg_match('/^#EXTINF:(.+),(.*)$/', $line, $matches); |
67
|
1 |
|
$this->duration = $matches[1]; |
68
|
|
|
|
69
|
1 |
|
if (isset($matches[2])) { |
70
|
1 |
|
$this->title = $matches[2]; |
71
|
1 |
|
} |
72
|
1 |
|
} |
73
|
|
|
} |
74
|
|
|
|