diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-01-04 03:33:07 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-01-04 03:33:07 -0800 |
commit | ec2fb71a3701379246e3b9210cce25aa3f548fcc (patch) | |
tree | fe1b69c51fae5ffaada65312939c0d20d9a297a3 /youtube/youtube.py | |
parent | ea0705a98d69343e0b3a81168dee3d68a711550f (diff) | |
download | yt-local-ec2fb71a3701379246e3b9210cce25aa3f548fcc.tar.lz yt-local-ec2fb71a3701379246e3b9210cce25aa3f548fcc.tar.xz yt-local-ec2fb71a3701379246e3b9210cce25aa3f548fcc.zip |
WSGI for search
Diffstat (limited to 'youtube/youtube.py')
-rw-r--r-- | youtube/youtube.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/youtube/youtube.py b/youtube/youtube.py index c4a0e5b..44f9e3d 100644 --- a/youtube/youtube.py +++ b/youtube/youtube.py @@ -8,18 +8,31 @@ YOUTUBE_FILES = ( '/comments.css', '/favicon.ico', ) - +page_handlers = { + 'search': search.get_search_page, + '': search.get_search_page, +} def youtube(env, start_response): path, method, query_string = env['PATH_INFO'], env['REQUEST_METHOD'], env['QUERY_STRING'] + env['qs_fields'] = urllib.parse.parse_qs(query_string) + env['fields'] = dict(env['qs_fields']) + + path_parts = path.rstrip('/').lstrip('/').split('/') + env['path_parts'] = path_parts + if method == "GET": + try: + handler = page_handlers[path_parts[0]] + except KeyError: + pass + else: + return handler(env, start_response) + if path in YOUTUBE_FILES: with open("youtube" + path, 'rb') as f: mime_type = mimetypes.guess_type(path)[0] or 'application/octet-stream' start_response('200 OK', (('Content-type',mime_type),) ) return f.read() - elif path.lstrip('/') == "": - start_response('200 OK', (('Content-type','text/html'),) ) - return search.get_search_page(query_string).encode() elif path == "/comments": start_response('200 OK', (('Content-type','text/html'),) ) @@ -33,10 +46,6 @@ def youtube(env, start_response): start_response('200 OK', (('Content-type','text/html'),) ) return watch.get_watch_page(query_string).encode() - elif path == "/search": - start_response('200 OK', (('Content-type','text/html'),) ) - return search.get_search_page(query_string).encode() - elif path == "/playlist": start_response('200 OK', (('Content-type','text/html'),) ) return playlist.get_playlist_page(query_string).encode() @@ -95,7 +104,10 @@ def youtube(env, start_response): return channel.get_channel_page_general_url(path, query_string=query_string).encode() elif method == "POST": - fields = urllib.parse.parse_qs(env['wsgi.input'].read().decode()) + post_fields = urllib.parse.parse_qs(env['wsgi.input'].read().decode()) + env['post_fields'] = post_fields + env['fields'].update(post_fields) + fields = post_fields if path == "/edit_playlist": if fields['action'][0] == 'add': local_playlist.add_to_playlist(fields['playlist_name'][0], fields['video_info_list']) |