Skip to content

Commit

Permalink
Remove videoType and add youtube-short provider
Browse files Browse the repository at this point in the history
  • Loading branch information
apfelbox committed Mar 15, 2024
1 parent caabf7e commit 4205269
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2.0.0
=====

* (bc) Remove `videoType` from video data.
* (feature) Add new `youtube-short` provider.


1.0.3
=====

Expand Down
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1.x to 2.0
==========

* The `videoType` field in `VideoDetails` was removed.
* YouTube shorts are now a separate provider.
1 change: 0 additions & 1 deletion src/Video/Data/VideoDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ final class VideoDetails
public function __construct (
public readonly VideoPlatform $platform,
public readonly string $id,
public readonly string $videoType = "video",
) {}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Video/Parser/VimeoUrlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function parseUrl (string $url) : ?VideoDetails
? new VideoDetails(
VideoPlatform::Vimeo,
$id,
"video",
)
: null;
}
Expand Down
14 changes: 8 additions & 6 deletions src/Video/Parser/YouTubeUrlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public function parseUrl (string $url) : ?VideoDetails
{
return $this->createVideoDetails(
$match["id"],
"shorts" === $match["type"]
? "short"
: "video",
isFullVideo: "shorts" !== $match["type"],
);
}

Expand Down Expand Up @@ -64,17 +62,21 @@ 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),
$id,
))
{
return new VideoDetails(
VideoPlatform::YouTube,
$isFullVideo
? VideoPlatform::YouTube
: VideoPlatform::YouTubeShort,
$id,
$videoType,
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Video/VideoPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ enum VideoPlatform : string

case YouTube = "youtube";

case YouTubeShort = "youtube-short";

/**
*
*/
Expand All @@ -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),
};
}
}
5 changes: 1 addition & 4 deletions tests/Video/VideoUrlParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_"];
Expand Down Expand Up @@ -61,7 +61,6 @@ public function testParsing (
string $url,
?VideoPlatform $expectedPlatform,
?string $expectedId = null,
string $expectedVideoType = "video",
) : void
{
$parser = new VideoUrlParser([
Expand All @@ -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);
}

}
}

0 comments on commit 4205269

Please sign in to comment.