aboutsummaryrefslogtreecommitdiffstats
path: root/youtube
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2020-11-29 13:44:03 -0800
committerJames Taylor <user234683@users.noreply.github.com>2020-11-29 13:44:03 -0800
commitac54362f084e8a847b7a437ae6391383a317770b (patch)
tree01164466b072a12793b6284e0fc74055286a6778 /youtube
parent13fef87f69d8fd6b95d25f24398e9a347abe7229 (diff)
downloadyt-local-ac54362f084e8a847b7a437ae6391383a317770b.tar.lz
yt-local-ac54362f084e8a847b7a437ae6391383a317770b.tar.xz
yt-local-ac54362f084e8a847b7a437ae6391383a317770b.zip
fetch_url: Use time.monotonic for comptability w/ tor_mgr
Buggy exit node retry behavior due to fetch_url still using time.time() instead of the time.monotonic() used by new_identity
Diffstat (limited to 'youtube')
-rw-r--r--youtube/util.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/youtube/util.py b/youtube/util.py
index fe34d0b..8945b9f 100644
--- a/youtube/util.py
+++ b/youtube/util.py
@@ -238,17 +238,17 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None,
cookiejar_send=None, cookiejar_receive=None, use_tor=True,
debug_name=None):
while True:
- start_time = time.time()
+ start_time = time.monotonic()
response, cleanup_func = fetch_url_response(
url, headers, timeout=timeout,
cookiejar_send=cookiejar_send, cookiejar_receive=cookiejar_receive,
use_tor=use_tor)
- response_time = time.time()
+ response_time = time.monotonic()
content = response.read()
- read_finish = time.time()
+ read_finish = time.monotonic()
cleanup_func(response) # release_connection for urllib3
content = decode_content(
@@ -298,7 +298,7 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None,
def head(url, use_tor=False, report_text=None, max_redirects=10):
pool = get_pool(use_tor and settings.route_tor)
- start_time = time.time()
+ start_time = time.monotonic()
# default: Retry.DEFAULT = Retry(3)
# (in connectionpool.py in urllib3)
@@ -310,7 +310,10 @@ def head(url, use_tor=False, report_text=None, max_redirects=10):
headers = {'User-Agent': 'Python-urllib'}
response = pool.request('HEAD', url, headers=headers, retries=retries)
if report_text:
- print(report_text, ' Latency:', round(time.time() - start_time,3))
+ print(
+ report_text,
+ ' Latency:',
+ round(time.monotonic() - 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'