Browse Source
feat(previews): previews and tests for large remote videos w/o full download
feat(previews): previews and tests for large remote videos w/o full download
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com> Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: invario <67800603+invario@users.noreply.github.com>pull/53952/head
committed by
Louis
4 changed files with 200 additions and 17 deletions
-
2REUSE.toml
-
148lib/private/Preview/Movie.php
-
BINtests/data/testvideo-remote-file.mp4
-
67tests/lib/Preview/MovieTestRemoteFile.php
@ -0,0 +1,67 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* SPDX-FileCopyrightText: 2019-2025 Nextcloud GmbH and Nextcloud contributors |
|||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc. |
|||
* SPDX-License-Identifier: AGPL-3.0-only |
|||
*/ |
|||
|
|||
namespace Test\Preview; |
|||
|
|||
use OC\Files\Node\File; |
|||
use OC\Files\Storage\Storage; |
|||
use OC\Preview\Movie; |
|||
use OCP\Files\IRootFolder; |
|||
use OCP\IBinaryFinder; |
|||
use OCP\Server; |
|||
|
|||
/** |
|||
* Class MovieTestRemoteFile |
|||
* |
|||
* @group DB |
|||
* |
|||
* @package Test\Preview |
|||
*/ |
|||
class MovieTestRemoteFile extends Provider { |
|||
// 1080p (1920x1080) 30 FPS HEVC/H264, 10 secs, avg. bitrate: ~10 Mbps
|
|||
protected string $fileName = 'testvideo-remote-file.mp4'; |
|||
protected int $width = 1920; |
|||
protected int $height = 1080; |
|||
|
|||
protected function setUp(): void { |
|||
$binaryFinder = Server::get(IBinaryFinder::class); |
|||
$movieBinary = $binaryFinder->findBinaryPath('ffmpeg'); |
|||
if (is_string($movieBinary)) { |
|||
parent::setUp(); |
|||
$this->imgPath = $this->prepareTestFile($this->fileName, \OC::$SERVERROOT . '/tests/data/' . $this->fileName); |
|||
$this->provider = new Movie(['movieBinary' => $movieBinary]); |
|||
} else { |
|||
$this->markTestSkipped('No Movie provider present'); |
|||
} |
|||
} |
|||
|
|||
#[\PHPUnit\Framework\Attributes\DataProvider('dimensionsDataProvider')]
|
|||
public function testGetThumbnail($widthAdjustment, $heightAdjustment): void { |
|||
$ratio = round($this->width / $this->height, 2); |
|||
$this->maxWidth = $this->width - $widthAdjustment; |
|||
$this->maxHeight = $this->height - $heightAdjustment; |
|||
$file = new File(Server::get(IRootFolder::class), $this->rootView, $this->imgPath); |
|||
// Create mock remote file to be passed
|
|||
$remoteStorage = $this->createMock(Storage::class); |
|||
$remoteStorage->method('isLocal') |
|||
->willReturn(false); |
|||
$mockRemoteVideo = $this->createMock(File::class); |
|||
$mockRemoteVideo->method('getStorage') |
|||
->willReturn($remoteStorage); |
|||
$mockRemoteVideo->method('getSize') |
|||
->willReturn($file->getSize()); |
|||
$mockRemoteVideo->method('fopen') |
|||
->with('r') |
|||
->willreturn($file->fopen('r')); |
|||
$remotePreview = $this->provider->getThumbnail($mockRemoteVideo, $this->maxWidth, $this->maxHeight, $this->scalingUp); |
|||
$localPreview = $this->provider->getThumbnail($file, $this->maxWidth, $this->maxHeight, $this->scalingUp); |
|||
$this->assertNotFalse($remotePreview); |
|||
$this->assertTrue($remotePreview->valid()); |
|||
$this->assertEquals($remotePreview->data(), $localPreview->data()); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue