Merge pull request #77 from alchemy-fr/file-restrictions
Fix #76 : Remove restriction on filesystem resources
This commit is contained in:
		
				commit
				
					
						e92fc312cd
					
				
			
		
					 10 changed files with 36 additions and 49 deletions
				
			
		|  | @ -5,6 +5,7 @@ CHANGELOG | ||||||
| 
 | 
 | ||||||
|   * Add Rotate filter. |   * Add Rotate filter. | ||||||
|   * Remove time_start metadata when using synchronize filter |   * Remove time_start metadata when using synchronize filter | ||||||
|  |   * Remove restriction on filesystem resources. | ||||||
| 
 | 
 | ||||||
| * 0.4.1 (11-26-2013) | * 0.4.1 (11-26-2013) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -14,6 +14,7 @@ namespace FFMpeg; | ||||||
| use Alchemy\BinaryDriver\ConfigurationInterface; | use Alchemy\BinaryDriver\ConfigurationInterface; | ||||||
| use FFMpeg\Driver\FFMpegDriver; | use FFMpeg\Driver\FFMpegDriver; | ||||||
| use FFMpeg\Exception\InvalidArgumentException; | use FFMpeg\Exception\InvalidArgumentException; | ||||||
|  | use FFMpeg\Exception\RuntimeException; | ||||||
| use FFMpeg\Media\Audio; | use FFMpeg\Media\Audio; | ||||||
| use FFMpeg\Media\Video; | use FFMpeg\Media\Video; | ||||||
| use Psr\Log\LoggerInterface; | use Psr\Log\LoggerInterface; | ||||||
|  | @ -88,12 +89,10 @@ class FFMpeg | ||||||
|      */ |      */ | ||||||
|     public function open($pathfile) |     public function open($pathfile) | ||||||
|     { |     { | ||||||
|         if (!file_exists($pathfile)) { |         if (null === $streams = $this->ffprobe->streams($pathfile)) { | ||||||
|             throw new InvalidArgumentException(sprintf('File %s does not exists', $pathfile)); |             throw new RuntimeException(sprintf('Unable to probe "%s".', $pathfile)); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         $streams = $this->ffprobe->streams($pathfile); |  | ||||||
| 
 |  | ||||||
|         if (0 < count($streams->videos())) { |         if (0 < count($streams->videos())) { | ||||||
|             return new Video($pathfile, $this->driver, $this->ffprobe); |             return new Video($pathfile, $this->driver, $this->ffprobe); | ||||||
|         } elseif (0 < count($streams->audios())) { |         } elseif (0 < count($streams->audios())) { | ||||||
|  |  | ||||||
|  | @ -154,6 +154,10 @@ abstract class AbstractProgressListener extends EventEmitter implements Listener | ||||||
|             $this->initialize(); |             $this->initialize(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         if (null === $this->totalSize || null === $this->duration) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         $matches = array(); |         $matches = array(); | ||||||
| 
 | 
 | ||||||
|         if (preg_match($this->getPattern(), $progress, $matches) !== 1) { |         if (preg_match($this->getPattern(), $progress, $matches) !== 1) { | ||||||
|  | @ -226,9 +230,14 @@ abstract class AbstractProgressListener extends EventEmitter implements Listener | ||||||
| 
 | 
 | ||||||
|     private function initialize() |     private function initialize() | ||||||
|     { |     { | ||||||
|         $format = $this->ffprobe->format($this->pathfile); |         try { | ||||||
|  |             $format = $this->ffprobe->format($this->pathfile); | ||||||
|  |         } catch (RuntimeException $e) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         if (false === $format->has('size') || false === $format->has('duration')) { |         if (false === $format->has('size') || false === $format->has('duration')) { | ||||||
|  |             return; | ||||||
|             throw new RuntimeException(sprintf('Unable to probe format for %s', $this->pathfile)); |             throw new RuntimeException(sprintf('Unable to probe format for %s', $this->pathfile)); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -30,8 +30,6 @@ abstract class AbstractMediaType implements MediaTypeInterface | ||||||
| 
 | 
 | ||||||
|     public function __construct($pathfile, FFMpegDriver $driver, FFProbe $ffprobe) |     public function __construct($pathfile, FFMpegDriver $driver, FFProbe $ffprobe) | ||||||
|     { |     { | ||||||
|         $this->ensureFileIsPresent($pathfile); |  | ||||||
| 
 |  | ||||||
|         $this->pathfile = $pathfile; |         $this->pathfile = $pathfile; | ||||||
|         $this->driver = $driver; |         $this->driver = $driver; | ||||||
|         $this->ffprobe = $ffprobe; |         $this->ffprobe = $ffprobe; | ||||||
|  | @ -106,15 +104,6 @@ abstract class AbstractMediaType implements MediaTypeInterface | ||||||
|         return $this->filters; |         return $this->filters; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     protected function ensureFileIsPresent($filename) |  | ||||||
|     { |  | ||||||
|         if (!is_file($filename) || !is_readable($filename)) { |  | ||||||
|             throw new InvalidArgumentException(sprintf( |  | ||||||
|                 '%s is not present or not readable', $filename |  | ||||||
|             )); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     protected function cleanupTemporaryFile($filename) |     protected function cleanupTemporaryFile($filename) | ||||||
|     { |     { | ||||||
|         if (file_exists($filename) && is_writable($filename)) { |         if (file_exists($filename) && is_writable($filename)) { | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ | ||||||
| namespace FFMpeg\Functional; | namespace FFMpeg\Functional; | ||||||
| 
 | 
 | ||||||
| use FFMpeg\Format\Video\X264; | use FFMpeg\Format\Video\X264; | ||||||
|  | use FFMpeg\Media\Video; | ||||||
| 
 | 
 | ||||||
| class VideoTranscodeTest extends FunctionalTestCase | class VideoTranscodeTest extends FunctionalTestCase | ||||||
| { | { | ||||||
|  | @ -35,4 +36,22 @@ class VideoTranscodeTest extends FunctionalTestCase | ||||||
|         $this->assertFileExists($filename); |         $this->assertFileExists($filename); | ||||||
|         unlink($filename); |         unlink($filename); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @expectedException \FFMpeg\Exception\RuntimeException | ||||||
|  |      */ | ||||||
|  |     public function testTranscodeInvalidFile() | ||||||
|  |     { | ||||||
|  |         $ffmpeg = $this->getFFMpeg(); | ||||||
|  |         $ffmpeg->open(__DIR__ . '/../../files/UnknownFileTest.ogv'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function testSaveInvalidForgedVideo() | ||||||
|  |     { | ||||||
|  |         $ffmpeg = $this->getFFMpeg(); | ||||||
|  |         $video = new Video(__DIR__ . '/../../files/UnknownFileTest.ogv', $ffmpeg->getFFMpegDriver(), $ffmpeg->getFFProbe()); | ||||||
|  | 
 | ||||||
|  |         $this->setExpectedException('FFMpeg\Exception\RuntimeException'); | ||||||
|  |         $video->save(new X264('libvo_aacenc'), __DIR__ . '/output/output-x264.mp4'); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -10,7 +10,8 @@ use FFMpeg\FFProbe\DataMapping\Stream; | ||||||
| class FFMpegTest Extends TestCase | class FFMpegTest Extends TestCase | ||||||
| { | { | ||||||
|     /** |     /** | ||||||
|      * @expectedException FFMpeg\Exception\InvalidArgumentException |      * @expectedException \FFMpeg\Exception\RuntimeException | ||||||
|  |      * @expectedExceptionMessage Unable to probe "/path/to/unknown/file". | ||||||
|      */ |      */ | ||||||
|     public function testOpenInvalid() |     public function testOpenInvalid() | ||||||
|     { |     { | ||||||
|  | @ -58,7 +59,7 @@ class FFMpegTest Extends TestCase | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * @expectedException FFMpeg\Exception\InvalidArgumentException |      * @expectedException \FFMpeg\Exception\InvalidArgumentException | ||||||
|      */ |      */ | ||||||
|     public function testOpenUnknown() |     public function testOpenUnknown() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -6,5 +6,4 @@ use FFMpeg\Tests\TestCase; | ||||||
| 
 | 
 | ||||||
| abstract class AbstractMediaTestCase extends TestCase | abstract class AbstractMediaTestCase extends TestCase | ||||||
| { | { | ||||||
|     abstract public function testWithInvalidFile(); |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -9,17 +9,6 @@ use FFMpeg\Format\AudioInterface; | ||||||
| 
 | 
 | ||||||
| class AudioTest extends AbstractStreamableTestCase | class AudioTest extends AbstractStreamableTestCase | ||||||
| { | { | ||||||
|     /** |  | ||||||
|      * @expectedException FFMpeg\Exception\InvalidArgumentException |  | ||||||
|      */ |  | ||||||
|     public function testWithInvalidFile() |  | ||||||
|     { |  | ||||||
|         $driver = $this->getFFMpegDriverMock(); |  | ||||||
|         $ffprobe = $this->getFFProbeMock(); |  | ||||||
| 
 |  | ||||||
|         new Audio('/no/file', $driver, $ffprobe); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testFiltersReturnsAudioFilters() |     public function testFiltersReturnsAudioFilters() | ||||||
|     { |     { | ||||||
|         $driver = $this->getFFMpegDriverMock(); |         $driver = $this->getFFMpegDriverMock(); | ||||||
|  |  | ||||||
|  | @ -6,14 +6,6 @@ use FFMpeg\Media\Frame; | ||||||
| 
 | 
 | ||||||
| class FrameTest extends AbstractMediaTestCase | class FrameTest extends AbstractMediaTestCase | ||||||
| { | { | ||||||
|     /** |  | ||||||
|      * @expectedException FFMpeg\Exception\InvalidArgumentException |  | ||||||
|      */ |  | ||||||
|     public function testWithInvalidFile() |  | ||||||
|     { |  | ||||||
|         new Frame($this->getVideoMock('/No/file'), $this->getFFMpegDriverMock(), $this->getFFProbeMock(), $this->getTimeCodeMock()); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testGetTimeCode() |     public function testGetTimeCode() | ||||||
|     { |     { | ||||||
|         $driver = $this->getFFMpegDriverMock(); |         $driver = $this->getFFMpegDriverMock(); | ||||||
|  |  | ||||||
|  | @ -9,17 +9,6 @@ use FFMpeg\Format\VideoInterface; | ||||||
| 
 | 
 | ||||||
| class VideoTest extends AbstractStreamableTestCase | class VideoTest extends AbstractStreamableTestCase | ||||||
| { | { | ||||||
|     /** |  | ||||||
|      * @expectedException FFMpeg\Exception\InvalidArgumentException |  | ||||||
|      */ |  | ||||||
|     public function testWithInvalidFile() |  | ||||||
|     { |  | ||||||
|         $driver = $this->getFFMpegDriverMock(); |  | ||||||
|         $ffprobe = $this->getFFProbeMock(); |  | ||||||
| 
 |  | ||||||
|         new Video('/no/file', $driver, $ffprobe); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testFiltersReturnsVideoFilters() |     public function testFiltersReturnsVideoFilters() | ||||||
|     { |     { | ||||||
|         $driver = $this->getFFMpegDriverMock(); |         $driver = $this->getFFMpegDriverMock(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue