Completed
Push — master ( 561193...f1a784 )
by ARCANEDEV
02:56
created

YoutubeParser::getInfoUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
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
     * Timestamp pattern and param.
17
     *
18
     * @var array
19
     */
20
    protected $timestamp = [
21
        'pattern' => '^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com/)(?:\S+)?(?:(?:\S+)?(?:\?|&)t=(?:([0-9]+)h)?(?:([0-9]+)m)?(?:([0-9]+)s)?)$',
22
        'param'   => 'start',
23
    ];
24
25
    /* -----------------------------------------------------------------
26
     |  Getters & Setters
27
     | -----------------------------------------------------------------
28
     */
29
    /**
30
     * Get the video id from cached matches.
31
     *
32
     * @return string
33
     */
34 30
    public function videoId()
35
    {
36 30
        return $this->getCached(2);
37
    }
38
39
    /**
40
     * Get the default URL queries.
41
     *
42
     * @return array
43
     */
44 42
    protected function defaultQueries()
45
    {
46
        return [
47 42
            'rel'   => 0,
48 14
            'wmode' => 'transparent',
49 14
        ];
50
    }
51
52
    /**
53
     * Get the iframe pattern.
54
     *
55
     * @return string
56
     */
57 24
    protected function getIframePattern()
58
    {
59 24
        return '{protocol}://www.youtube.com/embed/{id}';
60
    }
61
62
    /**
63
     * Get the iframe replace.
64
     *
65
     * @return array
66
     */
67 24
    protected function getIframeReplacer()
68
    {
69
        return [
70 24
            '{protocol}' => $this->protocol,
71 24
            '{id}'       => $this->videoId(),
72 8
        ];
73
    }
74
75
    /**
76
     * Get the info URL.
77
     *
78
     * @return string
79
     */
80 3
    public function getInfoUrl()
81
    {
82 3
        return $this->protocol.'://youtu.be/'.$this->videoId();
83
    }
84
}
85