55 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66 * SPDX-License-Identifier: AGPL-3.0-only
77 */
8+
89namespace OC \Preview ;
910
1011use OCP \Files \File ;
1112use OCP \Files \FileInfo ;
1213use OCP \IConfig ;
1314use OCP \IImage ;
15+ use OCP \ITempManager ;
1416use OCP \Server ;
1517use Psr \Log \LoggerInterface ;
1618
1719class Movie extends ProviderV2 {
1820 private IConfig $ config ;
1921
20- /**
21- * @deprecated 23.0.0 pass option to \OCP\Preview\ProviderV2
22- * @var string
23- */
24- public static $ avconvBinary ;
25-
26- /**
27- * @deprecated 23.0.0 pass option to \OCP\Preview\ProviderV2
28- * @var string
29- */
30- public static $ ffmpegBinary ;
31-
32- /** @var string */
33- private $ binary ;
22+ private ?string $ binary = null ;
3423
35- public function __construct (array $ config ) {
36- parent ::__construct ($ config );
24+ public function __construct (array $ options = [] ) {
25+ parent ::__construct ($ options );
3726 $ this ->config = Server::get (IConfig::class);
3827 }
3928
@@ -45,14 +34,9 @@ public function getMimeType(): string {
4534 * {@inheritDoc}
4635 */
4736 public function isAvailable (FileInfo $ file ): bool {
48- // TODO: remove when avconv is dropped
4937 if (is_null ($ this ->binary )) {
5038 if (isset ($ this ->options ['movieBinary ' ])) {
5139 $ this ->binary = $ this ->options ['movieBinary ' ];
52- } elseif (is_string (self ::$ avconvBinary )) {
53- $ this ->binary = self ::$ avconvBinary ;
54- } elseif (is_string (self ::$ ffmpegBinary )) {
55- $ this ->binary = self ::$ ffmpegBinary ;
5640 }
5741 }
5842 return is_string ($ this ->binary );
@@ -89,14 +73,11 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
8973 return null ;
9074 }
9175
92- $ result = null ;
93- if (is_string ( $ absPath ) ) {
94- $ result = $ this ->generateThumbNail ($ maxX , $ maxY , $ absPath , 5 );
76+ $ result = $ this -> generateThumbNail ( $ maxX , $ maxY , $ absPath , 5 ) ;
77+ if ($ result === null ) {
78+ $ result = $ this ->generateThumbNail ($ maxX , $ maxY , $ absPath , 1 );
9579 if ($ result === null ) {
96- $ result = $ this ->generateThumbNail ($ maxX , $ maxY , $ absPath , 1 );
97- if ($ result === null ) {
98- $ result = $ this ->generateThumbNail ($ maxX , $ maxY , $ absPath , 0 );
99- }
80+ $ result = $ this ->generateThumbNail ($ maxX , $ maxY , $ absPath , 0 );
10081 }
10182 }
10283
@@ -137,7 +118,15 @@ private function useHdr(string $absPath): bool {
137118 }
138119
139120 private function generateThumbNail (int $ maxX , int $ maxY , string $ absPath , int $ second ): ?IImage {
140- $ tmpPath = \OC ::$ server ->getTempManager ()->getTemporaryFile ();
121+ $ tmpPath = Server::get (ITempManager::class)->getTemporaryFile ();
122+
123+ if ($ tmpPath === false ) {
124+ Server::get (LoggerInterface::class)->error (
125+ 'Failed to get local file to generate thumbnail for: ' . $ absPath ,
126+ ['app ' => 'core ' ]
127+ );
128+ return null ;
129+ }
141130
142131 $ binaryType = substr (strrchr ($ this ->binary , '/ ' ), 1 );
143132
@@ -190,7 +179,7 @@ private function generateThumbNail(int $maxX, int $maxY, string $absPath, int $s
190179 }
191180
192181 if ($ second === 0 ) {
193- $ logger = \ OC :: $ server -> get (LoggerInterface::class);
182+ $ logger = Server:: get (LoggerInterface::class);
194183 $ logger ->info ('Movie preview generation failed Output: {output} ' , ['app ' => 'core ' , 'output ' => $ output ]);
195184 }
196185
0 commit comments