From d8e02e7f12840205385d370eb42124a95a717a3f Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 12 Jul 2023 17:50:27 +0000 Subject: [PATCH] Probably fixed things by not really doing anything in particular? --- src/FFMPEG.php | 33 ++++++++++++++++++++--------- src/Lookup/WebLookupMediaResult.php | 3 ++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/FFMPEG.php b/src/FFMPEG.php index 5b09d83..e646915 100644 --- a/src/FFMPEG.php +++ b/src/FFMPEG.php @@ -3,6 +3,7 @@ namespace Uiharu; use stdClass; use Imagick; +use RuntimeException; use Index\IO\Stream; use Index\IO\ProcessStream; @@ -23,23 +24,35 @@ final class FFMPEG { } public static function probe(string $url): ?object { - return json_decode( - shell_exec( - sprintf( - 'ffprobe -show_streams -show_format -print_format json -v quiet -i %s', - escapeshellarg($url) - ) - ) + $command = sprintf( + 'ffprobe -show_streams -show_format -print_format json -v quiet -i %s', + escapeshellarg($url) ); + + $ffprobe = proc_open($command, [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); + if(!is_resource($ffprobe)) + throw new RuntimeException('Could not open ffprobe.'); + + try { + $stderr = trim(stream_get_contents($pipes[2])); + if(!empty($stderr)) + throw new RuntimeException('ffprobe: ' . $stderr); + + $stdout = trim(stream_get_contents($pipes[1])); + if(empty($stdout)) + throw new RuntimeException('ffprobe did not report any errors but exited without any output'); + } finally { + proc_close($ffprobe); + } + + return json_decode($stdout); } public static function cleanProbe(string $url): ?object { return self::cleanProbeResult(self::probe($url)); } - public static function cleanProbeResult(?object $in): ?object { - if($in === null) - return null; + public static function cleanProbeResult(?object $in): object { $out = new stdClass; if(!empty($in->format)) { diff --git a/src/Lookup/WebLookupMediaResult.php b/src/Lookup/WebLookupMediaResult.php index 74a5db4..62e1572 100644 --- a/src/Lookup/WebLookupMediaResult.php +++ b/src/Lookup/WebLookupMediaResult.php @@ -4,6 +4,7 @@ namespace Uiharu\Lookup; use Uiharu\AudioTags; use Uiharu\Url; use Index\MediaType; +use Index\Colour\Colour; class WebLookupMediaResult extends WebLookupResult implements \Uiharu\IHasMediaInfo { private object $mediaInfo; @@ -26,7 +27,7 @@ class WebLookupMediaResult extends WebLookupResult implements \Uiharu\IHasMediaI public function hasColour(): bool { return false; } - public function getColour(): int { + public function getColour(): Colour { throw new RuntimeException('Unsupported'); }