From 014ba1468db365a489917ee6276fe67d03e4eb30 Mon Sep 17 00:00:00 2001 From: MoojMidge <56883549+MoojMidge@users.noreply.github.com> Date: Thu, 5 Dec 2024 20:51:56 +1100 Subject: [PATCH] Store video details from player requests for local history #991 --- .../youtube/helper/stream_info.py | 21 ++++++++++++++++++- .../youtube_plugin/youtube/helper/utils.py | 17 +++++++++++---- .../youtube_plugin/youtube/helper/yt_play.py | 7 +++++-- resources/lib/youtube_resolver.py | 2 +- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/resources/lib/youtube_plugin/youtube/helper/stream_info.py b/resources/lib/youtube_plugin/youtube/helper/stream_info.py index 590914cec..392c6c169 100644 --- a/resources/lib/youtube_plugin/youtube/helper/stream_info.py +++ b/resources/lib/youtube_plugin/youtube/helper/stream_info.py @@ -1635,6 +1635,25 @@ def load_stream_info(self, video_id): del headers['Authorization'] video_details = result.get('videoDetails', {}) + yt_item = { + 'id': video_id, + 'snippet': { + 'title': video_details.get('title'), + 'description': video_details.get('shortDescription'), + 'channelId': video_details.get('channelId'), + 'channelTitle': video_details.get('author'), + 'thumbnails': (video_details + .get('thumbnail', {}) + .get('thumbnails', [])), + }, + 'contentDetails': { + 'duration': 'P' + video_details.get('lengthSeconds', '0') + 'S', + }, + 'statistics': { + 'viewCount': video_details.get('viewCount', ''), + }, + '_partial': True, + } is_live = video_details.get('isLiveContent', False) if is_live: is_live = video_details.get('isLive', False) @@ -1871,7 +1890,7 @@ def load_stream_info(self, video_id): if not stream_list: raise YouTubeException('No streams found') - return stream_list.values() + return stream_list.values(), yt_item def _process_stream_data(self, stream_data, diff --git a/resources/lib/youtube_plugin/youtube/helper/utils.py b/resources/lib/youtube_plugin/youtube/helper/utils.py index 2d3f7314d..24cee2279 100644 --- a/resources/lib/youtube_plugin/youtube/helper/utils.py +++ b/resources/lib/youtube_plugin/youtube/helper/utils.py @@ -541,7 +541,8 @@ def update_video_items(provider, context, video_id_dict, channel_items_dict=None, live_details=True, item_filter=None, - data=None): + data=None, + yt_items=None): if not video_id_dict and not data: return @@ -550,7 +551,8 @@ def update_video_items(provider, context, video_id_dict, resource_manager = provider.get_resource_manager(context) data = resource_manager.get_videos(video_ids, live_details=live_details, - suppress_errors=True) + suppress_errors=True, + yt_items=yt_items) if not data: return @@ -1025,8 +1027,15 @@ def update_video_items(provider, context, video_id_dict, media_item.add_context_menu(context_menu) -def update_play_info(provider, context, video_id, media_item, video_stream): - update_video_items(provider, context, {video_id: media_item}) +def update_play_info(provider, + context, + video_id, + media_item, + video_stream, + yt_item=None): + update_video_items( + provider, context, {video_id: media_item}, yt_items=[yt_item] + ) settings = context.get_settings() diff --git a/resources/lib/youtube_plugin/youtube/helper/yt_play.py b/resources/lib/youtube_plugin/youtube/helper/yt_play.py index de8781da5..de3bc41a4 100644 --- a/resources/lib/youtube_plugin/youtube/helper/yt_play.py +++ b/resources/lib/youtube_plugin/youtube/helper/yt_play.py @@ -60,6 +60,7 @@ def _play_stream(provider, context): stream = { 'url': 'https://youtu.be/{0}'.format(video_id), } + yt_item = None else: ask_for_quality = settings.ask_for_video_quality() if ui.pop_property(PLAY_PROMPT_QUALITY) and not screensaver: @@ -73,7 +74,7 @@ def _play_stream(provider, context): and context.wakeup(SERVER_WAKEUP, timeout=5)) try: - streams = client.get_streams( + streams, yt_item = client.get_streams( context, video_id=video_id, ask_for_quality=ask_for_quality, @@ -141,7 +142,9 @@ def _play_stream(provider, context): use_remote_history = use_history and settings.use_remote_history() use_local_history = use_history and settings.use_local_history() - utils.update_play_info(provider, context, video_id, media_item, stream) + utils.update_play_info( + provider, context, video_id, media_item, stream, yt_item + ) seek_time = 0.0 if params.get('resume') else params.get('seek', 0.0) start_time = params.get('start', 0.0) diff --git a/resources/lib/youtube_resolver.py b/resources/lib/youtube_resolver.py index 72eb0ae43..4d936fd59 100644 --- a/resources/lib/youtube_resolver.py +++ b/resources/lib/youtube_resolver.py @@ -53,7 +53,7 @@ def resolve(video_id, sort=True, addon_id=None): break if matched_id: - streams = client.get_streams(context=context, video_id=matched_id) + streams, _ = client.get_streams(context=context, video_id=matched_id) if sort and streams: streams = sorted(streams, key=lambda x: x.get('sort', (0, 0)))