youtube-dl: Handle youtube CAPTCHAs (402 errors) gracefully

Upon encountering a 402 error, youtube-dl should:

  • By default, throw out an error (“Due to high usage, youtube requires a CAPTCHA to be solved. Specify the --captcha-solver or --captcha-interactive option to solve the CAPTCHA.”)
  • If the --captcha-solver has been specified, execute the specified program. Write the CAPTCHA image to its stdin and read its stdout. Enter the trimmed stdout as the CAPTCHA and continue downloading.
  • If the --captcha-interactive option has be been specified, download the file to a temporary location and call ['xdg-open', 'tmpfile']. If this fails, abort with an error message. Otherwise, call raw_input() and ask for a solution for the CAPTCHA.

Implementation notes:

  • This is requires an option captcha-solver. For the moment, I’m not sure whether it should be a Python callback(Fits better in a library) or a string(Allows serialization of options).
  • It will be hard to test. I can have a process downloading 24/7 from a high-bandwidth server until it encounters this problem, but there should be a nicer way to get youtube to present CAPTCHAs
  • Afterwards, update the FAQ / documentation / README.md

About this issue

  • Original URL
  • State: open
  • Created 13 years ago
  • Reactions: 7
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Hi phihag, here is the dump - http://www.grab.lv/_external/capture-libcapng

Steps made:

So basically you’d have to forcibly save cookie jar and save passed cookies (use_hitbox, goojf, I’m not sure about VISITOR_INFO1_LIVE) before and after authentication (only captcha filling should be done in a real browser), parse returned html page (goes via 302 redirect) and get iframe location. This URL should be passed to console, so user can click or copy-paste in browser. User fills the captcha in his browser, copies returned hash and pastes in youtube-dl. And again, same as step one - save cookies and afterwards - retry downloading.

Maybe you should take a look at Mechanize - http://wwwsearch.sourceforge.net/mechanize/ - unfortunately I’m not familiar with Python, but WWW::Mechanize works really well for Perl.

Just use this service https://anti-captcha.com/

Then let people submit their own login to it if they want to bypass captchas

I would suggest adding auto captcha solver from https://de-captcher.com/ or some other website because if you are using this to download vids for personal use than you won’t encounter captcha but if you are doing like making a website that downloads youtube vids, than you need a service. So a auto captcha solver service is best option.

In the docs there’s an option for that now:

–sleep-interval SECONDS

cheers everyone

What about adding OAuth 2 support so we can authorize our apps using this library against YouTube? This would solve the issue as far as I can tell.