PHP code example of mail2bapi / youtube-downloader
1. Go to this page and download the library: Download mail2bapi/youtube-downloader library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mail2bapi / youtube-downloader example snippets
use Mail2bapi\YouTubeDownloader\YoutubeDownloader;
// Yourtube URL
$yourtubeVideoUrl = '<youtube.com video URL>';
// New YoutubeDownloader instance
$yt = new YoutubeDownloader();
// Enabling logging
$yt->setLogging(true);
// Setting location for saving videos and thumbnails. By default is saves in directory 'videos/'
$yt->setDownloadFolder('<my/location>');
// Collect Video ID from URL
$videoId = $yt->getVideoId($yourtubeVideoUrl);
// Get Video details of a Yourtube video
$videos = $yt->getVideoDetail($yourtubeVideoUrl);
// $videos array have following keys
// 'video_id', 'channel_id', 'duration', 'title', 'description', 'keywords', 'average_rating', 'allow_ratings', 'view_count', 'author', 'video', 'embed_video', 'adaptive_formats', 'formats', 'thumbnails'
// Get array of all video qualities
$videoQualities = $yt->getVideoQualities();
// Download all Thumbnail images
$yt->downloadThumbnails($videos);
// Download all videos as per video qualities available for the video
$yt->downloadVideo();
// Download single videos as per video qualities available for the video
$yt->downloadAVideo($videos['formats']['360p']['link'], $videos['video_id'], $videoQualities[0]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.