Skip to content

Commit

Permalink
Merge pull request #4 from 21TORR/next2
Browse files Browse the repository at this point in the history
Cleanup and make keys more unified
  • Loading branch information
apfelbox authored Jun 23, 2023
2 parents eebd517 + 92a8d83 commit 1d0b532
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.0.2
=====

* (improvement) `VideoDetails::$videoType` is now required and will default to `"video"`.
* (improvement) Renamed the YouTube video type "shorts" to "short".


1.0.1
=====

Expand Down
2 changes: 1 addition & 1 deletion src/Video/Data/VideoDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
) {}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Video/Parser/YouTubeUrlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function parseUrl (string $url) : ?VideoDetails
return $this->createVideoDetails(
$match["id"],
"shorts" === $match["type"]
? "shorts"
? "short"
: "video",
);
}
Expand Down
30 changes: 15 additions & 15 deletions tests/Video/VideoUrlParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -62,7 +62,7 @@ public function testParsing (
string $url,
?VideoPlatform $expectedPlatform,
?string $expectedId = null,
?string $expectedVideoType = null,
string $expectedVideoType = "video",
) : void
{
$parser = new VideoUrlParser([
Expand Down

0 comments on commit 1d0b532

Please sign in to comment.