aboutsummaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-06-01 23:23:18 -0700
committerJames Taylor <user234683@users.noreply.github.com>2019-06-02 02:25:39 -0700
commitaf9c4e0554c3475d959014e9e7cef78eff88afa5 (patch)
treeced7a2ccd6d0ab8e9d251dcd61bba09f3bb87074 /server.py
parent3905e7e64059b45479894ba1fdfb0ef9cef64475 (diff)
parent9f93b9429c77e631972186049fbc7518e2cf5d4b (diff)
downloadyt-local-af9c4e0554c3475d959014e9e7cef78eff88afa5.tar.lz
yt-local-af9c4e0554c3475d959014e9e7cef78eff88afa5.tar.xz
yt-local-af9c4e0554c3475d959014e9e7cef78eff88afa5.zip
Bring up to date with master
Diffstat (limited to 'server.py')
-rw-r--r--server.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/server.py b/server.py
index 17da4cc..3f400a3 100644
--- a/server.py
+++ b/server.py
@@ -2,16 +2,19 @@ from gevent import monkey
monkey.patch_all()
import gevent.socket
-from gevent.pywsgi import WSGIServer
from youtube.youtube import youtube
+from youtube import util
import http_errors
+import settings
+
+from gevent.pywsgi import WSGIServer
import urllib
+import urllib3
import socket
import socks, sockshandler
import subprocess
import re
-import settings
@@ -31,15 +34,14 @@ def proxy_site(env, start_response):
url += '?' + env['QUERY_STRING']
- req = urllib.request.Request(url, headers=headers)
- if settings.route_tor:
- opener = urllib.request.build_opener(sockshandler.SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9150))
- response = opener.open(req, timeout=10)
- else:
- response = urllib.request.urlopen(req, timeout=10)
+ content, response = util.fetch_url(url, headers, return_response=True)
+
+ headers = response.getheaders()
+ if isinstance(headers, urllib3._collections.HTTPHeaderDict):
+ headers = headers.items()
- start_response('200 OK', response.getheaders() )
- return response.read()
+ start_response('200 OK', headers )
+ return content
site_handlers = {
'youtube.com':youtube,