youtube-dl-php
youtube-dl-php copied to clipboard
Add support for async download
I added functionality to download youtube videos asynchronized, using react event loop and promises. Example code:
$loop = \React\EventLoop\Factory::create();
$timer = $loop->addPeriodicTimer(1, function () {
static $i = 0;
echo "Loop ".++$i."\n";
});
$loop->addTimer(1, function () use ($timer, $loop) {
$dl = new \YoutubeDl\YoutubeDl([
"extract-audio" => true,
"audio-format" => "mp3",
"audio-quality" => 0,
"output" => "%(id)s.%(ext)s"
]);
$dl->downloadAsync("URL", $loop)->then(function (\YoutubeDl\Entity\Video $video) use ($timer) {
echo "Done, ".$video->getFilename()."\n";
$timer->cancel();
}, function (Exception $e) use ($timer) {
echo get_class($e).": ".$e->getMessage()."\n";
$timer->cancel();
});
});
$loop->run();
I don't think that this should be in core because I want this lib to be lightweight :thinking:
Alright, thats fine by me, I am closing the PR. If anyone in the future is reading this, you can use this feature by using these lines in your composer.json
:
{
"require": {
"norkunas/youtube-dl-php": "dev-async",
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/jaspervdm/youtube-dl-php"
}
]
}
@jaspervdm actually we could provide this method but just adding these dependencies to the composer suggest and if people would try async method and the dependencies wouldn't be installed then we could just throw exception
Okay, I will modify the code to check for the dependencies.
I made the async functionality optional now, what do you think?
@jaspervdm are you still interested to finish this?