Skip to content

Commit

Permalink
Simplify ResourceManager.get_channel_info
Browse files Browse the repository at this point in the history
- Remove redundant force parameter
- Update logging
  • Loading branch information
MoojMidge committed Dec 13, 2024
1 parent c4fe9d0 commit 1e048c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
44 changes: 24 additions & 20 deletions resources/lib/youtube_plugin/youtube/helper/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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():
Expand All @@ -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 {}
Expand Down
1 change: 0 additions & 1 deletion resources/lib/youtube_plugin/youtube/helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions resources/lib/youtube_plugin/youtube/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 ''

Expand Down

0 comments on commit 1e048c0

Please sign in to comment.