youtube-downloader
youtube-downloader copied to clipboard
getFirstCombinedFormat()->url returns only audio
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/
This is happening for me too. I've tried about a dozen different videos and getFirstCombinedFormat() only returns links to audio only.
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!
Thank you very much, that works! Please also create a PR for that.