From 1573e0a5da4a080162f5f29e0943d4b54c547a92 Mon Sep 17 00:00:00 2001 From: MoojMidge <56883549+MoojMidge@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:26:15 +1100 Subject: [PATCH] Update display of channels Show the following details: - view count - subscriber count - video count - date - description - channel name in description - web url --- .../resource.language.en_gb/strings.po | 4 +- .../kodion/context/xbmc/xbmc_context.py | 1 + .../kodion/settings/abstract_settings.py | 2 + .../youtube_plugin/youtube/client/youtube.py | 2 +- .../youtube_plugin/youtube/helper/utils.py | 78 +++++++++++++++++-- 5 files changed, 76 insertions(+), 11 deletions(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 5fda428e8..b9b3ba928 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -1262,7 +1262,7 @@ msgid "Videos" msgstr "" msgctxt "#30739" -msgid "" +msgid "Subscribers" msgstr "" msgctxt "#30740" @@ -1482,7 +1482,7 @@ msgid "Views count display colour" msgstr "" msgctxt "#30794" -msgid "Likes count display colour" +msgid "Subscriber/Likes count display colour" msgstr "" msgctxt "#30795" diff --git a/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py b/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py index 0761fdd2a..c1023005d 100644 --- a/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py +++ b/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py @@ -213,6 +213,7 @@ class XbmcContext(AbstractContext): # 'stats.favoriteCount': 1036, 'stats.itemCount': 30737, 'stats.likeCount': 30733, + 'stats.subscriberCount': 30739, 'stats.videoCount': 30738, 'stats.viewCount': 30767, 'stream.alternate': 30747, diff --git a/resources/lib/youtube_plugin/kodion/settings/abstract_settings.py b/resources/lib/youtube_plugin/kodion/settings/abstract_settings.py index 83e62be2e..81dbc3812 100644 --- a/resources/lib/youtube_plugin/kodion/settings/abstract_settings.py +++ b/resources/lib/youtube_plugin/kodion/settings/abstract_settings.py @@ -631,6 +631,8 @@ def set_history_playlist(self, value): if current_system_version.compatible(20): _COLOR_SETTING_MAP = { 'itemCount': 'commentCount', + 'subscriberCount': 'likeCount', + 'videoCount': 'commentCount', } def get_label_color(self, label_part): diff --git a/resources/lib/youtube_plugin/youtube/client/youtube.py b/resources/lib/youtube_plugin/youtube/client/youtube.py index 48e30566f..005896c01 100644 --- a/resources/lib/youtube_plugin/youtube/client/youtube.py +++ b/resources/lib/youtube_plugin/youtube/client/youtube.py @@ -937,7 +937,7 @@ def get_channels(self, channel_id, **kwargs): if not isinstance(channel_id, string_type): channel_id = ','.join(channel_id) - params = {'part': 'snippet,contentDetails,brandingSettings'} + params = {'part': 'snippet,contentDetails,brandingSettings,statistics'} if channel_id != 'mine': params['id'] = channel_id else: diff --git a/resources/lib/youtube_plugin/youtube/helper/utils.py b/resources/lib/youtube_plugin/youtube/helper/utils.py index 421763ef1..ab3068405 100644 --- a/resources/lib/youtube_plugin/youtube/helper/utils.py +++ b/resources/lib/youtube_plugin/youtube/helper/utils.py @@ -150,10 +150,18 @@ def update_channel_infos(provider, context, channel_id_dict, if subscription_id_dict is None: subscription_id_dict = {} - settings = context.get_settings() logged_in = provider.is_logged_in() + + settings = context.get_settings() + channel_name_aliases = settings.get_channel_name_aliases() + show_details = settings.show_detailed_description() + + localize = context.localize + channel_role = localize(19029) # "Channel" + untitled = localize('untitled') + path = context.get_path() - untitled = context.localize('untitled') + ui = context.get_ui() filter_list = None if path.startswith(PATHS.SUBSCRIPTIONS): @@ -183,17 +191,71 @@ def update_channel_infos(provider, context, channel_id_dict, channel_item = channel_id_dict[channel_id] - # title + label_stats = [] + stats = [] + if 'statistics' in yt_item: + for stat, value in yt_item['statistics'].items(): + label = context.LOCAL_MAP.get('stats.' + stat) + if not label: + continue + + str_value, value = friendly_number(value, as_str=False) + if not value: + continue + + color = settings.get_label_color(stat) + label = localize(label) + if value == 1: + label = label.rstrip('s') + + label_stats.append(ui.color(color, str_value)) + stats.append(ui.color(color, ui.bold(' '.join(( + str_value, label + ))))) + + label_stats = ' | '.join(label_stats) + stats = ' | '.join(stats) + + # Used for label2, but is poorly supported in skins + channel_item.set_short_details(label_stats) + # Hack to force a custom label mask containing production code, + # activated on sort order selection, to display details + # Refer XbmcContext.set_content for usage + channel_item.set_production_code(label_stats) + + # channel name and title localised_info = snippet.get('localized') or {} - title = localised_info.get('title') or snippet.get('title') or untitled - channel_item.set_name(title) + channel_name = (localised_info.get('title') + or snippet.get('title') + or untitled) + channel_item.set_name(channel_name) + channel_item.add_artist(channel_name) + if 'cast' in channel_name_aliases: + channel_item.add_cast(channel_name, role=channel_role) + if 'studio' in channel_name_aliases: + channel_item.add_studio(channel_name) # plot description = strip_html_from_text(localised_info.get('description') or snippet.get('description') or '') + if show_details: + description = ''.join(( + ui.bold(channel_name, cr_after=1), + ui.new_line(stats, cr_after=1) if stats else '', + ui.new_line(description, cr_after=1) if description else '', + 'https://youtu.be/channel' + channel_id, + )) channel_item.set_plot(description) + # date time + published_at = snippet.get('publishedAt') + if published_at: + datetime = datetime_parser.parse(published_at) + channel_item.set_added_utc(datetime) + local_datetime = datetime_parser.utc_to_local(datetime) + channel_item.set_date_from_datetime(local_datetime) + # image image = get_thumbnail(thumb_size, snippet.get('thumbnails')) channel_item.set_image(image) @@ -221,13 +283,13 @@ def update_channel_infos(provider, context, channel_id_dict, # add/remove from filter list if in_subscription_list and filter_list is not None: - channel = title.lower().replace(',', '') + channel = channel_name.lower().replace(',', '') context_menu.append( menu_items.remove_my_subscriptions_filter( - context, title + context, channel_name ) if channel in filter_list else menu_items.add_my_subscriptions_filter( - context, title + context, channel_name ) )