public function downloadVideo($videoLink, $fileName) { require 'youtube-dl.class.php'; $downloadDir = realpath(sprintf('%s/../data/downloads/', APPLICATION_PATH)); $ffmpegLogsDir = realpath(sprintf('%s/../data/logs/', APPLICATION_PATH)); $youtubeDownloader = new yt_downloader($videoLink['video_link']); $youtubeDownloader->set_downloads_dir($downloadDir . DIRECTORY_SEPARATOR); $youtubeDownloader->set_ffmpegLogs_dir($ffmpegLogsDir . DIRECTORY_SEPARATOR); $youtubeDownloader->set_download_thumbnail(false); $youtubeDownloader->set_video_title($fileName); // $youtubeDownloader->download_video(); exit; $youtubeDownloader->download_audio(); $audioFileName = $youtubeDownloader->get_video_title(); return sprintf('%s.mp3', $audioFileName); }
<?php require 'youtube-dl.class.php'; try { $mytube = new yt_downloader("http://www.youtube.com/watch?v=px17OLxdDMU"); $mytube->set_audio_format("wav"); # Change default audio output filetype. $mytube->set_ffmpegLogs_active(FALSE); # Disable Ffmpeg process logging. $mytube->download_audio(); } catch (Exception $e) { die($e->getMessage()); }