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()); }
<?php if (!isset($_GET["vid"])) { exit("Nope."); } else { require 'youtube-dl.class.php'; try { $mytube = new yt_downloader(); $mytube->set_youtube($_GET["vid"]); # YouTube URL (or ID) of the video to download. $mytube->set_video_quality(1); # Change default output video file quality. $mytube->set_thumb_size('s'); # Change default video preview image size. $download = $mytube->download_video(); if ($download == 0 || $download == 1) { $video = $mytube->get_video(); if ($download == 0) { print "<h2><code>{$video}</code><br>succesfully downloaded into your Downloads Folder.</h2>"; } else { if ($download == 1) { print "<h2><code>{$video}</code><br>already exists in your your Downloads Folder.</h2>"; } } $filestats = $mytube->video_stats(); if ($filestats !== FALSE) { print "<h3>File statistics for <code>{$video}</code></h3>"; print "Filesize: " . $filestats["size"] . "<br>"; print "Created: " . $filestats["created"] . "<br>"; print "Last modified: " . $filestats["modified"] . "<br>"; }
<?php require 'youtube-dl.class.php'; try { $mytube = new yt_downloader("http://www.youtube.com/watch?v=px17OLxdDMU", TRUE, "audio"); $audio = $mytube->get_audio(); $path_dl = $mytube->get_downloads_dir(); clearstatcache(); if ($audio !== FALSE && file_exists($path_dl . $audio) !== FALSE) { print "<a href='" . $path_dl . $audio . "' target='_blank'>Click, to open downloaded audio file.</a>"; } else { print "Oups. Something went wrong."; } $log = $mytube->get_ffmpeg_Logfile(); if ($log !== FALSE) { print "<br><a href='" . $log . "' target='_blank'>Click, to view the Ffmpeg file.</a>"; } } catch (Exception $e) { die($e->getMessage()); }