Passed
Push — master ( cf4d2d...b4a1f8 )
by Luca
03:56 queued 02:11
created

YoutubeDownloader::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jackal\Downloader\Ext\Youtube\Downloader;
4
5
use Jackal\Downloader\Downloader\AbstractDownloader;
6
use Jackal\Downloader\Ext\Youtube\Filter\VideoResultFilter;
7
use Jackal\Downloader\Ext\Youtube\Validator\CUrlValidator;
8
9
class YoutubeDownloader extends AbstractDownloader
10
{
11
    /** @var array $options */
12
    protected $options;
13
14
    /** @var string $youtubeVideoURL */
15
    protected $youtubeVideoURL;
16
17
    public function getURL() : string
18
    {
19
        $this->youtubeVideoURL = 'https://www.youtube.com/watch?v=' . $this->getVideoId();
20
21
        $yt = new \YouTube\YouTubeDownloader();
22
        $links = $yt->getDownloadLinks($this->youtubeVideoURL);
23
24
        $videoFilter = new VideoResultFilter();
25
        $videoFilter->setValidator(new CUrlValidator());
26
        $formatVideos = $videoFilter->filter($links, $this->getFormats());
0 ignored issues
show
Bug introduced by
It seems like $links can also be of type null; however, parameter $videos of Jackal\Downloader\Ext\Yo...oResultFilter::filter() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        $formatVideos = $videoFilter->filter(/** @scrutinizer ignore-type */ $links, $this->getFormats());
Loading history...
27
28
        $formatVideos = $this->filterByFormats($formatVideos);
29
30
        return array_values($formatVideos)[0];
31
    }
32
33
    public static function getPublicUrlRegex(): string
34
    {
35
        return '/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i';
36
    }
37
38
    public static function getType(): string
39
    {
40
        return 'youtube';
41
    }
42
}
43