Completed
Push — master ( 723c0e...561193 )
by ARCANEDEV
02:49
created

YoutubeParser::getIframeReplacer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
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