mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-23 13:36:35 +00:00
More stringent checking of types
This commit is contained in:
parent
cfec876796
commit
8bff3b6c24
@ -205,20 +205,26 @@ def normalize_codec(codec_str):
|
|||||||
|
|
||||||
def _url_keys(arg_dict, filter_func):
|
def _url_keys(arg_dict, filter_func):
|
||||||
result = {}
|
result = {}
|
||||||
for key in arg_dict.keys():
|
if isinstance(arg_dict, dict):
|
||||||
if 'url' in key:
|
for key, value in arg_dict.items():
|
||||||
result.update(
|
if 'url' in key:
|
||||||
{key: filter_func(key=key, url=arg_dict[key])}
|
result.update(
|
||||||
)
|
{key: filter_func(key=key, url=value)}
|
||||||
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _drop_url_keys(arg_dict, key, filter_func):
|
def _drop_url_keys(arg_dict, key, filter_func):
|
||||||
|
assert isinstance(arg_dict, dict)
|
||||||
if key in arg_dict.keys():
|
if key in arg_dict.keys():
|
||||||
for val_dict in arg_dict[key]:
|
key_list = arg_dict[key]
|
||||||
for url_key, remove in _url_keys(val_dict, filter_func).items():
|
assert isinstance(key_list, list)
|
||||||
if remove is True:
|
if isinstance(key_list, list):
|
||||||
del val_dict[url_key]
|
for val_dict in key_list:
|
||||||
|
assert isinstance(val_dict, dict)
|
||||||
|
for url_key, remove in _url_keys(val_dict, filter_func).items():
|
||||||
|
if remove is True:
|
||||||
|
del val_dict[url_key]
|
||||||
|
|
||||||
|
|
||||||
def filter_response(arg_dict, copy_arg=False):
|
def filter_response(arg_dict, copy_arg=False):
|
||||||
@ -260,13 +266,16 @@ def filter_response(arg_dict, copy_arg=False):
|
|||||||
'__needs_testing',
|
'__needs_testing',
|
||||||
'__working',
|
'__working',
|
||||||
))
|
))
|
||||||
for key in frozenset(('formats', 'requested_formats',)):
|
for key in ('formats', 'requested_formats',):
|
||||||
_drop_url_keys(response_dict, key, drop_format_url)
|
|
||||||
if key in response_dict.keys():
|
if key in response_dict.keys():
|
||||||
for format in response_dict[key]:
|
_drop_url_keys(response_dict, key, drop_format_url)
|
||||||
for drop_key in drop_keys:
|
formats = response_dict[key]
|
||||||
if drop_key in format.keys():
|
assert isinstance(formats, list)
|
||||||
del format[drop_key]
|
if isinstance(formats, list):
|
||||||
|
for format in formats:
|
||||||
|
for drop_key in drop_keys:
|
||||||
|
if drop_key in format.keys():
|
||||||
|
del format[drop_key]
|
||||||
# end of formats cleanup }}}
|
# end of formats cleanup }}}
|
||||||
|
|
||||||
# beginning of subtitles cleanup {{{
|
# beginning of subtitles cleanup {{{
|
||||||
@ -282,19 +291,17 @@ def filter_response(arg_dict, copy_arg=False):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for key in frozenset(('subtitles', 'automatic_captions',)):
|
for key in ('subtitles', 'requested_subtitles', 'automatic_captions',):
|
||||||
if key in response_dict.keys():
|
if key in response_dict.keys():
|
||||||
key_dict = response_dict[key]
|
lang_codes = response_dict[key]
|
||||||
for lang_code in key_dict:
|
assert isinstance(lang_codes, dict)
|
||||||
_drop_url_keys(key_dict, lang_code, drop_subtitles_url)
|
if isinstance(lang_codes, dict):
|
||||||
|
for lang_code in lang_codes.keys():
|
||||||
for key in frozenset(('requested_subtitles',)):
|
_drop_url_keys(lang_codes, lang_code, drop_subtitles_url)
|
||||||
if key in response_dict.keys():
|
|
||||||
_drop_url_keys(response_dict, key, drop_subtitles_url)
|
|
||||||
# end of subtitles cleanup }}}
|
# end of subtitles cleanup }}}
|
||||||
|
|
||||||
# beginning of heatmap cleanup {{{
|
# beginning of heatmap cleanup {{{
|
||||||
for key in frozenset(('heatmap',)):
|
for key in ('heatmap',):
|
||||||
if key in response_dict.keys():
|
if key in response_dict.keys():
|
||||||
del response_dict[key]
|
del response_dict[key]
|
||||||
# end of heatmap cleanup }}}
|
# end of heatmap cleanup }}}
|
||||||
|
Loading…
Reference in New Issue
Block a user