def maintenance_actions(self, context, re_match):
maint_type = re_match.group('maint_type')
action = re_match.group('action')
if action == 'clear':
if maint_type == 'function_cache':
if context.get_ui().on_remove_content(context.localize(self.LOCAL_MAP['youtube.function.cache'])):
context.get_function_cache().clear()
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.succeeded']))
elif maint_type == 'search_cache':
if context.get_ui().on_remove_content(context.localize(self.LOCAL_MAP['youtube.search.history'])):
context.get_search_history().clear()
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.succeeded']))
elif action == 'reset':
if maint_type == 'access_manager':
if context.get_ui().on_yes_no_input(context.get_name(), context.localize(self.LOCAL_MAP['youtube.reset.access.manager.confirm'])):
try:
context.get_function_cache().clear()
access_manager = context.get_access_manager()
client = self.get_client(context)
if access_manager.has_refresh_token():
refresh_tokens = access_manager.get_refresh_token().split('|')
refresh_tokens = list(set(refresh_tokens))
for refresh_token in refresh_tokens:
client.revoke(refresh_token)
self.reset_client()
access_manager.update_access_token(access_token='', refresh_token='')
context.get_ui().refresh_container()
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.succeeded']))
except:
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.failed']))
elif action == 'delete':
_maint_files = {'function_cache': 'cache.sqlite',
'search_cache': 'search.sqlite',
'settings_xml': 'settings.xml'}
_file = _maint_files.get(maint_type, '')
if _file:
if 'sqlite' in _file:
_file_w_path = os.path.join(context._get_cache_path(), _file)
else:
_file_w_path = os.path.join(context._data_path, _file)
if context.get_ui().on_delete_content(_file):
success = xbmcvfs.delete(_file_w_path)
if success:
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.succeeded']))
else:
context.get_ui().show_notification(context.localize(self.LOCAL_MAP['youtube.failed']))
评论列表
文章目录