aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/watch.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-01-05 00:20:39 -0800
committerJames Taylor <user234683@users.noreply.github.com>2019-01-05 00:20:39 -0800
commita57fc774260f2940449880ec9b6aaf40fa2776c3 (patch)
tree5a3c1620f637d0ed9c965dc3aadb16f397471e15 /youtube/watch.py
parentec2fb71a3701379246e3b9210cce25aa3f548fcc (diff)
downloadyt-local-a57fc774260f2940449880ec9b6aaf40fa2776c3.tar.lz
yt-local-a57fc774260f2940449880ec9b6aaf40fa2776c3.tar.xz
yt-local-a57fc774260f2940449880ec9b6aaf40fa2776c3.zip
WSGI for simple non-path GET pages
Diffstat (limited to 'youtube/watch.py')
-rw-r--r--youtube/watch.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/youtube/watch.py b/youtube/watch.py
index 4051a3f..1e3e93a 100644
--- a/youtube/watch.py
+++ b/youtube/watch.py
@@ -228,18 +228,23 @@ music_list_table_row = Template('''<tr>
<td>$attribute</td>
<td>$value</td>
''')
-def get_watch_page(query_string):
- parsed_qs = urllib.parse.parse_qs(query_string)
- id = parsed_qs['v'][0]
- lc = common.default_multi_get(parsed_qs, 'lc', 0, default='')
+def get_watch_page(env, start_response):
+ video_id = env['fields']['v'][0]
+ if len(video_id) < 11:
+ start_response('404 Not Found', ())
+ return b'Incomplete video id (too short): ' + video_id.encode('ascii')
+
+ start_response('200 OK', [('Content-type','text/html'),])
+
+ lc = common.default_multi_get(env['fields'], 'lc', 0, default='')
if settings.route_tor:
proxy = 'socks5://127.0.0.1:9150/'
else:
proxy = ''
downloader = YoutubeDL(params={'youtube_include_dash_manifest':False, 'proxy':proxy})
tasks = (
- gevent.spawn(comments.video_comments, id, int(settings.default_comment_sorting), lc=lc ),
- gevent.spawn(extract_info, downloader, "https://www.youtube.com/watch?v=" + id, download=False)
+ gevent.spawn(comments.video_comments, video_id, int(settings.default_comment_sorting), lc=lc ),
+ gevent.spawn(extract_info, downloader, "https://www.youtube.com/watch?v=" + video_id, download=False)
)
gevent.joinall(tasks)
comments_html, info = tasks[0].value, tasks[1].value
@@ -256,7 +261,7 @@ def get_watch_page(query_string):
style = "",
header = common.get_header(),
page = html.escape(info),
- )
+ ).encode('utf-8')
sorted_formats = sort_formats(info)
@@ -351,4 +356,4 @@ def get_watch_page(query_string):
music_list = music_list_html,
is_unlisted = '<span class="is-unlisted">Unlisted</span>' if info['unlisted'] else '',
)
- return page \ No newline at end of file
+ return page.encode('utf-8') \ No newline at end of file