youtube-downloader icon indicating copy to clipboard operation
youtube-downloader copied to clipboard

getFirstCombinedFormat()->url returns only audio

Open AgentSmith0 opened this issue 2 years ago • 3 comments

The following example code only returns an audio URL:

use YouTube\YouTubeDownloader;
use YouTube\Exception\YouTubeException;

$youtube = new YouTubeDownloader();

try {
    $downloadOptions = $youtube->getDownloadLinks("https://www.youtube.com/watch?v=aqz-KE-bpKQ");

    if ($downloadOptions->getAllFormats()) {
        echo $downloadOptions->getFirstCombinedFormat()->url;
    } else {
        echo 'No links found';
    }

} catch (YouTubeException $e) {
    echo 'Something went wrong: ' . $e->getMessage();
}

This problem also occurs in the demo: https://youtube-downloader-v3.herokuapp.com/

AgentSmith0 avatar Oct 16 '21 14:10 AgentSmith0

This is happening for me too. I've tried about a dozen different videos and getFirstCombinedFormat() only returns links to audio only.

Kryd0s avatar Nov 04 '21 01:11 Kryd0s

I overrided the function getCombinedFormats() in DownloadOptions.php to:

public function getCombinedFormats()
    {
        return Utils::arrayFilterReset($this->getAllFormats(), function ($format) {
            return strpos($format->mimeType, 'video') === 0 && !empty($format->audioQuality) && $format->quality === 'hd720';
        });
    }

... and now is working!

danpalmieri avatar Nov 04 '21 12:11 danpalmieri

Thank you very much, that works! Please also create a PR for that.

AgentSmith0 avatar Nov 04 '21 14:11 AgentSmith0