Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 53 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
MPEGHandler | |
0.00% |
0 / 53 |
|
0.00% |
0 / 6 |
342 | |
0.00% |
0 / 1 |
getMetadataType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getWebType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getStreamTypes | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
42 | |||
getImageSize | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 | |||
getShortDesc | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
getLongDesc | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\TimedMediaHandler\Handlers\MPEGHandler; |
4 | |
5 | use File; |
6 | use MediaWiki\TimedMediaHandler\Handlers\ID3Handler\ID3Handler; |
7 | |
8 | /** |
9 | * MPEG 1/2 video handler |
10 | */ |
11 | class MPEGHandler extends ID3Handler { |
12 | |
13 | /** |
14 | * @param File $image |
15 | * @return string |
16 | */ |
17 | public function getMetadataType( $image ) { |
18 | return 'mpeg'; |
19 | } |
20 | |
21 | /** |
22 | * @param File $file |
23 | * @return string |
24 | */ |
25 | public function getWebType( $file ) { |
26 | return 'video/mpeg'; |
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 | if ( !$metadata || isset( $metadata['error'] ) ) { |
37 | return false; |
38 | } |
39 | if ( isset( $metadata['audio']['dataformat'] ) ) { |
40 | if ( $metadata['audio']['dataformat'] === 'mp2' ) { |
41 | $streamTypes[] = 'MPEG-2'; |
42 | } else { |
43 | $streamTypes[] = $metadata['audio']['dataformat']; |
44 | } |
45 | } |
46 | if ( isset( $metadata['video']['codec'] ) ) { |
47 | $streamTypes[] = $metadata['video']['codec']; |
48 | } |
49 | |
50 | return $streamTypes; |
51 | } |
52 | |
53 | /** |
54 | * Get the "media size" |
55 | * @param File $file |
56 | * @param string $path |
57 | * @param string|false $metadata |
58 | * @return array|false |
59 | */ |
60 | public function getImageSize( $file, $path, $metadata = false ) { |
61 | // Just return the size of the first video stream |
62 | if ( $metadata === false ) { |
63 | $metadata = $file->getMetadata(); |
64 | } |
65 | $metadata = $this->unpackMetadata( $metadata ); |
66 | if ( isset( $metadata['error'] ) ) { |
67 | return false; |
68 | } |
69 | if ( |
70 | isset( $metadata['video']['resolution_x'] ) && |
71 | isset( $metadata['video']['resolution_y'] ) && |
72 | isset( $metadata['video']['pixel_aspect_ratio'] ) |
73 | ) { |
74 | $width = $metadata['video']['resolution_x']; |
75 | $height = $metadata['video']['resolution_y']; |
76 | $aspect = $metadata['video']['pixel_aspect_ratio']; |
77 | $width = (int)( $width * $aspect ); |
78 | return [ |
79 | $width, |
80 | $height |
81 | ]; |
82 | } |
83 | return [ false, false ]; |
84 | } |
85 | |
86 | /** |
87 | * @param File $file |
88 | * @return string |
89 | */ |
90 | public function getShortDesc( $file ) { |
91 | $streamTypes = $this->getStreamTypes( $file ); |
92 | if ( !$streamTypes ) { |
93 | return parent::getShortDesc( $file ); |
94 | } |
95 | return wfMessage( 'timedmedia-mpeg-short-video', implode( '/', $streamTypes ) |
96 | )->timeperiodParams( |
97 | $this->getLength( $file ) |
98 | )->text(); |
99 | } |
100 | |
101 | /** |
102 | * @param File $file |
103 | * @return string |
104 | */ |
105 | public function getLongDesc( $file ) { |
106 | $streamTypes = $this->getStreamTypes( $file ); |
107 | if ( !$streamTypes ) { |
108 | return parent::getLongDesc( $file ); |
109 | } |
110 | return wfMessage( |
111 | 'timedmedia-mpeg-long-video', |
112 | implode( '/', $streamTypes ) |
113 | )->timeperiodParams( |
114 | $this->getLength( $file ) |
115 | )->bitrateParams( |
116 | $this->getBitRate( $file ) |
117 | )->numParams( |
118 | $file->getWidth(), |
119 | $file->getHeight() |
120 | )->sizeParams( |
121 | $file->getSize() |
122 | )->text(); |
123 | } |
124 | |
125 | } |