Fix #76 : Remove restriction on filesystem resources

This commit is contained in:
Romain Neutron 2013-11-29 11:14:49 +01:00
commit ad2b9e75a5
10 changed files with 36 additions and 49 deletions

View file

@ -14,6 +14,7 @@ namespace FFMpeg;
use Alchemy\BinaryDriver\ConfigurationInterface;
use FFMpeg\Driver\FFMpegDriver;
use FFMpeg\Exception\InvalidArgumentException;
use FFMpeg\Exception\RuntimeException;
use FFMpeg\Media\Audio;
use FFMpeg\Media\Video;
use Psr\Log\LoggerInterface;
@ -88,12 +89,10 @@ class FFMpeg
*/
public function open($pathfile)
{
if (!file_exists($pathfile)) {
throw new InvalidArgumentException(sprintf('File %s does not exists', $pathfile));
if (null === $streams = $this->ffprobe->streams($pathfile)) {
throw new RuntimeException(sprintf('Unable to probe "%s".', $pathfile));
}
$streams = $this->ffprobe->streams($pathfile);
if (0 < count($streams->videos())) {
return new Video($pathfile, $this->driver, $this->ffprobe);
} elseif (0 < count($streams->audios())) {

View file

@ -154,6 +154,10 @@ abstract class AbstractProgressListener extends EventEmitter implements Listener
$this->initialize();
}
if (null === $this->totalSize || null === $this->duration) {
return;
}
$matches = array();
if (preg_match($this->getPattern(), $progress, $matches) !== 1) {
@ -226,9 +230,14 @@ abstract class AbstractProgressListener extends EventEmitter implements Listener
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')) {
return;
throw new RuntimeException(sprintf('Unable to probe format for %s', $this->pathfile));
}

View file

@ -30,8 +30,6 @@ abstract class AbstractMediaType implements MediaTypeInterface
public function __construct($pathfile, FFMpegDriver $driver, FFProbe $ffprobe)
{
$this->ensureFileIsPresent($pathfile);
$this->pathfile = $pathfile;
$this->driver = $driver;
$this->ffprobe = $ffprobe;
@ -106,15 +104,6 @@ abstract class AbstractMediaType implements MediaTypeInterface
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)
{
if (file_exists($filename) && is_writable($filename)) {