From 86b0876a9e720522457e53e87f0b5e86b1532e5f Mon Sep 17 00:00:00 2001 From: odan Date: Tue, 3 Sep 2019 21:50:01 +0200 Subject: [PATCH] Add FLV (Adobe Flash Video) #11 --- .gitattributes | 1 + README.md | 1 + src/Detector/FlvDetector.php | 29 +++++++++++++++++++++++++++ src/Provider/DefaultVideoProvider.php | 2 ++ src/VideoFormat.php | 1 + src/VideoMimeType.php | 1 + tests/VideoTypeDetectorTest.php | 1 + tests/videos/test.flv | 1 + 8 files changed, 37 insertions(+) create mode 100644 src/Detector/FlvDetector.php create mode 100644 tests/videos/test.flv diff --git a/.gitattributes b/.gitattributes index c59de00..437cfe3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -38,3 +38,4 @@ *.ogg binary *.ogv binary *.wmv binary +*.flv binary diff --git a/README.md b/README.md index 80d763e..6653691 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Video type detection library for PHP. * **WEBM** * **QuickTime** * **WMV** (Windows Media Video) +* **FLV** (Adobe Flash Video) ## Requirements diff --git a/src/Detector/FlvDetector.php b/src/Detector/FlvDetector.php new file mode 100644 index 0000000..11d34d2 --- /dev/null +++ b/src/Detector/FlvDetector.php @@ -0,0 +1,29 @@ +fread(3) === 'FLV' ? new VideoType( + VideoFormat::FLV, + VideoMimeType::VIDEO_FLV + ) : null; + } +} diff --git a/src/Provider/DefaultVideoProvider.php b/src/Provider/DefaultVideoProvider.php index 79d43f7..3e4f867 100644 --- a/src/Provider/DefaultVideoProvider.php +++ b/src/Provider/DefaultVideoProvider.php @@ -3,6 +3,7 @@ namespace Selective\VideoType\Provider; use Selective\VideoType\Detector\AviDetector; +use Selective\VideoType\Detector\FlvDetector; use Selective\VideoType\Detector\MpegDetector; use Selective\VideoType\Detector\Mpeg4Detector; use Selective\VideoType\Detector\MkvDetector; @@ -34,6 +35,7 @@ public function getDetectors(): array new ThreeGp2Detector(), new QuickTimeDetector(), new WmvDetector(), + new FlvDetector(), ]; } } diff --git a/src/VideoFormat.php b/src/VideoFormat.php index 9b23773..1096a74 100644 --- a/src/VideoFormat.php +++ b/src/VideoFormat.php @@ -17,4 +17,5 @@ final class VideoFormat public const THREEG2 = '3g2'; public const QUICK_TIME = 'mov'; public const WMV = 'wmv'; + public const FLV = 'flv'; } diff --git a/src/VideoMimeType.php b/src/VideoMimeType.php index 2b05d67..c1043f9 100644 --- a/src/VideoMimeType.php +++ b/src/VideoMimeType.php @@ -17,4 +17,5 @@ final class VideoMimeType public const VIDEO_3G2 = 'video/3gpp2'; public const VIDEO_QUICK_TIME = 'video/quicktime'; public const VIDEO_WMV = 'video/x-ms-wmv'; + public const VIDEO_FLV = 'video/x-flv'; } diff --git a/tests/VideoTypeDetectorTest.php b/tests/VideoTypeDetectorTest.php index a35f449..15931c7 100644 --- a/tests/VideoTypeDetectorTest.php +++ b/tests/VideoTypeDetectorTest.php @@ -74,6 +74,7 @@ public function providerGetVideoTypeFromFile(): array [__DIR__ . '/videos/test.mov', VideoFormat::QUICK_TIME, VideoMimeType::VIDEO_QUICK_TIME], [__DIR__ . '/videos/test.ogv', VideoFormat::OGV, VideoMimeType::VIDEO_OGG], [__DIR__ . '/videos/test.wmv', VideoFormat::WMV, VideoMimeType::VIDEO_WMV], + [__DIR__ . '/videos/test.flv', VideoFormat::FLV, VideoMimeType::VIDEO_FLV], ]; } diff --git a/tests/videos/test.flv b/tests/videos/test.flv new file mode 100644 index 0000000..9eadd6e --- /dev/null +++ b/tests/videos/test.flv @@ -0,0 +1 @@ +FLV \ No newline at end of file