Skip to content

Commit f944eef

Browse files
authored
Merge pull request #435 from kinglozzer/youtube-consent
Update YouTube Oembed adapter to work with new consent page (fixes #434)
2 parents 99f6d95 + 7389dca commit f944eef

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Providers/OEmbed/Youtube.php

+17
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,25 @@
22

33
namespace Embed\Providers\OEmbed;
44

5+
use Embed\Adapters\Adapter;
6+
57
class Youtube extends EndPoint implements EndPointInterface
68
{
79
protected static $pattern = ['*youtube.*', '*youtu\.be.*'];
810
protected static $endPoint = 'https://www.youtube.com/oembed';
11+
12+
public static function create(Adapter $adapter)
13+
{
14+
$response = $adapter->getResponse();
15+
// If the starting URL is a valid YouTube URL, but we've been redirected to a consent page,
16+
// we should attempt to get Oembed using the original URL instead of the consent URL
17+
if (
18+
preg_match('/consent\.youtube.*/', $response->getUrl())
19+
&& $response->getStartingUrl()->match(static::$pattern)
20+
) {
21+
return new static($response, $response->getStartingUrl());
22+
}
23+
24+
return parent::create($adapter);
25+
}
926
}

0 commit comments

Comments
 (0)