Skip to content

Commit 18f1d95

Browse files
committed
Add playlist embed code builder
1 parent 03dab07 commit 18f1d95

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace Embed\Adapters\Tidal\Detectors;
5+
6+
use Embed\Detectors\Code as Detector;
7+
use Embed\EmbedCode;
8+
use function Embed\html;
9+
10+
class Code extends Detector
11+
{
12+
public function detect(): ?EmbedCode
13+
{
14+
return parent::detect()
15+
?: $this->fallback();
16+
}
17+
18+
private function fallback(): ?EmbedCode
19+
{
20+
$uri = $this->extractor->getUri();
21+
22+
if (!preg_match('{^/playlist/(?P<uuid>[0-9a-fA-F\-]{36})$}', $uri->getPath(), $matches)) {
23+
return NULL;
24+
}
25+
26+
$html = html('iframe', [
27+
'src' => 'https://embed.tidal.com/playlists/' . $matches['uuid'] . '?disableAnalytics=true',
28+
'allow' => 'encrypted-media',
29+
'allowfullscreen' => 'allowfullscreen',
30+
'frameborder' => '0',
31+
'style' => 'width:100%;height:352px',
32+
]);
33+
34+
return new EmbedCode($html, null, 352);
35+
}
36+
}

src/Adapters/Tidal/Extractor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Extractor extends Base
1010
public function createCustomDetectors(): array
1111
{
1212
return [
13+
'code' => new Detectors\Code($this),
1314
'providerName' => new Detectors\ProviderName($this),
1415
];
1516
}

0 commit comments

Comments
 (0)