diff options
author | James Taylor <user234683@users.noreply.github.com> | 2020-02-01 15:09:37 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2020-02-01 15:09:37 -0800 |
commit | 7c2736aa26cb1700297c9fcd6e6ffa5516243a92 (patch) | |
tree | fd7fe697484ade8a86eeeecdec04a282d3e77aaa /youtube/util.py | |
parent | e364927f8374577c3ecaf7ccb365382aa525f913 (diff) | |
download | yt-local-7c2736aa26cb1700297c9fcd6e6ffa5516243a92.tar.lz yt-local-7c2736aa26cb1700297c9fcd6e6ffa5516243a92.tar.xz yt-local-7c2736aa26cb1700297c9fcd6e6ffa5516243a92.zip |
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.
Diffstat (limited to 'youtube/util.py')
-rw-r--r-- | youtube/util.py | 8 |
1 files changed, 8 insertions, 0 deletions
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' |