Skip to content

Commit

Permalink
Merge pull request #147 from pascalbaljetmedia/readStream-nonLocalFiles
Browse files Browse the repository at this point in the history
Copy remote file using 'stream_copy_to_stream'
  • Loading branch information
pascalbaljet authored Aug 27, 2019
2 parents 50ce131 + 9916167 commit a1f7ff2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: php

php:
- 7.1
- 7.2
- 7.3
- '7.1'
- '7.2'
- '7.3'

env:
matrix:
Expand All @@ -17,9 +17,9 @@ before_install:

install:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
- sudo add-apt-repository -y ppa:mc3man/trusty-media
- sudo add-apt-repository -y ppa:mc3man/xerus-media
- sudo apt-get -qq update
- sudo apt-get install -y --allow-unauthenticated software-properties-common ffmpeg

script:
- phpunit
- ./vendor/bin/phpunit
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "7.5"
"phpunit/phpunit": "7.5",
"twistor/flysystem-http": "^0.2.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions src/Disk.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use League\Flysystem\Adapter\Local as LocalAdapater;

/**
* @method \League\Flysystem\FilesystemInterface getDriver()
* @method bool put($path, $contents, $visibility = null)
* @method array|false read($path)
* @method void setVisibility($path, $visibility)
Expand Down
6 changes: 5 additions & 1 deletion src/FFMpeg.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public function open($path): Media
$ffmpegPathFile = $file->getFullPath();
} else {
$ffmpegPathFile = static::newTemporaryFile();
file_put_contents($ffmpegPathFile, $this->disk->read($path));

stream_copy_to_stream(
$this->disk->getDriver()->readStream($path),
fopen($ffmpegPathFile, 'w')
);
}

$ffmpegMedia = $this->ffmpeg->open($ffmpegPathFile);
Expand Down
15 changes: 5 additions & 10 deletions tests/AudioVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Pbmedia\LaravelFFMpeg\File;
use Pbmedia\LaravelFFMpeg\Media;
use Pbmedia\LaravelFFMpeg\MediaExporter;
use Twistor\Flysystem\Http\HttpAdapter;

class AudioVideoTest extends TestCase
{
Expand Down Expand Up @@ -197,16 +198,10 @@ public function testOpeningFromRemoteDisk()
$config = Mockery::mock(ConfigRepository::class);
$logger = new Writer(new Logger('ffmpeg'));

$adapter = Mockery::mock(AdapterInterface::class);
$adapter = new HttpAdapter("https://raw.githubusercontent.com/pascalbaljetmedia/laravel-ffmpeg/master/tests/src/");
$driver = new \League\Flysystem\Filesystem($adapter);

$driver = Mockery::mock(FilesystemInterface::class);
$driver->shouldReceive('getAdapter')->andReturn($adapter);

$remoteDisk = Mockery::mock(FilesystemAdapter::class);
$remoteDisk->shouldReceive('getDriver')->andReturn($driver);
$remoteDisk->shouldReceive('read')->with('remote_guitar.m4a')->andReturn(
$videoContents = file_get_contents(__DIR__ . '/src/guitar.m4a')
);
$remoteDisk = new FilesystemAdapter($driver);

$localDisk = $this->getLocalAdapter();

Expand All @@ -217,7 +212,7 @@ public function testOpeningFromRemoteDisk()
$config->shouldReceive('get')->once()->with('filesystems.default')->andReturn('s3');

$service = new FFMpeg($filesystems, $config, $logger);
$media = $service->open('remote_guitar.m4a');
$media = $service->open('guitar.m4a');

$format = new \FFMpeg\Format\Audio\Aac;

Expand Down

0 comments on commit a1f7ff2

Please sign in to comment.