2017 © Pedro Peláez
 

library youtube-dl-php

youtube-dl wrapper for php

image

norkunas/youtube-dl-php

youtube-dl wrapper for php

  • Friday, January 12, 2018
  • by norkunas
  • Repository
  • 7 Watchers
  • 95 Stars
  • 11,215 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 38 Forks
  • 17 Open issues
  • 19 Versions
  • 22 % Grown

The README.md

Youtube-dl PHP

A PHP wrapper for youtube-dl or yt-dlp., (*1)

Latest Stable Version Latest Unstable Version Total Downloads CI Status License, (*2)

Install

First step is to download the youtube-dl or yt-dlp., (*3)

Second step is to install the wrapper using Composer:, (*4)

composer require norkunas/youtube-dl-php:dev-master

Download video

<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use YoutubeDl\Options;
use YoutubeDl\YoutubeDl;

$yt = new YoutubeDl();

$collection = $yt->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

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use YoutubeDl\Options;
use YoutubeDl\YoutubeDl;

$yt = new YoutubeDl();
$collection = $yt->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

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use YoutubeDl\YoutubeDl;

$yt = new YoutubeDl();
$yt->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

declare(strict_types=1);

namespace App\YoutubeDl;

use Symfony\Component\Process\Process;
use YoutubeDl\Process\ProcessBuilderInterface;

class ProcessBuilder implements ProcessBuilderInterface
{
    public function build(?string $binPath, ?string $pythonPath, array $arguments = []): Process
    {
        $process = new Process([$binPath, $pythonPath, ...$arguments]);
        // Set custom timeout or customize other things..
        $process->setTimeout(60);

        return $process;
    }
}
<?php

declare(strict_types=1);

use App\YoutubeDl\ProcessBuilder;
use YoutubeDl\YoutubeDl;

$processBuilder = new ProcessBuilder();

// Provide your custom process builder as the first argument.
$yt = new YoutubeDl($processBuilder);

Questions?

If you have any questions please open a discussion., (*5)

License

This library is released under the MIT License. See the bundled LICENSE file for details., (*6)

The Versions

12/01 2018

dev-master

9999999-dev

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

12/01 2018

v1.0.3

1.0.3.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

11/01 2018

v1.0.2

1.0.2.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

29/11 2017

v1.0.1

1.0.1.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

28/11 2017

v1.0

1.0.0.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

12/10 2017

0.x-dev

0.9999999.9999999.9999999-dev

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

12/10 2017

v0.3.5

0.3.5.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

22/09 2017

v0.3.4

0.3.4.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

18/03 2017

v0.3.3

0.3.3.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

27/02 2017

v0.3.2

0.3.2.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

10/11 2016

v0.3.1

0.3.1.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

08/09 2016

v0.3.0

0.3.0.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

14/01 2016

v0.2.3

0.2.3.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

07/01 2016

v0.2.2

0.2.2.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

13/10 2015

v0.2.1

0.2.1.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

11/10 2015

v0.2.0

0.2.0.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

youtube youtube-dl

16/07 2015

v0.1.3

0.1.3.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas

youtube youtube-dl

28/05 2015

v0.1.2

0.1.2.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas

youtube youtube-dl

04/04 2015

v0.1

0.1.0.0

youtube-dl wrapper for php

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas

youtube youtube-dl