Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
21.21% |
7 / 33 |
|
16.67% |
1 / 6 |
CRAP | |
0.00% |
0 / 1 |
WAVHandler | |
21.21% |
7 / 33 |
|
16.67% |
1 / 6 |
141.20 | |
0.00% |
0 / 1 |
getMetadataType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getWebType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
verifyUpload | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
getStreamTypes | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
5.07 | |||
getShortDesc | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getLongDesc | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\TimedMediaHandler\Handlers\WAVHandler; |
4 | |
5 | use File; |
6 | use MediaWiki\Status\Status; |
7 | use MediaWiki\TimedMediaHandler\Handlers\ID3Handler\ID3Handler; |
8 | |
9 | /** |
10 | * WAV handler |
11 | */ |
12 | class WAVHandler extends ID3Handler { |
13 | |
14 | /** |
15 | * @param File $file |
16 | * @return string |
17 | */ |
18 | public function getMetadataType( $file ) { |
19 | return 'wav'; |
20 | } |
21 | |
22 | /** |
23 | * @param File $file |
24 | * @return string |
25 | */ |
26 | public function getWebType( $file ) { |
27 | return 'audio/wav'; |
28 | } |
29 | |
30 | /** @inheritDoc */ |
31 | public function verifyUpload( $fileName ) { |
32 | $metadata = $this->getID3( $fileName ); |
33 | |
34 | if ( |
35 | isset( $metadata['audio'] ) |
36 | && $metadata['audio']['dataformat'] === 'wav' |
37 | && ( $metadata['audio']['codec'] === 'Pulse Code Modulation (PCM)' || |
38 | $metadata['audio']['codec'] === 'IEEE Float' ) |
39 | ) { |
40 | return Status::newGood(); |
41 | } |
42 | |
43 | return Status::newFatal( 'timedmedia-wav-pcm-required' ); |
44 | } |
45 | |
46 | /** |
47 | * @param File $file |
48 | * @return string[]|false |
49 | */ |
50 | public function getStreamTypes( $file ) { |
51 | $streamTypes = []; |
52 | $metadata = $this->unpackMetadata( $file->getMetadata() ); |
53 | |
54 | if ( !$metadata || isset( $metadata['error'] ) ) { |
55 | return false; |
56 | } |
57 | |
58 | if ( isset( $metadata['audio'] ) && $metadata['audio']['dataformat'] === 'wav' ) { |
59 | $streamTypes[] = 'WAV'; |
60 | } |
61 | |
62 | return $streamTypes; |
63 | } |
64 | |
65 | /** |
66 | * @param File $file |
67 | * @return string |
68 | */ |
69 | public function getShortDesc( $file ) { |
70 | global $wgLang; |
71 | |
72 | $streamTypes = $this->getStreamTypes( $file ); |
73 | if ( !$streamTypes ) { |
74 | return parent::getShortDesc( $file ); |
75 | } |
76 | return wfMessage( 'timedmedia-wav-short-audio', |
77 | $wgLang->formatTimePeriod( $this->getLength( $file ) ) )->text(); |
78 | } |
79 | |
80 | /** |
81 | * @param File $file |
82 | * @return string |
83 | */ |
84 | public function getLongDesc( $file ) { |
85 | $streamTypes = $this->getStreamTypes( $file ); |
86 | if ( !$streamTypes ) { |
87 | return parent::getLongDesc( $file ); |
88 | } |
89 | return wfMessage( |
90 | 'timedmedia-wav-long-audio' |
91 | )->timeperiodParams( |
92 | $this->getLength( $file ) |
93 | )->bitrateParams( |
94 | $this->getBitRate( $file ) |
95 | )->sizeParams( |
96 | $file->getSize() |
97 | )->text(); |
98 | } |
99 | |
100 | } |