aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--youtube/util.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/youtube/util.py b/youtube/util.py
index 701d922..f8c4be5 100644
--- a/youtube/util.py
+++ b/youtube/util.py
@@ -292,6 +292,15 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None,
content,
response.getheader('Content-Encoding', default='identity'))
+ if (settings.debugging_save_responses
+ and debug_name is not None and content):
+ save_dir = os.path.join(settings.data_dir, 'debug')
+ if not os.path.exists(save_dir):
+ os.makedirs(save_dir)
+
+ with open(os.path.join(save_dir, debug_name), 'wb') as f:
+ f.write(content)
+
if response.status == 429:
ip = re.search(
br'IP address: ((?:[\da-f]*:)+[\da-f]+|(?:\d+\.)+\d+)',
@@ -321,14 +330,6 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None,
if report_text:
print(report_text, ' Latency:', round(response_time - start_time, 3), ' Read time:', round(read_finish - response_time,3))
- if settings.debugging_save_responses and debug_name is not None:
- save_dir = os.path.join(settings.data_dir, 'debug')
- if not os.path.exists(save_dir):
- os.makedirs(save_dir)
-
- with open(os.path.join(save_dir, debug_name), 'wb') as f:
- f.write(content)
-
return content