aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/common.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2018-12-26 17:24:53 -0800
committerJames Taylor <user234683@users.noreply.github.com>2018-12-26 17:24:53 -0800
commit6a23df8c90cd3def49f83a68b501f785eefc6b37 (patch)
tree4e6eabc8fb964fc6fccf4947d8b5bbe9766debaa /youtube/common.py
parentb321b5fc6484c38d861530e6b89405b062e32459 (diff)
downloadyt-local-6a23df8c90cd3def49f83a68b501f785eefc6b37.tar.lz
yt-local-6a23df8c90cd3def49f83a68b501f785eefc6b37.tar.xz
yt-local-6a23df8c90cd3def49f83a68b501f785eefc6b37.zip
Don't use tor when logging in
Diffstat (limited to 'youtube/common.py')
-rw-r--r--youtube/common.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/youtube/common.py b/youtube/common.py
index 655f24c..6b0051b 100644
--- a/youtube/common.py
+++ b/youtube/common.py
@@ -1,5 +1,6 @@
from youtube.template import Template
from youtube import local_playlist
+import settings
import html
import json
import re
@@ -7,7 +8,7 @@ import urllib.parse
import gzip
import brotli
import time
-
+import socks, sockshandler
URL_ORIGIN = "/https://www.youtube.com"
@@ -148,7 +149,7 @@ def decode_content(content, encoding_header):
content = gzip.decompress(content)
return content
-def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, cookie_jar_send=None, cookie_jar_receive=None):
+def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, cookie_jar_send=None, cookie_jar_receive=None, use_tor=True):
'''
When cookie_jar_send is set to a CookieJar object,
those cookies will be sent in the request (but cookies in response will not be merged into it)
@@ -168,10 +169,16 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, cookie_j
start_time = time.time()
+
req = urllib.request.Request(url, data=data, headers=headers)
if cookie_jar_send is not None:
cookie_jar_send.add_cookie_header(req)
- response = urllib.request.urlopen(req, timeout=timeout)
+
+ if use_tor and settings.route_tor:
+ opener = urllib.request.build_opener(sockshandler.SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9150))
+ response = opener.open(req, timeout=timeout)
+ else:
+ response = urllib.request.urlopen(req, timeout=timeout)
response_time = time.time()
if cookie_jar_receive is not None: