From f01d42392427fc475e549beb610c5c2e5a69c2f6 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 23 Jun 2023 08:50:20 +0200 Subject: [PATCH 1/2] `VideoDetails::$videoType` is now required and will default to `"video"` --- CHANGELOG.md | 6 ++++++ src/Video/Data/VideoDetails.php | 2 +- tests/Video/VideoUrlParsingTest.php | 30 ++++++++++++++--------------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 915bb1d..a89bd8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +1.0.2 +===== + +* (improvement) `VideoDetails::$videoType` is now required and will default to `"video"`. + + 1.0.1 ===== diff --git a/src/Video/Data/VideoDetails.php b/src/Video/Data/VideoDetails.php index 099cb56..7f4a7e4 100644 --- a/src/Video/Data/VideoDetails.php +++ b/src/Video/Data/VideoDetails.php @@ -11,7 +11,7 @@ final class VideoDetails public function __construct ( public readonly VideoPlatform $platform, public readonly string $id, - public readonly ?string $videoType = null, + public readonly string $videoType = "video", ) {} /** diff --git a/tests/Video/VideoUrlParsingTest.php b/tests/Video/VideoUrlParsingTest.php index 5e1ae88..5689673 100644 --- a/tests/Video/VideoUrlParsingTest.php +++ b/tests/Video/VideoUrlParsingTest.php @@ -17,14 +17,14 @@ final class VideoUrlParsingTest extends TestCase public static function provideTestCases () : iterable { // YouTube: valid - yield "youtube http" => ["http://www.youtube.com/watch?v=1234567890_", VideoPlatform::YouTube, "1234567890_", "video"]; - yield "youtube https" => ["https://www.youtube.com/watch?v=1234567890_", VideoPlatform::YouTube, "1234567890_", "video"]; - yield "youtube/v" => ["https://www.youtube.com/v/1234567890_?a=3&b=1", VideoPlatform::YouTube, "1234567890_", "video"]; - yield "youtube/shorts" => ["https://www.youtube.com/shorts/1234567890_?a=3&b=1", VideoPlatform::YouTube, "1234567890_", "shorts"]; - yield "youtube/embed" => ["https://www.youtube.com/embed/1234567890_?a=3&b=1", VideoPlatform::YouTube, "1234567890_", "video"]; - yield "youtu.be https" => ["https://youtu.be/1234567890_", VideoPlatform::YouTube, "1234567890_", "video"]; - yield "youtu.be http" => ["http://youtu.be/1234567890_", VideoPlatform::YouTube, "1234567890_", "video"]; - yield "youtube/oembed" => ["https://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D1234567890_&format=json", VideoPlatform::YouTube, "1234567890_", "video"]; + 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/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_"]; + yield "youtube/oembed" => ["https://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D1234567890_&format=json", VideoPlatform::YouTube, "1234567890_"]; // YouTube: invalid yield "youtube/watch invalid id" => ["http://www.youtube.com/watch?v=123456789012", null]; @@ -41,12 +41,12 @@ public static function provideTestCases () : iterable yield "youtube/embed sub before" => ["https://youtube.com/embed/sub/1234567890_", null]; // Vimeo: valid - yield "vimeo https" => ["http://vimeo.com/123456789", VideoPlatform::Vimeo, "123456789", "video"]; - yield "vimeo http" => ["https://vimeo.com/123456789", VideoPlatform::Vimeo, "123456789", "video"]; - yield "vimeo with query" => ["https://vimeo.com/123456789?q=uery", VideoPlatform::Vimeo, "123456789", "video"]; - yield "vimeo with fragment" => ["https://vimeo.com/123456789#fragment", VideoPlatform::Vimeo, "123456789", "video"]; - yield "vimeo with query + fragment" => ["https://vimeo.com/123456789?q=uery#fragment", VideoPlatform::Vimeo, "123456789", "video"]; - yield "vimeo staff picks" => ["https://vimeo.com/channels/staffpicks/123456789", VideoPlatform::Vimeo, "123456789", "video"]; + yield "vimeo https" => ["http://vimeo.com/123456789", VideoPlatform::Vimeo, "123456789"]; + yield "vimeo http" => ["https://vimeo.com/123456789", VideoPlatform::Vimeo, "123456789"]; + yield "vimeo with query" => ["https://vimeo.com/123456789?q=uery", VideoPlatform::Vimeo, "123456789"]; + yield "vimeo with fragment" => ["https://vimeo.com/123456789#fragment", VideoPlatform::Vimeo, "123456789"]; + yield "vimeo with query + fragment" => ["https://vimeo.com/123456789?q=uery#fragment", VideoPlatform::Vimeo, "123456789"]; + yield "vimeo staff picks" => ["https://vimeo.com/channels/staffpicks/123456789", VideoPlatform::Vimeo, "123456789"]; // Vimeo: invalid yield "vimeo with before path" => ["https://vimeo.com/before/123456789", null]; @@ -62,7 +62,7 @@ public function testParsing ( string $url, ?VideoPlatform $expectedPlatform, ?string $expectedId = null, - ?string $expectedVideoType = null, + string $expectedVideoType = "video", ) : void { $parser = new VideoUrlParser([ From 92a8d83a7675c32fd76016d697b0a70b4e994569 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 23 Jun 2023 08:50:24 +0200 Subject: [PATCH 2/2] Renamed the YouTube video type "shorts" to "short" --- CHANGELOG.md | 1 + src/Video/Parser/YouTubeUrlParser.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a89bd8e..29f80f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ===== * (improvement) `VideoDetails::$videoType` is now required and will default to `"video"`. +* (improvement) Renamed the YouTube video type "shorts" to "short". 1.0.1 diff --git a/src/Video/Parser/YouTubeUrlParser.php b/src/Video/Parser/YouTubeUrlParser.php index 99832a4..163e234 100644 --- a/src/Video/Parser/YouTubeUrlParser.php +++ b/src/Video/Parser/YouTubeUrlParser.php @@ -33,7 +33,7 @@ public function parseUrl (string $url) : ?VideoDetails return $this->createVideoDetails( $match["id"], "shorts" === $match["type"] - ? "shorts" + ? "short" : "video", ); }