Skip to content

Commit

Permalink
Disable refresh parameter on Kodi forced refresh anxdpanic#1072
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Jan 20, 2025
1 parent ed22ed5 commit 276fa3d
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 49 deletions.
16 changes: 10 additions & 6 deletions resources/lib/youtube_plugin/kodion/abstract_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def navigate(self, context):
if new_options:
options.update(new_options)

if context.get_param('refresh'):
if context.get_param('refresh', 0) > 0:
options[self.RESULT_CACHE_TO_DISC] = True
options[self.RESULT_UPDATE_LISTING] = True

Expand Down Expand Up @@ -276,10 +276,14 @@ def reroute(self, context, path=None, params=None, uri=None):
context.log_debug('Rerouting - Fallback route not required')
return False, {self.RESULT_FALLBACK: False}

if 'refresh' in params:
container = context.get_infolabel('System.CurrentControlId')
position = context.get_infolabel('Container.CurrentItem')
params['refresh'] += 1
refresh = params.get('refresh', 0)
if refresh:
if refresh < 0:
del params['refresh']
else:
container = context.get_infolabel('System.CurrentControlId')
position = context.get_infolabel('Container.CurrentItem')
params['refresh'] = refresh + 1
elif (params == current_params
and path.rstrip('/') == current_path.rstrip('/')):
context.log_error('Rerouting - Unable to reroute to current path')
Expand Down Expand Up @@ -425,7 +429,7 @@ def on_search(provider, context, re_match):
# came from page 1 of search query by '..'/back
# user doesn't want to input on this path
old_path = context.get_infolabel('Container.FolderPath')
if (not params.get('refresh')
if (not params.get('refresh', 0) > 0
and context.is_plugin_folder()
and context.is_plugin_path(old_path,
PATHS.SEARCH,
Expand Down
19 changes: 14 additions & 5 deletions resources/lib/youtube_plugin/kodion/items/menu_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ def more_for_video(context,
'item_name': video_name,
'logged_in': logged_in,
}
if refresh:
params['refresh'] = context.get_param('refresh', 0) + 1
_refresh = context.get_param('refresh', 0)
if refresh or _refresh:
if _refresh < 0:
_refresh = -_refresh
params['refresh'] = _refresh + 1
return (
context.localize('video.more'),
context.create_uri(
Expand Down Expand Up @@ -99,11 +102,14 @@ def play_with(context, video_id):

def refresh(context):
params = context.get_params()
refresh = params.get('refresh', 0)
if refresh < 0:
refresh = -refresh
return (
context.localize('refresh'),
context.create_uri(
(PATHS.ROUTE, context.get_path(),),
dict(params, refresh=params.get('refresh', 0) + 1),
dict(params, refresh=refresh + 1),
run=True,
),
)
Expand Down Expand Up @@ -354,8 +360,11 @@ def rate_video(context, video_id, refresh=False):
params = {
'video_id': video_id,
}
if refresh:
params['refresh'] = context.get_param('refresh', 0) + 1
_refresh = context.get_param('refresh', 0)
if refresh or _refresh:
if _refresh < 0:
_refresh = -_refresh
params['refresh'] = _refresh + 1
return (
context.localize('video.rate'),
context.create_uri(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class XbmcPlugin(AbstractPlugin):
def __init__(self):
super(XbmcPlugin, self).__init__()

def run(self, provider, context, focused=None):
def run(self, provider, context, forced=None):
handle = context.get_handle()
ui = context.get_ui()

Expand Down Expand Up @@ -166,9 +166,9 @@ def run(self, provider, context, focused=None):
if ui.get_property(PLUGIN_SLEEPING):
context.wakeup(PLUGIN_WAKEUP)

if ui.pop_property(REFRESH_CONTAINER):
if ui.pop_property(REFRESH_CONTAINER) or not forced:
focused = False
elif focused:
elif forced:
focused = ui.get_property(VIDEO_ID)

if ui.pop_property(RELOAD_ACCESS_MANAGER):
Expand Down Expand Up @@ -290,7 +290,7 @@ def run(self, provider, context, focused=None):

if ui.pop_property(PLAY_FORCED):
context.set_path(PATHS.PLAY)
return self.run(provider, context, focused=focused)
return self.run(provider, context, forced=forced)

window_skip = ui.pop_property(WINDOW_SKIP)
if window_skip and handle != -1:
Expand Down
26 changes: 19 additions & 7 deletions resources/lib/youtube_plugin/kodion/plugin_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,25 @@ def run(context=_context,
context.debug_log(off=True)

current_uri = context.get_uri()
current_path = context.get_path()
current_params = context.get_params()
context.init()
new_uri = context.get_uri()

params = context.get_params().copy()
new_params = context.get_params()
new_handle = context.get_handle()

forced = (new_handle != -1
and (current_uri == new_uri
or (current_path == '/' and not current_params)))
if forced and 'refresh' in new_params:
refresh = new_params['refresh']
if refresh > 0:
new_params['refresh'] = -refresh

log_params = new_params.copy()
for key in ('api_key', 'client_id', 'client_secret'):
if key in params:
params[key] = '<redacted>'
if key in log_params:
log_params[key] = '<redacted>'

system_version = context.get_system_version()
context.log_notice('Plugin: Running v{version}'
Expand All @@ -62,11 +74,11 @@ def run(context=_context,
.format(version=context.get_version(),
kodi=str(system_version),
python=system_version.get_python_version(),
handle=context.get_handle(),
handle=new_handle,
path=context.get_path(),
params=params))
params=log_params))

plugin.run(provider, context, focused=(current_uri == new_uri))
plugin.run(provider, context, forced=forced)

if debug:
profiler.print_stats()
10 changes: 5 additions & 5 deletions resources/lib/youtube_plugin/youtube/helper/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_channels(self, ids, suppress_errors=False, defer_cache=False):
client = self._provider.get_client(context)
data_cache = context.get_data_cache()
function_cache = context.get_function_cache()
refresh = context.get_param('refresh')
refresh = context.get_param('refresh', 0) > 0
updated = []
handles = {}
for identifier in ids:
Expand Down Expand Up @@ -152,7 +152,7 @@ def get_channel_info(self,
suppress_errors=False,
defer_cache=False):
context = self._context
refresh = context.get_param('refresh')
refresh = context.get_param('refresh', 0) > 0
if not refresh and channel_data:
result = channel_data
else:
Expand Down Expand Up @@ -250,7 +250,7 @@ def get_channel_info(self,
def get_playlists(self, ids, suppress_errors=False, defer_cache=False):
context = self._context
ids = tuple(ids)
refresh = context.get_param('refresh')
refresh = context.get_param('refresh', 0) > 0
if refresh or not ids:
result = {}
else:
Expand Down Expand Up @@ -316,7 +316,7 @@ def get_playlist_items(self, ids=None, batch_id=None, defer_cache=False):
return None

context = self._context
refresh = context.get_param('refresh')
refresh = context.get_param('refresh', 0) > 0

if batch_id:
ids = [batch_id[0]]
Expand Down Expand Up @@ -451,7 +451,7 @@ def get_videos(self,
yt_items=None):
context = self._context
ids = tuple(ids)
refresh = context.get_param('refresh')
refresh = context.get_param('refresh', 0) > 0
if refresh or not ids:
result = {}
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def resolve(self, url):
resolved_url = function_cache.run(
self._resolve,
function_cache.ONE_DAY,
_refresh=self._context.get_param('refresh'),
_refresh=self._context.get_param('refresh', 0) > 0,
url=url
)
if not resolved_url or resolved_url == '/':
Expand Down
7 changes: 5 additions & 2 deletions resources/lib/youtube_plugin/youtube/helper/yt_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ def _process_remove_video(provider,
if playlist_id in container_uri:
uri = container_uri
path = None
params = {'refresh': params.get('refresh', 0) + 1}
refresh = params.get('refresh', 0)
if refresh < 0:
refresh = -refresh
params = {'refresh': refresh + 1}
else:
path = params.pop('reload_path', False if confirmed else None)
uri = None
Expand Down Expand Up @@ -224,7 +227,7 @@ def _process_select_playlist(provider, context):
current_page += 1
json_data = function_cache.run(client.get_playlists_of_channel,
function_cache.ONE_MINUTE // 3,
_refresh=params.get('refresh'),
_refresh=params.get('refresh', 0) > 0,
channel_id='mine',
page_token=page_token)
if not json_data:
Expand Down
29 changes: 17 additions & 12 deletions resources/lib/youtube_plugin/youtube/helper/yt_specials.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _process_related_videos(provider, context, client):

params = context.get_params()
video_id = params.get('video_id')
refresh = params.get('refresh')
refresh = params.get('refresh', 0) > 0
if video_id:
json_data = function_cache.run(
client.get_related_videos,
Expand Down Expand Up @@ -84,7 +84,7 @@ def _process_recommendations(provider, context, client):
json_data = function_cache.run(
client.get_recommended_for_home,
function_cache.ONE_HOUR,
_refresh=params.get('refresh'),
_refresh=params.get('refresh', 0) > 0,
visitor=params.get('visitor'),
page_token=params.get('page_token'),
click_tracking=params.get('click_tracking'),
Expand All @@ -100,7 +100,7 @@ def filler(json_data, remaining):
json_data = function_cache.run(
client.get_recommended_for_home,
function_cache.ONE_HOUR,
_refresh=params.get('refresh'),
_refresh=params.get('refresh', 0) > 0,
visitor=json_data.get('visitorData'),
page_token=page_token,
click_tracking=json_data.get('clickTracking'),
Expand Down Expand Up @@ -141,14 +141,17 @@ def filler(json_data, _remaining):
def _process_browse_channels(provider, context, client):
context.set_content(CONTENT.LIST_CONTENT)

guide_id = context.get_param('guide_id', '')
params = context.get_params()
guide_id = params.get('guide_id')
if guide_id:
json_data = client.get_guide_category(guide_id)
else:
function_cache = context.get_function_cache()
json_data = function_cache.run(client.get_guide_categories,
function_cache.ONE_MONTH,
_refresh=context.get_param('refresh'))
json_data = function_cache.run(
client.get_guide_categories,
function_cache.ONE_MONTH,
_refresh=params.get('refresh', 0) > 0,
)

if not json_data:
return False
Expand Down Expand Up @@ -210,10 +213,12 @@ def _extract_urls(video_id):
description = strip_html_from_text(snippet['description'])

function_cache = context.get_function_cache()
urls = function_cache.run(utils.extract_urls,
function_cache.ONE_DAY,
_refresh=params.get('refresh'),
text=description)
urls = function_cache.run(
utils.extract_urls,
function_cache.ONE_DAY,
_refresh=params.get('refresh', 0) > 0,
text=description,
)

progress_dialog.set_total(len(urls))

Expand Down Expand Up @@ -330,7 +335,7 @@ def _process_my_subscriptions(provider, context, client, filtered=False):

logged_in = provider.is_logged_in()
params = context.get_params()
refresh = params.get('refresh')
refresh = params.get('refresh', 0) > 0

with context.get_ui().create_progress_dialog(
heading=context.localize('my_subscriptions.loading'),
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/youtube_plugin/youtube/helper/yt_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _process_rate_video(provider,

if response:
# this will be set if we are in the 'Liked Video' playlist
if context.get_param('refresh'):
if context.get_param('refresh', 0) > 0:
context.get_ui().refresh_container()

if result == 'none':
Expand Down Expand Up @@ -107,7 +107,7 @@ def _process_more_for_video(context):
menu_items.related_videos(context, video_id),
menu_items.video_comments(context, video_id, params.get('item_name')),
menu_items.content_from_description(context, video_id),
menu_items.rate_video(context, video_id, params.get('refresh')),
menu_items.rate_video(context, video_id),
] if params.get('logged_in') else [
menu_items.related_videos(context, video_id),
menu_items.video_comments(context, video_id, params.get('item_name')),
Expand Down
12 changes: 7 additions & 5 deletions resources/lib/youtube_plugin/youtube/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,12 @@ def on_channel(provider, context, re_match):
context.log_debug('Trying to get channel ID for |{0}|'.format(
identifier['identifier']
))
json_data = function_cache.run(client.get_channel_by_identifier,
function_cache.ONE_DAY,
_refresh=params.get('refresh'),
**identifier)
json_data = function_cache.run(
client.get_channel_by_identifier,
function_cache.ONE_DAY,
_refresh=params.get('refresh', 0) > 0,
**identifier
)
if not json_data:
return False

Expand Down Expand Up @@ -949,7 +951,7 @@ def on_search_run(self, context, query=None):
search_params, json_data = function_cache.run(
self.get_client(context).search_with_params,
function_cache.ONE_MINUTE * 10,
_refresh=params.get('refresh'),
_refresh=params.get('refresh', 0) > 0,
params=search_params,
)
if not json_data:
Expand Down

0 comments on commit 276fa3d

Please sign in to comment.