From bb2d40ac83f222678ed5b4265355b9f146f2ba3e Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sun, 6 Jan 2019 01:33:52 -0800 Subject: rename env['fields'] to env['parameters'] and rename fields to parameters in general --- youtube/accounts.py | 8 ++++---- youtube/channel.py | 2 +- youtube/comments.py | 2 +- youtube/local_playlist.py | 12 ++++++------ youtube/playlist.py | 2 +- youtube/post_comment.py | 14 +++++++------- youtube/search.py | 22 +++++++++++----------- youtube/watch.py | 4 ++-- youtube/youtube.py | 11 +++++------ 9 files changed, 38 insertions(+), 39 deletions(-) (limited to 'youtube') diff --git a/youtube/accounts.py b/youtube/accounts.py index 6edfa97..458703a 100644 --- a/youtube/accounts.py +++ b/youtube/accounts.py @@ -52,18 +52,18 @@ def _add_account(username, password, save, use_tor): return False def add_account(env, start_response): - fields = env['fields'] - if 'save' in fields and fields['save'][0] == "on": + parameters = env['parameters'] + if 'save' in parameters and parameters['save'][0] == "on": save_account = True else: save_account = False - if 'use_tor' in fields and fields['use_tor'][0] == "on": + if 'use_tor' in parameters and parameters['use_tor'][0] == "on": use_tor = True else: use_tor = False - if _add_account(fields['username'][0], fields['password'][0], save_account, use_tor ): + if _add_account(parameters['username'][0], parameters['password'][0], save_account, use_tor ): start_response('200 OK', () ) return b'Account successfully added' else: diff --git a/youtube/channel.py b/youtube/channel.py index d4a1d47..087c13c 100644 --- a/youtube/channel.py +++ b/youtube/channel.py @@ -367,7 +367,7 @@ def get_channel_page(env, start_response): except IndexError: tab = 'videos' - parameters = env['fields'] + parameters = env['parameters'] page_number = int(common.default_multi_get(parameters, 'page', 0, default='1')) sort = common.default_multi_get(parameters, 'sort', 0, default='3') view = common.default_multi_get(parameters, 'view', 0, default='1') diff --git a/youtube/comments.py b/youtube/comments.py index 4860636..5181ee8 100644 --- a/youtube/comments.py +++ b/youtube/comments.py @@ -358,7 +358,7 @@ $options ''') def get_comments_page(env, start_response): start_response('200 OK', [('Content-type','text/html'),] ) - parameters = env['fields'] + parameters = env['parameters'] ctoken = default_multi_get(parameters, 'ctoken', 0, default='') replies = False if not ctoken: diff --git a/youtube/local_playlist.py b/youtube/local_playlist.py index 4d85a1f..f25e826 100644 --- a/youtube/local_playlist.py +++ b/youtube/local_playlist.py @@ -147,10 +147,10 @@ def get_playlist_page(env, start_response): def path_edit_playlist(env, start_response): '''Called when making changes to the playlist from that playlist's page''' - fields = env['fields'] - if fields['action'][0] == 'remove': + parameters = env['parameters'] + if parameters['action'][0] == 'remove': playlist_name = env['path_parts'][1] - remove_from_playlist(playlist_name, fields['video_info_list']) + remove_from_playlist(playlist_name, parameters['video_info_list']) start_response('303 See Other', [('Location', common.URL_ORIGIN + env['PATH_INFO']),] ) return b'' @@ -160,9 +160,9 @@ def path_edit_playlist(env, start_response): def edit_playlist(env, start_response): '''Called when adding videos to a playlist from elsewhere''' - fields = env['fields'] - if fields['action'][0] == 'add': - add_to_playlist(fields['playlist_name'][0], fields['video_info_list']) + parameters = env['parameters'] + if parameters['action'][0] == 'add': + add_to_playlist(parameters['playlist_name'][0], parameters['video_info_list']) start_response('204 No Content', ()) else: start_response('400 Bad Request', ()) diff --git a/youtube/playlist.py b/youtube/playlist.py index 9e3eb4b..fbb0322 100644 --- a/youtube/playlist.py +++ b/youtube/playlist.py @@ -80,7 +80,7 @@ playlist_stat_template = Template('''
$stat
''') def get_playlist_page(env, start_response): start_response('200 OK', [('Content-type','text/html'),]) - parameters = env['fields'] + parameters = env['parameters'] playlist_id = parameters['list'][0] page = parameters.get("page", "1")[0] if page == "1": diff --git a/youtube/post_comment.py b/youtube/post_comment.py index 575eaf5..f5b1fd8 100644 --- a/youtube/post_comment.py +++ b/youtube/post_comment.py @@ -110,12 +110,12 @@ def get_session_token(video_id, cookiejar): raise Exception("Couldn't find xsrf_token") def delete_comment(env, start_response): - fields = env['fields'] - video_id = fields['video_id'][0] - cookiejar = accounts.account_cookiejar(fields['channel_id'][0]) + parameters = env['parameters'] + video_id = parameters['video_id'][0] + cookiejar = accounts.account_cookiejar(parameters['channel_id'][0]) token = get_session_token(video_id, cookiejar) - code = _delete_comment(video_id, fields['comment_id'][0], fields['author_id'][0], token, cookiejar) + code = _delete_comment(video_id, parameters['comment_id'][0], parameters['author_id'][0], token, cookiejar) if code == "SUCCESS": start_response('303 See Other', [('Location', common.URL_ORIGIN + '/comment_delete_success'),] ) @@ -123,7 +123,7 @@ def delete_comment(env, start_response): start_response('303 See Other', [('Location', common.URL_ORIGIN + '/comment_delete_fail'),] ) def post_comment(env, start_response): - parameters = env['fields'] + parameters = env['parameters'] video_id = parameters['video_id'][0] channel_id = parameters['channel_id'][0] cookiejar = accounts.account_cookiejar(channel_id) @@ -141,7 +141,7 @@ def post_comment(env, start_response): def get_delete_comment_page(env, start_response): start_response('200 OK', [('Content-type','text/html'),]) - parameters = env['fields'] + parameters = env['parameters'] style = ''' main{ @@ -172,7 +172,7 @@ def get_delete_comment_page(env, start_response): def get_post_comment_page(env, start_response): start_response('200 OK', [('Content-type','text/html'),]) - parameters = env['fields'] + parameters = env['parameters'] video_id = parameters['video_id'][0] parent_id = common.default_multi_get(parameters, 'parent_id', 0, default='') diff --git a/youtube/search.py b/youtube/search.py index 2b90998..4ffa2ba 100644 --- a/youtube/search.py +++ b/youtube/search.py @@ -68,22 +68,22 @@ did_you_mean = Template(''' ''') def get_search_page(env, start_response): start_response('200 OK', [('Content-type','text/html'),]) - fields = env['fields'] - if len(fields) == 0: + parameters = env['parameters'] + if len(parameters) == 0: return common.yt_basic_template.substitute( page_title = "Search", header = common.get_header(), style = '', page = '', ).encode('utf-8') - query = fields["query"][0] - page = fields.get("page", "1")[0] - autocorrect = int(fields.get("autocorrect", "1")[0]) - sort = int(fields.get("sort", "0")[0]) + query = parameters["query"][0] + page = parameters.get("page", "1")[0] + autocorrect = int(parameters.get("autocorrect", "1")[0]) + sort = int(parameters.get("sort", "0")[0]) filters = {} - filters['time'] = int(fields.get("time", "0")[0]) - filters['type'] = int(fields.get("type", "0")[0]) - filters['duration'] = int(fields.get("duration", "0")[0]) + filters['time'] = int(parameters.get("time", "0")[0]) + filters['type'] = int(parameters.get("type", "0")[0]) + filters['duration'] = int(parameters.get("duration", "0")[0]) info = get_search_json(query, page, autocorrect, sort, filters) estimated_results = int(info[1]['response']['estimatedResults']) @@ -98,7 +98,7 @@ def get_search_page(env, start_response): continue if type == 'didYouMeanRenderer': renderer = renderer[type] - corrected_query_string = fields.copy() + corrected_query_string = parameters.copy() corrected_query_string['query'] = [renderer['correctedQueryEndpoint']['searchEndpoint']['query']] corrected_query_url = URL_ORIGIN + '/search?' + urllib.parse.urlencode(corrected_query_string, doseq=True) corrections = did_you_mean.substitute( @@ -108,7 +108,7 @@ def get_search_page(env, start_response): continue if type == 'showingResultsForRenderer': renderer = renderer[type] - no_autocorrect_query_string = fields.copy() + no_autocorrect_query_string = parameters.copy() no_autocorrect_query_string['autocorrect'] = ['0'] no_autocorrect_query_url = URL_ORIGIN + '/search?' + urllib.parse.urlencode(no_autocorrect_query_string, doseq=True) corrections = showing_results_for.substitute( diff --git a/youtube/watch.py b/youtube/watch.py index 1e3e93a..0ca3778 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -229,14 +229,14 @@ music_list_table_row = Template(''' $value ''') def get_watch_page(env, start_response): - video_id = env['fields']['v'][0] + video_id = env['parameters']['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='') + lc = common.default_multi_get(env['parameters'], 'lc', 0, default='') if settings.route_tor: proxy = 'socks5://127.0.0.1:9150/' else: diff --git a/youtube/youtube.py b/youtube/youtube.py index 57ea481..46cfdf0 100644 --- a/youtube/youtube.py +++ b/youtube/youtube.py @@ -37,8 +37,8 @@ post_handlers = { 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']) + env['qs_parameters'] = urllib.parse.parse_qs(query_string) + env['parameters'] = dict(env['qs_parameters']) path_parts = path.rstrip('/').lstrip('/').split('/') env['path_parts'] = path_parts @@ -86,10 +86,9 @@ def youtube(env, start_response): return channel.get_channel_page_general_url(env, start_response) elif method == "POST": - post_fields = urllib.parse.parse_qs(env['wsgi.input'].read().decode()) - env['post_fields'] = post_fields - env['fields'].update(post_fields) - fields = post_fields + post_parameters = urllib.parse.parse_qs(env['wsgi.input'].read().decode()) + env['post_parameters'] = post_parameters + env['parameters'].update(post_parameters) try: handler = post_handlers[path_parts[0]] -- cgit v1.2.3