From 7c2736aa26cb1700297c9fcd6e6ffa5516243a92 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sat, 1 Feb 2020 15:09:37 -0800 Subject: Check for 403 errors and fallback on Invidious 403 errors on the video urls happen typically when a video has copyrighted content or was livestreamed originally. They appear to not happen (or at least happen less frequently) if the Tor exit node used ipv6, however. --- youtube/util.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'youtube/util.py') diff --git a/youtube/util.py b/youtube/util.py index f209060..a5bd874 100644 --- a/youtube/util.py +++ b/youtube/util.py @@ -195,6 +195,14 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, cookieja return content, response return content +def head(url, use_tor=False, report_text=None): + pool = get_pool(use_tor and settings.route_tor) + start_time = time.time() + response = pool.request('HEAD', url) + if report_text: + print(report_text, ' Latency:', round(time.time() - start_time,3)) + return response + mobile_user_agent = 'Mozilla/5.0 (Linux; Android 7.0; Redmi Note 4 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36' mobile_ua = (('User-Agent', mobile_user_agent),) desktop_user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0' -- cgit v1.2.3