-
Notifications
You must be signed in to change notification settings - Fork 5
/
Youtube.php
71 lines (54 loc) · 1.62 KB
/
Youtube.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Faker\Provider;
class Youtube extends Base
{
public function youtubeId()
{
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
. 'abcdefghijklmnopqrstuvwxyz_-';
$id = substr($this->shuffle($characters), 0, 11);
return $this->generator->parse($id);
}
public function youtubeUri()
{
return 'https://www.youtube.com/watch?v=' . $this->youtubeId();
}
public function youtubeShortUri()
{
return 'https://youtu.be/' . $this->youtubeId();
}
public function youtubeEmbedUri()
{
return 'https://www.youtube.com/embed/' . $this->youtubeId();
}
public function youtubeEmbedCode()
{
return '<iframe width="560" height="315" src="' . $this->youtubeEmbedUri()
. '" frameborder="0" gesture="media" allow="encrypted-media"'
. ' allowfullscreen></iframe>';
}
public function youtubeChannelUri()
{
return sprintf('https://www.youtube.com/%s/%s',
$this->randomElement(['channel', 'user']),
$this->regexify(sprintf('[a-zA-Z0-9\-]{1,%s}', $this->numberBetween(1, 20)))
);
}
public function youtubeRandomUri()
{
switch ($this->numberBetween(1,3)) {
case 1:
return $this->youtubeUri();
break;
case 2:
return $this->youtubeShortUri();
break;
case 3:
return $this->youtubeEmbedUri();
break;
default:
return $this->youtubeUri();
break;
}
}
}