Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
26.92% |
7 / 26 |
|
20.00% |
1 / 5 |
CRAP | |
0.00% |
0 / 1 |
FLACHandler | |
26.92% |
7 / 26 |
|
20.00% |
1 / 5 |
58.22 | |
0.00% |
0 / 1 |
getMetadataType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getWebType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
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\FLACHandler; |
4 | |
5 | use File; |
6 | use MediaWiki\TimedMediaHandler\Handlers\ID3Handler\ID3Handler; |
7 | |
8 | /** |
9 | * FLAC handler |
10 | */ |
11 | class FLACHandler extends ID3Handler { |
12 | |
13 | /** |
14 | * @param File $file |
15 | * @return string |
16 | */ |
17 | public function getMetadataType( $file ) { |
18 | return 'flac'; |
19 | } |
20 | |
21 | /** |
22 | * @param File $file |
23 | * @return string |
24 | */ |
25 | public function getWebType( $file ) { |
26 | return 'audio/flac'; |
27 | } |
28 | |
29 | /** |
30 | * @param File $file |
31 | * @return string[]|false |
32 | */ |
33 | public function getStreamTypes( $file ) { |
34 | $streamTypes = []; |
35 | $metadata = $this->unpackMetadata( $file->getMetadata() ); |
36 | |
37 | if ( !$metadata || isset( $metadata['error'] ) ) { |
38 | return false; |
39 | } |
40 | |
41 | if ( isset( $metadata['audio'] ) && $metadata['audio']['dataformat'] === 'flac' ) { |
42 | $streamTypes[] = 'FLAC'; |
43 | } |
44 | |
45 | return $streamTypes; |
46 | } |
47 | |
48 | /** |
49 | * @param File $file |
50 | * @return string |
51 | */ |
52 | public function getShortDesc( $file ) { |
53 | global $wgLang; |
54 | |
55 | $streamTypes = $this->getStreamTypes( $file ); |
56 | if ( !$streamTypes ) { |
57 | return parent::getShortDesc( $file ); |
58 | } |
59 | return wfMessage( 'timedmedia-flac-short-audio', |
60 | $wgLang->formatTimePeriod( $this->getLength( $file ) ) )->text(); |
61 | } |
62 | |
63 | /** |
64 | * @param File $file |
65 | * @return string |
66 | */ |
67 | public function getLongDesc( $file ) { |
68 | $streamTypes = $this->getStreamTypes( $file ); |
69 | if ( !$streamTypes ) { |
70 | return parent::getLongDesc( $file ); |
71 | } |
72 | return wfMessage( |
73 | 'timedmedia-flac-long-audio' |
74 | )->timeperiodParams( |
75 | $this->getLength( $file ) |
76 | )->bitrateParams( |
77 | $this->getBitRate( $file ) |
78 | )->sizeParams( |
79 | $file->getSize() |
80 | )->text(); |
81 | } |
82 | |
83 | } |