-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for async download #38
base: master
Are you sure you want to change the base?
Conversation
I don't think that this should be in core because I want this lib to be lightweight 🤔 |
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 {
"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? |
@@ -116,6 +122,77 @@ public function download(string $url): Video | |||
return $this->processDownload($process); | |||
} | |||
|
|||
public function downloadAsync(string $url, LoopInterface $loop): PromiseInterface | |||
{ | |||
if (!class_exists('LoopInterface')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use LoopInterface::class
throw new \RuntimeException('React event loop package not installed.'); | ||
} | ||
|
||
if (!class_exists('Deferred')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Deferred::class
throw new UrlNotSupportedException(sprintf('Provided url "%s" is not supported.', $url)); | ||
} | ||
|
||
$arguments = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe would be nice to make a private helper to share download process building?
@jaspervdm are you still interested to finish this? |
I added functionality to download youtube videos asynchronized, using react event loop and promises. Example code: