Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
ID3Handler | |
0.00% |
0 / 33 |
|
0.00% |
0 / 10 |
156 | |
0.00% |
0 / 1 |
getID3 | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 | |||
getMetadata | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
unpackMetadata | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
getBitrate | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getLength | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getFramerate | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
isInterlaced | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
hasVideo | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
hasAudio | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getAudioChannels | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\TimedMediaHandler\Handlers\ID3Handler; |
4 | |
5 | use File; |
6 | use getID3; |
7 | use MediaWiki\TimedMediaHandler\TimedMediaHandler; |
8 | |
9 | /** |
10 | * getID3 Metadata handler |
11 | */ |
12 | class ID3Handler extends TimedMediaHandler { |
13 | // XXX match GETID3_VERSION ( too bad version is not a getter ) |
14 | private const METADATA_VERSION = 2; |
15 | |
16 | /** |
17 | * @param string $path |
18 | * @return array |
19 | */ |
20 | protected function getID3( $path ) { |
21 | // Create new id3 object: |
22 | $getID3 = new getID3(); |
23 | |
24 | // Don't grab stuff we don't use: |
25 | // Read and process ID3v1 tags |
26 | $getID3->option_tag_id3v1 = false; |
27 | // Read and process ID3v2 tags |
28 | $getID3->option_tag_id3v2 = false; |
29 | // Read and process Lyrics3 tags |
30 | $getID3->option_tag_lyrics3 = false; |
31 | // Read and process APE tags |
32 | $getID3->option_tag_apetag = false; |
33 | // Copy tags to root key 'tags' and encode to $this->encoding |
34 | $getID3->option_tags_process = false; |
35 | // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities |
36 | $getID3->option_tags_html = false; |
37 | |
38 | // Analyze file to get metadata structure: |
39 | $id3 = $getID3->analyze( $path ); |
40 | |
41 | // remove file paths |
42 | unset( $id3['filename'] ); |
43 | unset( $id3['filepath'] ); |
44 | unset( $id3['filenamepath'] ); |
45 | |
46 | // Update the version |
47 | $id3['version'] = self::METADATA_VERSION; |
48 | |
49 | return $id3; |
50 | } |
51 | |
52 | /** |
53 | * @param File $file |
54 | * @param string $path |
55 | * @return string |
56 | */ |
57 | public function getMetadata( $file, $path ) { |
58 | $id3 = $this->getID3( $path ); |
59 | return serialize( $id3 ); |
60 | } |
61 | |
62 | /** |
63 | * @param string $metadata |
64 | * @return false|mixed |
65 | * @deprecated 1.41 use File::getMetadataArray |
66 | */ |
67 | public function unpackMetadata( $metadata ) { |
68 | // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged |
69 | $unser = @unserialize( $metadata ); |
70 | if ( isset( $unser['version'] ) && $unser['version'] === self::METADATA_VERSION ) { |
71 | return $unser; |
72 | } |
73 | return false; |
74 | } |
75 | |
76 | /** |
77 | * @param File $file |
78 | * @return int |
79 | */ |
80 | public function getBitrate( $file ) { |
81 | $metadata = $file->getMetadataArray(); |
82 | return (int)( $metadata['bitrate'] ?? 0 ); |
83 | } |
84 | |
85 | /** |
86 | * @param File $file |
87 | * @return float |
88 | */ |
89 | public function getLength( $file ) { |
90 | $metadata = $file->getMetadataArray(); |
91 | return (float)( $metadata['playtime_seconds'] ?? 0.0 ); |
92 | } |
93 | |
94 | /** |
95 | * @param File $file |
96 | * @return float framerate as floating point; 0 indicates no valid rate data |
97 | */ |
98 | public function getFramerate( $file ) { |
99 | $metadata = $file->getMetadataArray(); |
100 | return (float)( $metadata['video']['frame_rate'] ?? 0.0 ); |
101 | } |
102 | |
103 | /** |
104 | * Returns true if the file contains an interlaced video track. |
105 | * @param File $file |
106 | * @return bool |
107 | */ |
108 | public function isInterlaced( $file ) { |
109 | $metadata = $file->getMetadataArray(); |
110 | return (bool)( $metadata['video']['interlaced'] ?? false ); |
111 | } |
112 | |
113 | /** |
114 | * @param File $file |
115 | * @return bool |
116 | */ |
117 | public function hasVideo( $file ) { |
118 | $metadata = $file->getMetadataArray(); |
119 | return ( $metadata['video'] ?? null ) !== null; |
120 | } |
121 | |
122 | /** |
123 | * @param File $file |
124 | * @return bool |
125 | */ |
126 | public function hasAudio( $file ) { |
127 | $metadata = $file->getMetadataArray(); |
128 | return ( $metadata['audio'] ?? null ) !== null; |
129 | } |
130 | |
131 | /** |
132 | * @param File $file |
133 | * @return int |
134 | */ |
135 | public function getAudioChannels( $file ) { |
136 | $metadata = $file->getMetadataArray(); |
137 | return (int)( $metadata['audio']['channels'] ?? 0 ); |
138 | } |
139 | |
140 | } |