Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/norkunas/youtube-dl-php
A PHP wrapper for youtube-dl or yt-dlp.
https://github.com/norkunas/youtube-dl-php
php youtube-dl yt-dlp
Last synced: 5 days ago
JSON representation
A PHP wrapper for youtube-dl or yt-dlp.
- Host: GitHub
- URL: https://github.com/norkunas/youtube-dl-php
- Owner: norkunas
- License: mit
- Created: 2015-03-28T23:45:48.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-12-09T04:52:47.000Z (2 months ago)
- Last Synced: 2025-01-30T08:05:05.720Z (12 days ago)
- Topics: php, youtube-dl, yt-dlp
- Language: PHP
- Homepage:
- Size: 412 KB
- Stars: 470
- Watchers: 20
- Forks: 157
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Youtube-dl PHP
A PHP wrapper for [youtube-dl](https://github.com/ytdl-org/youtube-dl) or [yt-dlp](https://github.com/yt-dlp/yt-dlp).[![Latest Stable Version](https://poser.pugx.org/norkunas/youtube-dl-php/v/stable.svg)](https://packagist.org/packages/norkunas/youtube-dl-php)
[![Latest Unstable Version](https://poser.pugx.org/norkunas/youtube-dl-php/v/unstable.svg)](https://packagist.org/packages/norkunas/youtube-dl-php)
[![Total Downloads](https://poser.pugx.org/norkunas/youtube-dl-php/downloads)](https://packagist.org/packages/norkunas/youtube-dl-php)
![CI Status](https://github.com/norkunas/youtube-dl-php/workflows/CI/badge.svg?branch=master)
[![License](https://poser.pugx.org/norkunas/youtube-dl-php/license.svg)](https://packagist.org/packages/norkunas/youtube-dl-php)## Install
First step is to download the [youtube-dl](https://ytdl-org.github.io/youtube-dl/download.html) or [yt-dlp](https://github.com/yt-dlp/yt-dlp#installation).Second step is to install the wrapper using [Composer](http://getcomposer.org/):
```
composer require norkunas/youtube-dl-php:dev-master
```## Download video
```php
download(
Options::create()
->downloadPath('/path/to/downloads')
->url('https://www.youtube.com/watch?v=oDAw7vW7H0c')
);foreach ($collection->getVideos() as $video) {
if ($video->getError() !== null) {
echo "Error downloading video: {$video->getError()}.";
} else {
echo $video->getTitle(); // Will return Phonebloks
// $video->getFile(); // \SplFileInfo instance of downloaded file
}
}```
## Download only audio (requires ffmpeg or avconv and ffprobe or avprobe)
```php
download(
Options::create()
->downloadPath('/path/to/downloads')
->extractAudio(true)
->audioFormat('mp3')
->audioQuality('0') // best
->output('%(title)s.%(ext)s')
->url('https://www.youtube.com/watch?v=oDAw7vW7H0c')
);foreach ($collection->getVideos() as $video) {
if ($video->getError() !== null) {
echo "Error downloading video: {$video->getError()}.";
} else {
$video->getFile(); // audio file
}
}
```## Download progress
```php
onProgress(static function (?string $progressTarget, string $percentage, string $size, string $speed, string $eta, ?string $totalTime): void {
echo "Download file: $progressTarget; Percentage: $percentage; Size: $size";
if ($speed) {
echo "; Speed: $speed";
}
if ($eta) {
echo "; ETA: $eta";
}
if ($totalTime !== null) {
echo "; Downloaded in: $totalTime";
}
});
```## Custom Process Instantiation
```php
setTimeout(60);return $process;
}
}
``````php