|
1
|
|
|
<?php namespace Arcanedev\EmbedVideo\Parsers; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class YoutubeParser |
|
5
|
|
|
* |
|
6
|
|
|
* @package Arcanedev\EmbedVideo\Parsers |
|
7
|
|
|
* @author ARCANEDEV <[email protected]> |
|
8
|
|
|
*/ |
|
9
|
|
|
class YoutubeParser extends AbstractParser |
|
10
|
|
|
{ |
|
11
|
|
|
/* ----------------------------------------------------------------- |
|
12
|
|
|
| Properties |
|
13
|
|
|
| ----------------------------------------------------------------- |
|
14
|
|
|
*/ |
|
15
|
|
|
/** |
|
16
|
|
|
* The parser's URL patterns. |
|
17
|
|
|
* |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $patterns = [ |
|
21
|
|
|
'^(https?://)?(?:www\.)?youtu\.be/([0-9a-zA-Z-_]{11})?(?:(?:\S+)?(?:\?|&)t=([0-9hm]+s))?(?:\S+)?', |
|
22
|
|
|
'^(https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com/(?:embed/|v/|watch\?v=|watch\?.+&v=))((?:\w|-){11})(?:(?:\S+)?(?:\?|&)t=([0-9hm]+s))?(?:\S+)?$' |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Timestamp pattern and param. |
|
27
|
|
|
* |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $timestamp = [ |
|
31
|
|
|
'pattern' => '^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com/)(?:\S+)?(?:(?:\S+)?(?:\?|&)t=(?:([0-9]+)h)?(?:([0-9]+)m)?(?:([0-9]+)s)?)$', |
|
32
|
|
|
'param' => 'start', |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
/* ----------------------------------------------------------------- |
|
36
|
|
|
| Getters & Setters |
|
37
|
|
|
| ----------------------------------------------------------------- |
|
38
|
|
|
*/ |
|
39
|
|
|
/** |
|
40
|
|
|
* Get the video id from cached matches. |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
21 |
|
public function videoId() |
|
45
|
|
|
{ |
|
46
|
21 |
|
return $this->getCached(2); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get the default URL queries. |
|
51
|
|
|
* |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
30 |
|
protected function defaultQueries() |
|
55
|
|
|
{ |
|
56
|
|
|
return [ |
|
57
|
30 |
|
'rel' => 0, |
|
58
|
10 |
|
'wmode' => 'transparent', |
|
59
|
10 |
|
]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get the iframe pattern. |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
21 |
|
protected function getIframePattern() |
|
68
|
|
|
{ |
|
69
|
21 |
|
return '{protocol}://www.youtube.com/embed/{id}'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get the iframe replace. |
|
74
|
|
|
* |
|
75
|
|
|
* @return array |
|
76
|
|
|
*/ |
|
77
|
21 |
|
protected function getIframeReplacer() |
|
78
|
|
|
{ |
|
79
|
|
|
return [ |
|
80
|
21 |
|
'{protocol}' => $this->protocol, |
|
81
|
21 |
|
'{id}' => $this->videoId(), |
|
82
|
7 |
|
]; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|