Completed
Pull Request — master (#2)
by Luca
01:50
created

YoutubeDownloader::getFormats()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 11
rs 10
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
    const VIDEO_TYPE = 'youtube';
12
13
    /** @var array $options */
14
    protected $options;
15
    /** @var string $youtubeVideoURL */
16
    protected $youtubeVideoURL;
17
18
    public function getURL() : string
19
    {
20
        $this->youtubeVideoURL = 'https://www.youtube.com/watch?v=' . $this->getVideoId();
21
22
        $yt = new \YouTube\YouTubeDownloader();
23
        $links = $yt->getDownloadLinks($this->youtubeVideoURL);
24
25
        $videoFilter = new VideoResultFilter();
26
        $videoFilter->setValidator(new CUrlValidator());
27
        $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

27
        $formatVideos = $videoFilter->filter(/** @scrutinizer ignore-type */ $links, $this->getFormats());
Loading history...
28
29
        $formatVideos = $this->filterByFormats($formatVideos);
30
31
        return array_values($formatVideos)[0];
32
    }
33
}
34