From 1e048c01e09fad0e3b879bffe45e4cc15a5d3b4c Mon Sep 17 00:00:00 2001 From: MoojMidge <56883549+MoojMidge@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:56:44 +1100 Subject: [PATCH] Simplify ResourceManager.get_channel_info - Remove redundant force parameter - Update logging --- .../youtube/helper/resource_manager.py | 44 ++++++++++--------- .../youtube_plugin/youtube/helper/utils.py | 1 - .../lib/youtube_plugin/youtube/provider.py | 4 +- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/resources/lib/youtube_plugin/youtube/helper/resource_manager.py b/resources/lib/youtube_plugin/youtube/helper/resource_manager.py index 387944f9e..6caa69945 100644 --- a/resources/lib/youtube_plugin/youtube/helper/resource_manager.py +++ b/resources/lib/youtube_plugin/youtube/helper/resource_manager.py @@ -15,15 +15,21 @@ class ResourceManager(object): def __init__(self, provider, context, progress_dialog=None): - self._context = context - fanart_type = context.get_param('fanart_type') - if fanart_type is None: - fanart_type = context.get_settings().fanart_selection() - self._fanart_type = fanart_type self._provider = provider + self._context = context self._progress_dialog = progress_dialog + self.new_data = {} + params = context.get_params() + + fanart_type = params.get('fanart_type') + settings = context.get_settings() + if fanart_type is None: + fanart_type = settings.fanart_selection() + self._channel_fanart = fanart_type == settings.FANART_CHANNEL + self._thumb_size = settings.get_thumbnail_size() + def context_changed(self, context): return self._context != context @@ -137,15 +143,9 @@ def get_channels(self, ids, suppress_errors=False, defer_cache=False): def get_channel_info(self, ids, - force=False, channel_data=None, suppress_errors=False, defer_cache=False): - if force: - pass - elif self._fanart_type != self._context.get_settings().FANART_CHANNEL: - return {} - context = self._context refresh = context.get_param('refresh') if not refresh and channel_data: @@ -167,7 +167,7 @@ def get_channel_info(self, if result: context.debug_log and context.log_debug( - 'ResourceManager.get_fanarts' + 'ResourceManager.get_channel_info' ' - Using cached data for channels' '\n\tChannel IDs: {ids}' .format(ids=list(result)) @@ -196,7 +196,7 @@ def get_channel_info(self, if new_data: context.debug_log and context.log_debug( - 'ResourceManager.get_fanarts' + 'ResourceManager.get_channel_info' ' - Retrieved new data for channels' '\n\tChannel IDs: {ids}' .format(ids=to_update) @@ -211,7 +211,8 @@ def get_channel_info(self, 'bannerExternalUrl', ) untitled = context.localize('untitled') - thumb_size = context.get_settings().get_thumbnail_size() + thumb_size = self._thumb_size + channel_fanart = self._channel_fanart # transform for key, item in result.items(): @@ -220,12 +221,15 @@ def get_channel_info(self, 'image': None, 'fanart': None, } - images = item.get('brandingSettings', {}).get('image', {}) - for banner in banners: - image = images.get(banner) - if image: - channel_info['fanart'] = image - break + + if channel_fanart: + images = item.get('brandingSettings', {}).get('image', {}) + for banner in banners: + image = images.get(banner) + if image: + channel_info['fanart'] = image + break + snippet = item.get('snippet') if snippet: localised_info = snippet.get('localized') or {} diff --git a/resources/lib/youtube_plugin/youtube/helper/utils.py b/resources/lib/youtube_plugin/youtube/helper/utils.py index a87c1a185..2b7099f19 100644 --- a/resources/lib/youtube_plugin/youtube/helper/utils.py +++ b/resources/lib/youtube_plugin/youtube/helper/utils.py @@ -1106,7 +1106,6 @@ def update_channel_info(provider, if channel_ids and not data: resource_manager = provider.get_resource_manager(context) data = resource_manager.get_channel_info(channel_ids, - force=True, channel_data=channel_data, suppress_errors=True) diff --git a/resources/lib/youtube_plugin/youtube/provider.py b/resources/lib/youtube_plugin/youtube/provider.py index e30a411ac..0d496a2ff 100644 --- a/resources/lib/youtube_plugin/youtube/provider.py +++ b/resources/lib/youtube_plugin/youtube/provider.py @@ -411,7 +411,7 @@ def on_channel_playlists(provider, context, re_match): resource_manager = provider.get_resource_manager(context) channel_info = resource_manager.get_channel_info( - (channel_id,), force=True + (channel_id,), ).get(channel_id) or {} playlists = resource_manager.get_related_playlists(channel_id) @@ -657,7 +657,7 @@ def on_channel(provider, context, re_match): return False channel_info = resource_manager.get_channel_info( - (channel_id,), force=True + (channel_id,), ).get(channel_id) or {} fanart = channel_info.get('fanart') or ''