From 420526986b8564d5f7caddfbe8b74c5d835a2864 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 15 Mar 2024 12:35:00 +0100 Subject: [PATCH] Remove `videoType` and add `youtube-short` provider --- CHANGELOG.md | 7 +++++++ UPGRADE.md | 5 +++++ src/Video/Data/VideoDetails.php | 1 - src/Video/Parser/VimeoUrlParser.php | 1 - src/Video/Parser/YouTubeUrlParser.php | 14 ++++++++------ src/Video/VideoPlatform.php | 5 ++++- tests/Video/VideoUrlParsingTest.php | 5 +---- 7 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 UPGRADE.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b67e0b..36958e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +2.0.0 +===== + +* (bc) Remove `videoType` from video data. +* (feature) Add new `youtube-short` provider. + + 1.0.3 ===== diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000..6972b13 --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,5 @@ +1.x to 2.0 +========== + +* The `videoType` field in `VideoDetails` was removed. +* YouTube shorts are now a separate provider. diff --git a/src/Video/Data/VideoDetails.php b/src/Video/Data/VideoDetails.php index 7f4a7e4..b7df0c4 100644 --- a/src/Video/Data/VideoDetails.php +++ b/src/Video/Data/VideoDetails.php @@ -11,7 +11,6 @@ final class VideoDetails public function __construct ( public readonly VideoPlatform $platform, public readonly string $id, - public readonly string $videoType = "video", ) {} /** diff --git a/src/Video/Parser/VimeoUrlParser.php b/src/Video/Parser/VimeoUrlParser.php index ce7ace7..123ee68 100644 --- a/src/Video/Parser/VimeoUrlParser.php +++ b/src/Video/Parser/VimeoUrlParser.php @@ -18,7 +18,6 @@ public function parseUrl (string $url) : ?VideoDetails ? new VideoDetails( VideoPlatform::Vimeo, $id, - "video", ) : null; } diff --git a/src/Video/Parser/YouTubeUrlParser.php b/src/Video/Parser/YouTubeUrlParser.php index 163e234..142b41f 100644 --- a/src/Video/Parser/YouTubeUrlParser.php +++ b/src/Video/Parser/YouTubeUrlParser.php @@ -32,9 +32,7 @@ public function parseUrl (string $url) : ?VideoDetails { return $this->createVideoDetails( $match["id"], - "shorts" === $match["type"] - ? "short" - : "video", + isFullVideo: "shorts" !== $match["type"], ); } @@ -64,7 +62,10 @@ public function parseUrl (string $url) : ?VideoDetails /** * */ - private function createVideoDetails (string $id, string $videoType = "video") : ?VideoDetails + private function createVideoDetails ( + string $id, + bool $isFullVideo = true, + ) : ?VideoDetails { if (\preg_match( \sprintf('~^%s$~', self::ID_PATTERN), @@ -72,9 +73,10 @@ private function createVideoDetails (string $id, string $videoType = "video") : )) { return new VideoDetails( - VideoPlatform::YouTube, + $isFullVideo + ? VideoPlatform::YouTube + : VideoPlatform::YouTubeShort, $id, - $videoType, ); } diff --git a/src/Video/VideoPlatform.php b/src/Video/VideoPlatform.php index 25b7a17..e1dc451 100644 --- a/src/Video/VideoPlatform.php +++ b/src/Video/VideoPlatform.php @@ -8,6 +8,8 @@ enum VideoPlatform : string case YouTube = "youtube"; + case YouTubeShort = "youtube-short"; + /** * */ @@ -16,7 +18,8 @@ public function getEmbedUrl (string $id) : string return match ($this) { self::Vimeo => \sprintf("https://vimeo.com/%s", $id), - self::YouTube => \sprintf("https://www.youtube.com/embed/%s", $id), + self::YouTube, + self::YouTubeShort => \sprintf("https://www.youtube.com/embed/%s", $id), }; } } diff --git a/tests/Video/VideoUrlParsingTest.php b/tests/Video/VideoUrlParsingTest.php index 64cdd6a..46df7d5 100644 --- a/tests/Video/VideoUrlParsingTest.php +++ b/tests/Video/VideoUrlParsingTest.php @@ -19,7 +19,7 @@ public static function provideTestCases () : iterable yield "youtube http" => ["http://www.youtube.com/watch?v=1234567890_", VideoPlatform::YouTube, "1234567890_"]; yield "youtube https" => ["https://www.youtube.com/watch?v=1234567890_", VideoPlatform::YouTube, "1234567890_"]; yield "youtube/v" => ["https://www.youtube.com/v/1234567890_?a=3&b=1", VideoPlatform::YouTube, "1234567890_"]; - yield "youtube/shorts" => ["https://www.youtube.com/shorts/1234567890_?a=3&b=1", VideoPlatform::YouTube, "1234567890_", "short"]; + yield "youtube/shorts" => ["https://www.youtube.com/shorts/1234567890_?a=3&b=1", VideoPlatform::YouTubeShort, "1234567890_"]; yield "youtube/embed" => ["https://www.youtube.com/embed/1234567890_?a=3&b=1", VideoPlatform::YouTube, "1234567890_"]; yield "youtu.be https" => ["https://youtu.be/1234567890_", VideoPlatform::YouTube, "1234567890_"]; yield "youtu.be http" => ["http://youtu.be/1234567890_", VideoPlatform::YouTube, "1234567890_"]; @@ -61,7 +61,6 @@ public function testParsing ( string $url, ?VideoPlatform $expectedPlatform, ?string $expectedId = null, - string $expectedVideoType = "video", ) : void { $parser = new VideoUrlParser([ @@ -79,8 +78,6 @@ public function testParsing ( self::assertNotNull($result); self::assertSame($expectedPlatform, $result->platform); self::assertSame($expectedId, $result->id); - self::assertSame($expectedVideoType, $result->videoType); } - } }