Skip to content

Commit

Permalink
Store video details from player requests for local history #991
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Dec 7, 2024
1 parent e08554c commit 014ba14
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
21 changes: 20 additions & 1 deletion resources/lib/youtube_plugin/youtube/helper/stream_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions resources/lib/youtube_plugin/youtube/helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down
7 changes: 5 additions & 2 deletions resources/lib/youtube_plugin/youtube/helper/yt_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/youtube_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit 014ba14

Please sign in to comment.