PHP code example of masih / youtubedownloader
1. Go to this page and download the library: Download masih/youtubedownloader 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/ */
masih / youtubedownloader example snippets
// ...
$youtube->setPath('/path/to/folder'); // without trailing slash
Masih\YoutubeDownloader\YoutubeDownloader;
$youtube = new YoutubeDownloader('gmFn62dr0D8');
$result = $youtube->getInfo();
header('Content-type: application/json');
print json_encode($result);
set_time_limit(0); // Downloading a video may take a lot time
ubeDownloader('gmFn62dr0D8');
$youtube->download();
$youtube = new YoutubeDownloader('PLbjM1u8Yb9I0rK4hkPa9TWe4N_idJOnrJ');
$youtube->onProgress = function ($downloadedBytes, $fileSize, $index, $count) {
if ($count > 1) echo '[' . $index . ' of ' . $count . ' videos] ';
if ($fileSize > 0)
echo "\r" . 'Downloaded ' . $downloadedBytes . ' of ' . $fileSize . ' bytes [%' . number_format($downloadedBytes * 100 / $fileSize, 2) . '].';
else
echo "\r" . 'Downloading...'; // File size is unknown, so just keep downloading
};
$youtube->download();
$youtube = new YoutubeDownloader('PLbjM1u8Yb9I0rK4hkPa9TWe4N_idJOnrJ');
$youtube->onComplete = function ($filePath, $fileSize, $index, $count) {
if ($count > 1) echo '[' . $index . ' of ' . $count . ' videos] ';
echo 'Downloading of ' . $fileSize . ' bytes has been completed. It is saved in ' . $filePath . PHP_EOL;
};
$youtube->download();
$youtube = new YoutubeDownloader('PLbjM1u8Yb9I0rK4hkPa9TWe4N_idJOnrJ');
$youtube->onFinalized = function ($filePath, $fileSize, $index, $count) {
if ($count > 1) echo '[' . $index . ' of ' . $count . ' videos] ';
echo $filePath . ' Finalized' . PHP_EOL;
};
$youtube->download();
$youtube = new YoutubeDownloader('PLbjM1u8Yb9I0rK4hkPa9TWe4N_idJOnrJ');
$this->sanitizeFileName = function ($fileName) use ($youtube) {
return str_replace('_', ' ', $youtube->pathSafeFilename($fileName));
};
$youtube->download();
$youtube = new YoutubeDownloader('gmFn62dr0D8');
$youtube->enableMp4Editing(true);
composer global