diff --git a/app/routes.py b/app/routes.py index 034fa4a..a1f802a 100644 --- a/app/routes.py +++ b/app/routes.py @@ -464,7 +464,8 @@ def get_live_urls(urls): def watch(): id = request.args.get('v', None) info = ytwatch.extract_info(id, False, playlist_id=None, index=None) - + if info == 'Captcha': + return render_template('captcha.html', origin=request.referrer) retry = 3 while retry != 0 and info['playability_error'] == 'Could not find player': info=ytwatch.extract_info(id, False, playlist_id=None, index=None) diff --git a/app/templates/captcha.html b/app/templates/captcha.html new file mode 100644 index 0000000..9466bbb --- /dev/null +++ b/app/templates/captcha.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} +{% block content %} + +
+
+ +
+
+ Ahh... Here we go again! +
+

Google is asking to solve a Captcha. As we don't want you to do it, we'll do it for you.

+

Try again in a few seconds.

+ Click here to reload +
+
+
+ +{%endblock%} \ No newline at end of file diff --git a/youtube/util.py b/youtube/util.py index 5049aba..f980d38 100644 --- a/youtube/util.py +++ b/youtube/util.py @@ -200,6 +200,7 @@ def fetch_url_response(url, headers=(), timeout=15, data=None, # If there's a captcha, bypass it. if string_de in response.text or string_en in response.text: bypass_captcha(session, response, url) + return "Captcha", "Captcha" if max_redirects: retries = urllib3.Retry(3 + max_redirects, redirect=max_redirects) @@ -226,8 +227,10 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, cookiejar_send=cookiejar_send, cookiejar_receive=cookiejar_receive, use_tor=use_tor) print(response) - response_time = time.time() + if response == "Captcha": + return "Captcha" + response_time = time.time() content = response.read() read_finish = time.time() cleanup_func(response) # release_connection for urllib3 diff --git a/youtube/watch.py b/youtube/watch.py index 2867744..f87a066 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -171,6 +171,11 @@ def extract_info(video_id, use_invidious, playlist_id=None, index=None): if index: url += '&index=' + index polymer_json = util.fetch_url(url, headers=headers, debug_name='watch') + + # If there's a captcha... Return word Captcha + if polymer_json == 'Captcha': + return 'Captcha' + polymer_json = polymer_json.decode('utf-8') # TODO: Decide whether this should be done in yt_data_extract.extract_watch_info try: