Athlon1600 / youtube-downloader

:tv: PHP based alternative to youtube-dl and yt-dlp. Active and frequently updated! :star:
https://unblockvideos.com/
MIT License
800 stars 316 forks source link

Question: How to force download filetype to mp4 #147

Closed inglesuniversal closed 2 years ago

inglesuniversal commented 2 years ago

I tried with two videos and got them in 3gp

How can I force to always get the mp4 version of it.

and

Is it possible to get the file in mp3?

Regards

Athlon1600 commented 2 years ago

just loop through all available formats until you find the one that's mp4:

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

foreach ($downloadOptions->getCombinedFormats() as $format) {

    if (strpos($format->mimeType, 'video/mp4') !== false) {
        echo $format->url;
        break;
    }
}

Is it possible to get the file in mp3?

I don't believe YouTube ever returns links to mp3 files... you would have to download audio-only version of whatever format they provide, and then convert it yourself using ffmpeg or something.

inglesuniversal commented 2 years ago

Got it!!!