From 69767d3d34a8936869c7d8e6cb3b97c6f676a3dd Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 5 Aug 2013 14:36:27 +0200 Subject: [PATCH] Allow use of FFProbe on remote files --- src/FFMpeg/FFProbe.php | 13 +++++------ tests/FFMpeg/Functional/FFProbeTest.php | 29 +++++++++++++++++++++++++ tests/FFMpeg/Tests/FFProbeTest.php | 12 ---------- 3 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 tests/FFMpeg/Functional/FFProbeTest.php diff --git a/src/FFMpeg/FFProbe.php b/src/FFMpeg/FFProbe.php index db71971..7a32105 100644 --- a/src/FFMpeg/FFProbe.php +++ b/src/FFMpeg/FFProbe.php @@ -12,6 +12,7 @@ namespace FFMpeg; use Alchemy\BinaryDriver\ConfigurationInterface; +use Alchemy\BinaryDriver\Exception\ExecutionFailureException; use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\Cache; use FFMpeg\Driver\FFProbeDriver; @@ -207,12 +208,6 @@ class FFProbe private function probe($pathfile, $command, $type, $allowJson = true) { - if (!is_file($pathfile)) { - throw new InvalidArgumentException(sprintf( - 'Invalid filepath %s, unable to read.', $pathfile - )); - } - $id = sprintf('%s-%s', $command, $pathfile); if ($this->cache->contains($id)) { @@ -237,7 +232,11 @@ class FFProbe $parseIsToDo = true; } - $output = $this->ffprobe->command($commands); + try { + $output = $this->ffprobe->command($commands); + } catch (ExecutionFailureException $e) { + throw new RuntimeException(sprintf('Unable to probe %s', $pathfile), $e->getCode(), $e); + } if ($parseIsToDo) { $data = $this->parser->parse($type, $output); diff --git a/tests/FFMpeg/Functional/FFProbeTest.php b/tests/FFMpeg/Functional/FFProbeTest.php new file mode 100644 index 0000000..373c24f --- /dev/null +++ b/tests/FFMpeg/Functional/FFProbeTest.php @@ -0,0 +1,29 @@ +assertGreaterThan(0, count($ffprobe->streams(__DIR__ . '/../../files/Audio.mp3'))); + } + + /** + * @expectedException FFMpeg\Exception\RuntimeException + */ + public function testProbeOnUnexistantFile() + { + $ffprobe = FFProbe::create(); + $ffprobe->streams('/path/to/no/file'); + } + + public function testProbeOnRemoteFile() + { + $ffprobe = FFProbe::create(); + $this->assertGreaterThan(0, count($ffprobe->streams('http://video-js.zencoder.com/oceans-clip.mp4'))); + } +} diff --git a/tests/FFMpeg/Tests/FFProbeTest.php b/tests/FFMpeg/Tests/FFProbeTest.php index bf0ca3c..bb119ea 100644 --- a/tests/FFMpeg/Tests/FFProbeTest.php +++ b/tests/FFMpeg/Tests/FFProbeTest.php @@ -228,18 +228,6 @@ class FFProbeTest extends TestCase $this->assertEquals($output, call_user_func(array($ffprobe, $method), $pathfile)); } - /** - * @expectedException FFMpeg\Exception\InvalidArgumentException - * @dataProvider provideProbeMethod - */ - public function testProbeWithInvalidFile($method) - { - $pathfile = '/path/to/nofile'; - - $ffprobe = new FFProbe($this->getFFProbeDriverMock(), $this->getCacheMock()); - call_user_func(array($ffprobe, $method), $pathfile); - } - public function provideProbeMethod() { return array(