1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class ID3Data |
4
|
|
|
* |
5
|
|
|
* @created 07.03.2020 |
6
|
|
|
* @author smiley <[email protected]> |
7
|
|
|
* @copyright 2020 smiley |
8
|
|
|
* @license MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace chillerlan\ID3Tag; |
12
|
|
|
|
13
|
|
|
use finfo; |
14
|
|
|
use function array_column, filesize, in_array, is_array, property_exists; |
15
|
|
|
use const FILEINFO_MIME_ENCODING, FILEINFO_MIME_TYPE; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @property string $filename |
19
|
|
|
* @property int $filesize |
20
|
|
|
* @property int $v1tagsize |
21
|
|
|
* @property int $v2tagsize |
22
|
|
|
* @property string $mimeType |
23
|
|
|
* @property string $mimeEncoding |
24
|
|
|
* @property string $finfo |
25
|
|
|
* @property int|null $framecount |
26
|
|
|
* @property float $duration |
27
|
|
|
* @property int $bitrate |
28
|
|
|
* @property array|null $id3v1 |
29
|
|
|
* @property array|null $id3v2 |
30
|
|
|
* @property array|null $id3v1TagIndex |
31
|
|
|
* @property array|null $id3v2TagIndex |
32
|
|
|
*/ |
33
|
|
|
final class ID3Data{ |
34
|
|
|
|
35
|
|
|
private string $filename; |
36
|
|
|
private int $filesize; |
37
|
|
|
private int $v1tagsize = 0; |
38
|
|
|
private int $v2tagsize = 0; |
39
|
|
|
private string $mimeType; |
40
|
|
|
private string $mimeEncoding; |
41
|
|
|
private string $finfo; |
42
|
|
|
private ?int $framecount = null; |
43
|
|
|
private int $duration = 0; |
44
|
|
|
private int $bitrate; |
45
|
|
|
private ?array $id3v1 = null; |
46
|
|
|
private ?array $id3v2 = null; |
47
|
|
|
private ?array $id3v1TagIndex = null; |
48
|
|
|
private ?array $id3v2TagIndex = null; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* ID3Data constructor. |
52
|
|
|
*/ |
53
|
|
|
public function __construct(string $file){ |
54
|
|
|
$this->filename = $file; |
55
|
|
|
$this->filesize = filesize($file); |
56
|
|
|
$this->mimeType = (new finfo(FILEINFO_MIME_TYPE))->file($file); |
57
|
|
|
$this->mimeEncoding = (new finfo(FILEINFO_MIME_ENCODING))->file($file); |
58
|
|
|
$this->finfo = (new finfo)->file($file); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $property |
63
|
|
|
* |
64
|
|
|
* @return mixed |
65
|
|
|
*/ |
66
|
|
|
public function __get(string $property){ |
67
|
|
|
|
68
|
|
|
if(property_exists($this, $property)){ |
69
|
|
|
return $this->{$property}; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* |
77
|
|
|
*/ |
78
|
|
|
public function setProperties(iterable $properties):ID3Data{ |
79
|
|
|
|
80
|
|
|
foreach($properties as $property => $value){ |
81
|
|
|
|
82
|
|
|
if(!property_exists($this, $property)){ |
83
|
|
|
continue; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$this->{$property} = $value; |
87
|
|
|
|
88
|
|
|
if(in_array($property, ['id3v1', 'id3v2']) && is_array($value)){ |
89
|
|
|
$this->{$property.'TagIndex'} = array_column($value, 'tag'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|