-
-
Notifications
You must be signed in to change notification settings - Fork 630
Expand file tree
/
Copy pathVideo.php
More file actions
56 lines (46 loc) · 1.46 KB
/
Copy pathVideo.php
File metadata and controls
56 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Statamic\Fieldtypes\Video;
use Embera\Embera;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
use Illuminate\Support\Fluent;
use Illuminate\Support\Str;
class Video implements Arrayable
{
public static function fromUrl(string $url): self
{
if (Str::startsWith($url, 'cloudflare:')) {
$id = Str::after($url, 'cloudflare:');
$embedUrl = "https://iframe.cloudflarestream.com/{$id}";
$iframe = "<iframe src='$embedUrl' frameborder='0' allow='fullscreen' style='height: 100%; width: 100%;'></iframe>";
return new self(id: $id, provider: 'Cloudflare', embed: $iframe);
}
if (empty($details = (new Embera(['responsive' => true]))->getUrlData($url))) {
return static::notSupported();
}
$data = new Fluent(Arr::first($details));
return new self(
id: $data->video_id,
provider: $data->embera_provider_name,
embed: $data->html
);
}
public static function notSupported(): self
{
return new self(provider: 'Not Supported');
}
public function __construct(
public string $provider,
public ?string $id = null,
public ?string $embed = null,
) {
}
public function toArray(): array
{
return [
'embed' => $this->embed,
'id' => $this->id,
'provider' => $this->provider,
];
}
}