aboutsummaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-06-16 16:16:03 -0700
committerJames Taylor <user234683@users.noreply.github.com>2019-06-16 16:16:03 -0700
commit2db58930a6f8c955c4d437657bd07e2939a705f2 (patch)
treeb1d388bd4adc1d3134d255cd0c4d8746d7b2468b /server.py
parent9f93b9429c77e631972186049fbc7518e2cf5d4b (diff)
downloadyt-local-2db58930a6f8c955c4d437657bd07e2939a705f2.tar.lz
yt-local-2db58930a6f8c955c4d437657bd07e2939a705f2.tar.xz
yt-local-2db58930a6f8c955c4d437657bd07e2939a705f2.zip
Convert watch page to flask framework
Diffstat (limited to 'server.py')
-rw-r--r--server.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/server.py b/server.py
index 3f400a3..917be79 100644
--- a/server.py
+++ b/server.py
@@ -2,9 +2,12 @@ from gevent import monkey
monkey.patch_all()
import gevent.socket
-from youtube.youtube import youtube
+from youtube import yt_app
from youtube import util
-import http_errors
+
+# these are just so the files get run - they import yt_app and add routes to it
+from youtube import watch
+
import settings
from gevent.pywsgi import WSGIServer
@@ -22,7 +25,7 @@ def youtu_be(env, start_response):
id = env['PATH_INFO'][1:]
env['PATH_INFO'] = '/watch'
env['QUERY_STRING'] = 'v=' + id
- return youtube(env, start_response)
+ yield from yt_app(env, start_response)
def proxy_site(env, start_response):
headers = {
@@ -41,10 +44,10 @@ def proxy_site(env, start_response):
headers = headers.items()
start_response('200 OK', headers )
- return content
+ yield content
site_handlers = {
- 'youtube.com':youtube,
+ 'youtube.com':yt_app,
'youtu.be':youtu_be,
'ytimg.com': proxy_site,
'yt3.ggpht.com': proxy_site,
@@ -96,12 +99,12 @@ def site_dispatch(env, start_response):
except KeyError:
continue
else:
- yield handler(env, start_response)
+ yield from handler(env, start_response)
break
else: # did not break
yield error_code('404 Not Found', start_response)
return
-
+ '''
except http_errors.Code200 as e: # Raised in scenarios where a simple status message is to be returned, such as a terminated channel
start_response('200 OK', ())
yield str(e).encode('utf-8')
@@ -118,7 +121,7 @@ def site_dispatch(env, start_response):
start_response('502 Bad Gateway', ())
print(str(e))
yield b'502 Bad Gateway'
-
+ '''
except Exception:
start_response('500 Internal Server Error', ())
yield b'500 Internal Server Error'