mirror of
https://github.com/anxdpanic/plugin.video.youtube.git
synced 2025-12-06 02:30:50 -08:00
Improve handling of plugin actions that refresh current listing
This commit is contained in:
parent
2d33aba160
commit
39acf37006
7 changed files with 68 additions and 83 deletions
|
|
@ -46,6 +46,7 @@ class AbstractProvider(object):
|
|||
CACHE_TO_DISC = 'provider_cache_to_disc' # type: bool
|
||||
FALLBACK = 'provider_fallback' # type: bool | str
|
||||
FORCE_PLAY = 'provider_force_play' # type: bool
|
||||
FORCE_REFRESH = 'provider_force_refresh' # type: bool
|
||||
FORCE_RESOLVE = 'provider_force_resolve' # type: bool
|
||||
FORCE_RETURN = 'provider_force_return' # type: bool
|
||||
POST_RUN = 'provider_post_run' # type: bool
|
||||
|
|
@ -429,12 +430,10 @@ class AbstractProvider(object):
|
|||
return False, None
|
||||
|
||||
search_history.del_item(query)
|
||||
ui.refresh_container()
|
||||
|
||||
ui.show_notification(localize('removed.name.x', query),
|
||||
time_ms=2500,
|
||||
audible=False)
|
||||
return True, None
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
if command == 'rename':
|
||||
query = to_unicode(params.get('q', ''))
|
||||
|
|
@ -446,8 +445,7 @@ class AbstractProvider(object):
|
|||
|
||||
search_history.del_item(query)
|
||||
search_history.add_item(new_query)
|
||||
ui.refresh_container()
|
||||
return True, None
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
if command == 'clear':
|
||||
if not ui.on_yes_no_input(
|
||||
|
|
@ -457,12 +455,10 @@ class AbstractProvider(object):
|
|||
return False, None
|
||||
|
||||
search_history.clear()
|
||||
ui.refresh_container()
|
||||
|
||||
ui.show_notification(localize('completed'),
|
||||
time_ms=2500,
|
||||
audible=False)
|
||||
return True, None
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
if command == 'links':
|
||||
return provider.on_specials_x(
|
||||
|
|
|
|||
|
|
@ -371,6 +371,8 @@ class XbmcPlugin(AbstractPlugin):
|
|||
succeeded=False,
|
||||
listitem=item,
|
||||
)
|
||||
elif options.get(provider.FORCE_REFRESH):
|
||||
_post_run_action = ui.refresh_container
|
||||
else:
|
||||
if context.is_plugin_path(
|
||||
ui.get_container_info(FOLDER_URI, container_id=None)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ SIGN_IN = 'in'
|
|||
SIGN_OUT = 'out'
|
||||
|
||||
|
||||
def _do_logout(provider, context, client=None, refresh=True, **kwargs):
|
||||
def _do_logout(provider, context, client=None, **kwargs):
|
||||
ui = context.get_ui()
|
||||
if not context.get_param('confirmed') and not ui.on_yes_no_input(
|
||||
context.localize('sign.out'),
|
||||
|
|
@ -46,8 +46,6 @@ def _do_logout(provider, context, client=None, refresh=True, **kwargs):
|
|||
access_manager.update_access_token(
|
||||
addon_id, access_token='', expiry=-1, refresh_token='',
|
||||
)
|
||||
if refresh:
|
||||
context.get_ui().refresh_container()
|
||||
return success
|
||||
|
||||
|
||||
|
|
@ -178,27 +176,27 @@ def _do_login(provider, context, client=None, **kwargs):
|
|||
**kwargs
|
||||
)
|
||||
access_manager.update_access_token(addon_id, *zip(*token_types))
|
||||
ui.refresh_container()
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def process(mode, provider, context, client=None, refresh=True, **kwargs):
|
||||
if mode == SIGN_OUT:
|
||||
return _do_logout(
|
||||
signed_out = _do_logout(
|
||||
provider,
|
||||
context,
|
||||
client=client,
|
||||
refresh=refresh,
|
||||
**kwargs
|
||||
)
|
||||
return signed_out, {provider.FORCE_REFRESH: refresh}
|
||||
|
||||
if mode == SIGN_IN:
|
||||
return _do_login(
|
||||
signed_in = _do_login(
|
||||
provider,
|
||||
context,
|
||||
client=client,
|
||||
**kwargs
|
||||
)
|
||||
return signed_in, {provider.FORCE_REFRESH: refresh and signed_in}
|
||||
|
||||
return None
|
||||
return None, None
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ def _process_remove_playlist(provider, context):
|
|||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return False
|
||||
return False, None
|
||||
|
||||
ui.show_notification(
|
||||
message=localize('removed.name.x', playlist_name),
|
||||
|
|
@ -204,8 +204,9 @@ def _process_remove_playlist(provider, context):
|
|||
if channel_id:
|
||||
data_cache = context.get_data_cache()
|
||||
data_cache.del_item(channel_id)
|
||||
ui.refresh_container()
|
||||
return False
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
return False, None
|
||||
|
||||
|
||||
def _process_select_playlist(provider, context):
|
||||
|
|
@ -350,7 +351,7 @@ def _process_rename_playlist(provider, context):
|
|||
default=params.get('item_name', li_playlist_name),
|
||||
)
|
||||
if not result or not text:
|
||||
return False
|
||||
return False, None
|
||||
|
||||
success = provider.get_client(context).rename_playlist(
|
||||
playlist_id=playlist_id, new_title=text,
|
||||
|
|
@ -361,7 +362,7 @@ def _process_rename_playlist(provider, context):
|
|||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return False
|
||||
return False, None
|
||||
|
||||
ui.show_notification(
|
||||
message=localize('succeeded'),
|
||||
|
|
@ -371,8 +372,7 @@ def _process_rename_playlist(provider, context):
|
|||
|
||||
data_cache = context.get_data_cache()
|
||||
data_cache.del_item(playlist_id)
|
||||
ui.refresh_container()
|
||||
return False
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
|
||||
def _playlist_id_change(context, playlist, command):
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ def _process_add(_provider, context, client):
|
|||
return True
|
||||
|
||||
|
||||
def _process_remove(_provider, context, client):
|
||||
def _process_remove(provider, context, client):
|
||||
ui = context.get_ui()
|
||||
li_subscription_id = ui.get_listitem_property(SUBSCRIPTION_ID)
|
||||
li_channel_id = ui.get_listitem_property(CHANNEL_ID)
|
||||
|
|
@ -80,15 +80,14 @@ def _process_remove(_provider, context, client):
|
|||
success = False
|
||||
|
||||
if not success:
|
||||
return False
|
||||
return False, None
|
||||
|
||||
ui.refresh_container()
|
||||
ui.show_notification(
|
||||
context.localize('unsubscribed.from.channel'),
|
||||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return True
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
|
||||
def process(provider, context, re_match):
|
||||
|
|
|
|||
|
|
@ -70,16 +70,11 @@ def _process_rate_video(provider,
|
|||
else:
|
||||
result = -1
|
||||
|
||||
notify_message = None
|
||||
response = None
|
||||
if result != -1:
|
||||
notify_message = ''
|
||||
|
||||
response = provider.get_client(context).rate_video(video_id, result)
|
||||
|
||||
if response:
|
||||
# this will be set if we are in the 'Liked Video' playlist
|
||||
if context.refresh_requested():
|
||||
ui.refresh_container()
|
||||
|
||||
if result == 'none':
|
||||
notify_message = localize(('removed.x', 'rating'))
|
||||
elif result == 'like':
|
||||
|
|
@ -96,7 +91,13 @@ def _process_rate_video(provider,
|
|||
audible=False,
|
||||
)
|
||||
|
||||
return True
|
||||
return (
|
||||
True,
|
||||
{
|
||||
# this will be set if we are in the 'Liked Video' playlist
|
||||
provider.FORCE_REFRESH: response and context.refresh_requested(),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _process_more_for_video(context):
|
||||
|
|
|
|||
|
|
@ -1222,10 +1222,9 @@ class Provider(AbstractProvider):
|
|||
context.get_name(), localize('reset.access_manager.check')
|
||||
):
|
||||
access_manager = context.get_access_manager()
|
||||
success = (
|
||||
yt_login.process(yt_login.SIGN_OUT, provider, context)
|
||||
and access_manager.set_defaults(reset=True)
|
||||
)
|
||||
success, _ = yt_login.process(yt_login.SIGN_OUT, provider, context)
|
||||
if success:
|
||||
success = access_manager.set_defaults(reset=True)
|
||||
ui.show_notification(localize('succeeded' if success else 'failed'))
|
||||
else:
|
||||
success = False
|
||||
|
|
@ -1294,18 +1293,16 @@ class Provider(AbstractProvider):
|
|||
return False, {provider.FALLBACK: False}
|
||||
|
||||
playback_history.clear()
|
||||
ui.refresh_container()
|
||||
|
||||
ui.show_notification(
|
||||
localize('completed'),
|
||||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return True
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
video_id = params.get(VIDEO_ID)
|
||||
if not video_id:
|
||||
return False
|
||||
return False, None
|
||||
|
||||
if command == 'remove':
|
||||
video_name = params.get('item_name') or video_id
|
||||
|
|
@ -1317,14 +1314,12 @@ class Provider(AbstractProvider):
|
|||
return False, {provider.FALLBACK: False}
|
||||
|
||||
playback_history.del_item(video_id)
|
||||
ui.refresh_container()
|
||||
|
||||
ui.show_notification(
|
||||
localize('removed.name.x', video_name),
|
||||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return True
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
play_data = playback_history.get_item(video_id)
|
||||
if play_data:
|
||||
|
|
@ -1361,8 +1356,7 @@ class Provider(AbstractProvider):
|
|||
play_data['played_percent'] = 0
|
||||
|
||||
playback_history_method(video_id, play_data)
|
||||
ui.refresh_container()
|
||||
return True
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
@staticmethod
|
||||
def on_root(provider, context, re_match):
|
||||
|
|
@ -1946,14 +1940,12 @@ class Provider(AbstractProvider):
|
|||
return False, {provider.FALLBACK: False}
|
||||
|
||||
context.get_bookmarks_list().clear()
|
||||
ui.refresh_container()
|
||||
|
||||
ui.show_notification(
|
||||
localize('completed'),
|
||||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return True
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
item_id = params.get('item_id')
|
||||
|
||||
|
|
@ -1961,10 +1953,10 @@ class Provider(AbstractProvider):
|
|||
results = ui.on_keyboard_input(localize('bookmarks.edit.uri'),
|
||||
params.get('uri', ''))
|
||||
if not results[0]:
|
||||
return False
|
||||
return False, None
|
||||
item_uri = results[1]
|
||||
if not item_uri:
|
||||
return False
|
||||
return False, None
|
||||
|
||||
if item_uri.startswith(('https://', 'http://')):
|
||||
item_uri = UrlToItemConverter().process_url(
|
||||
|
|
@ -1978,12 +1970,12 @@ class Provider(AbstractProvider):
|
|||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return False
|
||||
return False, None
|
||||
|
||||
results = ui.on_keyboard_input(localize('bookmarks.edit.name'),
|
||||
params.get('item_name', item_uri))
|
||||
if not results[0]:
|
||||
return False
|
||||
return False, None
|
||||
item_name = results[1]
|
||||
|
||||
item_date_time = now()
|
||||
|
|
@ -2004,7 +1996,6 @@ class Provider(AbstractProvider):
|
|||
)
|
||||
item.bookmark_id = item_id
|
||||
context.get_bookmarks_list().add_item(item_id, repr(item))
|
||||
ui.refresh_container()
|
||||
|
||||
ui.show_notification(
|
||||
localize('updated.x', item_name)
|
||||
|
|
@ -2013,26 +2004,30 @@ class Provider(AbstractProvider):
|
|||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return True
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
if not item_id:
|
||||
return False
|
||||
return False, None
|
||||
|
||||
if command == 'add':
|
||||
item = params.get('item')
|
||||
if not item:
|
||||
return False
|
||||
return False, None
|
||||
|
||||
context.get_bookmarks_list().add_item(item_id, item)
|
||||
if context.get_path().startswith(PATHS.BOOKMARKS):
|
||||
ui.refresh_container()
|
||||
|
||||
ui.show_notification(
|
||||
localize('bookmark.created'),
|
||||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return True
|
||||
return (
|
||||
True,
|
||||
{
|
||||
provider.FORCE_REFRESH: context.get_path().startswith(
|
||||
PATHS.BOOKMARKS
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
if command == 'remove':
|
||||
bookmark_name = params.get('item_name') or localize('bookmark')
|
||||
|
|
@ -2044,16 +2039,14 @@ class Provider(AbstractProvider):
|
|||
return False, {provider.FALLBACK: False}
|
||||
|
||||
context.get_bookmarks_list().del_item(item_id)
|
||||
ui.refresh_container()
|
||||
|
||||
ui.show_notification(
|
||||
localize('removed.name.x', bookmark_name),
|
||||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return True
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
return False
|
||||
return False, None
|
||||
|
||||
@staticmethod
|
||||
def on_watch_later(provider, context, re_match):
|
||||
|
|
@ -2112,23 +2105,21 @@ class Provider(AbstractProvider):
|
|||
return False, {provider.FALLBACK: False}
|
||||
|
||||
context.get_watch_later_list().clear()
|
||||
ui.refresh_container()
|
||||
|
||||
ui.show_notification(
|
||||
localize('completed'),
|
||||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return True
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
video_id = params.get(VIDEO_ID)
|
||||
if not video_id:
|
||||
return False
|
||||
return False, None
|
||||
|
||||
if command == 'add':
|
||||
item = params.get('item')
|
||||
if not item:
|
||||
return False
|
||||
return False, None
|
||||
|
||||
context.get_watch_later_list().add_item(video_id, item)
|
||||
ui.show_notification(
|
||||
|
|
@ -2136,7 +2127,7 @@ class Provider(AbstractProvider):
|
|||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return True
|
||||
return True, None
|
||||
|
||||
if command == 'remove':
|
||||
video_name = params.get('item_name') or localize('untitled')
|
||||
|
|
@ -2148,16 +2139,14 @@ class Provider(AbstractProvider):
|
|||
return False, {provider.FALLBACK: False}
|
||||
|
||||
context.get_watch_later_list().del_item(video_id)
|
||||
ui.refresh_container()
|
||||
|
||||
ui.show_notification(
|
||||
localize('removed.name.x', video_name),
|
||||
time_ms=2500,
|
||||
audible=False,
|
||||
)
|
||||
return True
|
||||
return True, {provider.FORCE_REFRESH: True}
|
||||
|
||||
return False
|
||||
return False, None
|
||||
|
||||
def handle_exception(self, context, exception_to_handle):
|
||||
if not isinstance(exception_to_handle, (InvalidGrant, LoginException)):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue