youtube-dl-php
youtube-dl-php copied to clipboard
Add support for WARNING messages
To test you can for example login with wrong credentials with Facebook.
...
$collection = $yt->download($options);
foreach ($collection->getVideos() as $video) {
if ($video->getWarning() !== null) {
http_response_code(415);
echo "<pre>Warning downloading video: {$video->getWarning()}</pre>";
}
if ($video->getError() !== null) {
http_response_code(415);
echo "<pre>Error downloading video: {$video->getError()}</pre>";
$success = false;
}
...
Maybe instead of collecting only single warning, collect all of them? Then we could update documentation show people that if there is an error to gather more info what's wrong they could call $video->getWarnings() :)
Also tests needs to be updated.
Maybe instead of collecting only single warning, collect all of them? Then we could update documentation show people that if there is an error to gather more info what's wrong they could call
$video->getWarnings():)Also tests needs to be updated.
I have to admit I tought of that and tried some things but that made the program crash, so I just duplicated how error works for now
What was the reason of the crash?
I'd try to always initialize warnings array so when matching line if there are warning it'd append to the array and if there would be no warnings then calling $video->getWarnings() would just return empty array :)
Also for completeness I'd create test file in tests/Fixtures/fb/1582413528636185.txt with your output:
[facebook] Downloading login page
[facebook] Logging in
WARNING: unable to log in: bad username/password, or exceeded login rate limit (~3/min). Check credentials or wait.
[facebook] 1582413528636185: Downloading webpage
ERROR: This video is only available for registered users. Use --username and --password or --netrc to provide account credentials.
And then would add test that it collect the message and outputs as $warnings = ['unable to log in: bad username/password, or exceeded login rate limit (~3/min). Check credentials or wait.']
What was the reason of the crash?
I'd try to always initialize
warningsarray so when matching line if there are warning it'd append to the array and if there would be no warnings then calling$video->getWarnings()would just return empty array :)Also for completeness I'd create test file in tests/Fixtures/fb/1582413528636185.txt with your output:
[facebook] Downloading login page [facebook] Logging in WARNING: unable to log in: bad username/password, or exceeded login rate limit (~3/min). Check credentials or wait. [facebook] 1582413528636185: Downloading webpage ERROR: This video is only available for registered users. Use --username and --password or --netrc to provide account credentials.And then would add test that it collect the message and outputs as
$warnings = ['unable to log in: bad username/password, or exceeded login rate limit (~3/min). Check credentials or wait.']
Thanks for your advices, For the tests, I have to admit i've never wrote any test, i'm sorry i can't help on that. I tried to follow what you said.
I forced $currentVideo['error'] to be empty/null, because my guess is that warnings can happen even if there's no error ; two object(YoutubeDl\Entity\Video) are then created, as such it output twice all the same warnings and go two times into the "success" else. I couldn't successfully debug this.
I'm not happy with my push, but I pushed anyway in case it could help (you) at least a little. My knowledge is limited and I don't think I can do much more.
I see. Probably we could collect all the warnings and attach to the collection and also try to collect separately for the videos. But there are cases when the warning is printed even before the download was started so it's not easy to link it to the video then. I'll think about this more and will get back to you next week with suggestions how to continue.