-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jobtech-dev/develop
First release
- Loading branch information
Showing
17 changed files
with
258 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
filter: | ||
excluded_paths: [tests/*] | ||
checks: | ||
php: | ||
code_rating: true | ||
remove_extra_empty_lines: true | ||
remove_php_closing_tag: true | ||
remove_trailing_whitespace: true | ||
fix_use_statements: | ||
remove_unused: true | ||
preserve_multiple: false | ||
preserve_blanklines: true | ||
order_alphabetically: true | ||
fix_php_opening_tag: true | ||
fix_linefeed: true | ||
fix_line_ending: true | ||
fix_identation_4spaces: true | ||
fix_doc_comments: true | ||
tools: | ||
external_code_coverage: false | ||
php_analyzer: true | ||
php_code_coverage: false | ||
php_code_sniffer: | ||
config: | ||
standard: PSR2 | ||
filter: | ||
paths: ['src'] | ||
php_loc: | ||
enabled: true | ||
excluded_dirs: [vendor, tests] | ||
php_cpd: | ||
enabled: true | ||
excluded_dirs: [vendor, tests] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Jobtech\LaravelChunky\Strategies; | ||
|
||
use FFMpeg\Format\Audio\Aac; | ||
use FFMpeg\Format\Audio\Flac; | ||
use FFMpeg\Format\Audio\Mp3; | ||
use FFMpeg\Format\Audio\Vorbis; | ||
use FFMpeg\Format\Audio\Wav; | ||
use Illuminate\Support\Arr; | ||
use Jobtech\LaravelChunky\Strategies\Concerns\ChecksIntegrity; | ||
use Jobtech\LaravelChunky\Strategies\Concerns\HandlesFFMpeg; | ||
use ProtoneMedia\LaravelFFMpeg\FFMpeg\CopyFormat; | ||
|
||
class AudioStrategy extends MergeStrategy | ||
{ | ||
use ChecksIntegrity, | ||
HandlesFFMpeg; | ||
|
||
public function merge() | ||
{ | ||
$this->mergeWithFFMpeg(); | ||
|
||
$this->deleteChunks($this->folder); | ||
|
||
return $this->mergeContents(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function guessFormat() | ||
{ | ||
$extension = strtolower(Arr::last(explode('.', $this->destination()))); | ||
|
||
switch ($extension) { | ||
case 'aac': | ||
return new Aac; | ||
case 'flac': | ||
return new Flac; | ||
case 'mp3': | ||
return new Mp3; | ||
case 'oog': | ||
return new Vorbis; | ||
case 'wav': | ||
return new Wav; | ||
default: | ||
return new CopyFormat; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Jobtech\LaravelChunky\Strategies\Concerns; | ||
|
||
use Illuminate\Support\Arr; | ||
use ProtoneMedia\LaravelFFMpeg\Support\FFMpeg; | ||
|
||
trait HandlesFFMpeg | ||
{ | ||
public function mergeWithFFMpeg(): void | ||
{ | ||
$exporter = FFMpeg::fromDisk($this->manager->chunksFilesystem()) | ||
->open($this->mapChunksToArray()) | ||
->export() | ||
->inFormat($this->guessFormat()) | ||
->concatWithoutTranscoding(); | ||
|
||
if (! empty($visibility = $this->visibility())) { | ||
$exporter->withVisibility($visibility); | ||
} | ||
|
||
$exporter->toDisk( | ||
$this->manager->getMergeDisk() | ||
)->save($this->destination); | ||
} | ||
|
||
/** | ||
* Retrieve visibility option. | ||
* | ||
* @return string|null | ||
*/ | ||
public function visibility(): ?string | ||
{ | ||
return Arr::get( | ||
$this->manager->getMergeOptions(), | ||
'visibility' | ||
); | ||
} | ||
|
||
/** | ||
* Guess format from destination file extension. | ||
* | ||
* @return mixed | ||
*/ | ||
abstract public function guessFormat(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/Unit/Merge/MergeHandlerTest.php → tests/Unit/Handlers/MergeHandlerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace Jobtech\LaravelChunky\Tests\Unit\Strategies; | ||
|
||
use Illuminate\Support\Facades\Storage; | ||
use Jobtech\LaravelChunky\ChunksManager; | ||
use Jobtech\LaravelChunky\Strategies\AudioStrategy; | ||
use Jobtech\LaravelChunky\Tests\TestCase; | ||
|
||
class AudioStrategyTest extends TestCase | ||
{ | ||
/** | ||
* @var ChunksManager | ||
*/ | ||
private $manager; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->manager = $this->app->make('chunky'); | ||
} | ||
|
||
/** @test */ | ||
public function strategy_retrieves_visibility_from_options() | ||
{ | ||
$mock = $this->mock(ChunksManager::class, function ($mock) { | ||
$mock->shouldReceive('getMergeOptions') | ||
->once() | ||
->andReturn([]); | ||
|
||
$mock->shouldReceive('getMergeOptions') | ||
->once() | ||
->andReturn([ | ||
'visibility' => 'public', | ||
]); | ||
}); | ||
|
||
$strategy = new AudioStrategy($mock); | ||
|
||
$this->assertNull($strategy->visibility()); | ||
$this->assertEquals('public', $strategy->visibility()); | ||
} | ||
|
||
/** @test */ | ||
public function strategy_merges_chunks_without_transcode() | ||
{ | ||
$this->manager->chunksFilesystem()->makeDirectory('chunks'); | ||
|
||
$strategy = new AudioStrategy($this->manager); | ||
$strategy->chunksFolder('resources/mp3'); | ||
$strategy->destination('foo/sample.mp3'); | ||
|
||
$strategy->merge(); | ||
|
||
Storage::assertExists('foo/sample.mp3'); | ||
Storage::assertMissing('chunks/resources/mp3/0_sample.mp3'); | ||
Storage::assertMissing('chunks/resources/mp3/1_sample.mp3'); | ||
Storage::assertMissing('chunks/resources/mp3/2_sample.mp3'); | ||
Storage::assertMissing('chunks/resources/mp3'); | ||
} | ||
|
||
/** @test */ | ||
public function strategy_merges_chunks_with_transcode() | ||
{ | ||
$this->manager->chunksFilesystem()->makeDirectory('chunks'); | ||
|
||
$strategy = new AudioStrategy($this->manager); | ||
$strategy->chunksFolder('resources/mp3'); | ||
$strategy->destination('foo/sample.wav'); | ||
|
||
$strategy->merge(); | ||
|
||
Storage::assertExists('foo/sample.wav'); | ||
Storage::assertMissing('chunks/resources/mp3/0_sample.mp3'); | ||
Storage::assertMissing('chunks/resources/mp3/1_sample.mp3'); | ||
Storage::assertMissing('chunks/resources/mp3/2_sample.mp3'); | ||
Storage::assertMissing('chunks/resources/mp3'); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...erge/Strategies/FlysystemStrategyTest.php → ...Unit/Strategies/FlysystemStrategyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.