Skip to content

Commit

Permalink
Simplify handling of local history
Browse files Browse the repository at this point in the history
- Incognito will no longer prevent existing local history from being shown
- Incognito will continue to prevent any update to local history
  • Loading branch information
MoojMidge committed Sep 21, 2024
1 parent 4f2dc2e commit 0024baa
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 45 deletions.
35 changes: 16 additions & 19 deletions resources/lib/youtube_plugin/youtube/helper/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,32 @@


def tv_videos_to_items(provider, context, json_data):
incognito = context.get_param('incognito')
settings = context.get_settings()
use_play_data = not incognito and settings.use_local_history()
item_filter = settings.item_filter()

item_params = {
'video_id': None,
}
if incognito:
if context.get_param('incognito'):
item_params['incognito'] = True

video_id_dict = {}
channel_item_dict = {}
channel_items_dict = {}

for item in json_data.get('items', []):
video_id = item['id']
item_params['video_id'] = video_id
video_item = VideoItem(
video_id_dict[video_id] = VideoItem(
item['title'], context.create_uri((PATHS.PLAY,), item_params)
)
if incognito:
video_item.set_play_count(0)
video_id_dict[video_id] = video_item

utils.update_video_infos(provider,
context,
video_id_dict,
channel_items_dict=channel_item_dict,
use_play_data=use_play_data,
item_filter=item_filter)
utils.update_fanarts(provider, context, channel_item_dict)

item_filter = context.get_settings().item_filter()

utils.update_video_infos(
provider,
context,
video_id_dict,
channel_items_dict=channel_items_dict,
item_filter=item_filter,
)
utils.update_fanarts(provider, context, channel_items_dict)

if item_filter:
result = utils.filter_videos(video_id_dict.values(), **item_filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ def get_video_items(self, provider, context, skip_title=False):
if self._video_items:
return self._video_items

use_play_data = not context.get_param('incognito', False)

channel_id_dict = {}
utils.update_video_infos(provider, context, self._video_id_dict,
channel_items_dict=channel_id_dict,
use_play_data=use_play_data)
utils.update_video_infos(
provider,
context,
self._video_id_dict,
channel_items_dict=channel_id_dict,
)
utils.update_fanarts(provider, context, channel_id_dict)

self._video_items = [
Expand Down
12 changes: 4 additions & 8 deletions resources/lib/youtube_plugin/youtube/helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from math import log10

from ...kodion.constants import CONTENT, LICENSE_TOKEN, LICENSE_URL, PATHS
from ...kodion.items import AudioItem, DirectoryItem, CommandItem, menu_items
from ...kodion.items import AudioItem, CommandItem, DirectoryItem, menu_items
from ...kodion.utils import (
datetime_parser,
friendly_number,
Expand Down Expand Up @@ -363,7 +363,6 @@ def update_video_infos(provider, context, video_id_dict,
playlist_item_id_dict=None,
channel_items_dict=None,
live_details=True,
use_play_data=True,
item_filter=None,
data=None):
video_ids = list(video_id_dict)
Expand Down Expand Up @@ -399,6 +398,7 @@ def update_video_infos(provider, context, video_id_dict,
subtitles_prompt = settings.get_subtitle_selection() == 1
thumb_size = settings.get_thumbnail_size()
thumb_stamp = get_thumb_timestamp()
use_play_data = settings.use_local_history()

channel_role = localize(19029)
untitled = localize('untitled')
Expand Down Expand Up @@ -833,13 +833,9 @@ def update_video_infos(provider, context, video_id_dict,
media_item.add_context_menu(context_menu)


def update_play_info(provider, context, video_id, media_item, video_stream,
use_play_data=True):
def update_play_info(provider, context, video_id, media_item, video_stream):
media_item.video_id = video_id
update_video_infos(provider,
context,
{video_id: media_item},
use_play_data=use_play_data)
update_video_infos(provider, context, {video_id: media_item})

settings = context.get_settings()
ui = context.get_ui()
Expand Down
10 changes: 2 additions & 8 deletions resources/lib/youtube_plugin/youtube/helper/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,13 @@ def _process_list_response(provider, context, json_data, item_filter):

new_params = {}
params = context.get_params()
incognito = params.get('incognito', False)
if incognito:
new_params['incognito'] = incognito
if params.get('incognito'):
new_params['incognito'] = True
addon_id = params.get('addon_id', '')
if addon_id:
new_params['addon_id'] = addon_id

settings = context.get_settings()
use_play_data = not incognito and settings.use_local_history()

thumb_size = settings.get_thumbnail_size()
fanart_type = params.get('fanart_type')
if fanart_type is None:
Expand Down Expand Up @@ -251,8 +248,6 @@ def _process_list_response(provider, context, json_data, item_filter):

if isinstance(item, VideoItem):
item.video_id = item_id
if incognito:
item.set_play_count(0)
# Set track number from playlist, or set to current list length to
# match "Default" (unsorted) sort order
position = snippet.get('position') or len(result)
Expand Down Expand Up @@ -289,7 +284,6 @@ def _process_list_response(provider, context, json_data, item_filter):
'upd_kwargs': {
'data': None,
'live_details': True,
'use_play_data': use_play_data,
'item_filter': item_filter,
},
'complete': False,
Expand Down
9 changes: 4 additions & 5 deletions resources/lib/youtube_plugin/youtube/helper/yt_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ def _play_stream(provider, context):

use_history = not (screensaver or incognito or stream.get('live'))
use_remote_history = use_history and settings.use_remote_history()
use_play_data = use_history and settings.use_local_history()
use_local_history = use_history and settings.use_local_history()

utils.update_play_info(provider, context, video_id, media_item,
stream, use_play_data=use_play_data)
utils.update_play_info(provider, context, video_id, media_item, stream)

seek_time = 0.0 if params.get('resume') else params.get('seek', 0.0)
start_time = params.get('start', 0.0)
Expand All @@ -146,7 +145,7 @@ def _play_stream(provider, context):
# if end_time:
# video_item.set_duration_from_seconds(end_time)

play_count = use_play_data and media_item.get_play_count() or 0
play_count = use_local_history and media_item.get_play_count() or 0
playback_stats = stream.get('playback_stats')

playback_data = {
Expand All @@ -156,7 +155,7 @@ def _play_stream(provider, context):
'playing_file': media_item.get_uri(),
'play_count': play_count,
'use_remote_history': use_remote_history,
'use_local_history': use_play_data,
'use_local_history': use_local_history,
'playback_stats': playback_stats,
'seek_time': seek_time,
'start_time': start_time,
Expand Down

0 comments on commit 0024baa

Please sign in to comment.