Skip to content

Commit

Permalink
Fixed trackid keyerrors
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Oct 8, 2022
1 parent c71196b commit c031116
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion resources/lib/kodi/context_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def generate_context_menu_items(videoid, is_in_mylist, perpetual_range_start=Non
videoid.mediatype in [common.VideoId.MOVIE, common.VideoId.SHOW]):
items.insert(0, _ctx_item('trailer', videoid))

if videoid.mediatype in [common.VideoId.MOVIE, common.VideoId.SHOW]:
if videoid.mediatype in [common.VideoId.MOVIE, common.VideoId.SHOW] and trackid is not None:
list_action = 'remove_from_list' if is_in_mylist else 'add_to_list'
items.insert(0, _ctx_item(list_action, videoid, {'perpetual_range_start': perpetual_range_start,
'trackid': trackid}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ def _create_videolist_item(list_id, video_list, menu_data, common_data, static_l
def build_video_listing(video_list, menu_data, sub_genre_id=None, pathitems=None, perpetual_range_start=None,
mylist_items=None, path_params=None):
"""Build a video listing"""
trackid = None
if hasattr(video_list, 'component_summary'):
trackid = video_list.component_summary.get('trackIds', {}).get('trackId', 'None')
common_data = get_common_data()
common_data.update({
'params': get_param_watched_status_by_profile(),
Expand All @@ -254,6 +257,7 @@ def build_video_listing(video_list, menu_data, sub_genre_id=None, pathitems=None
'ctxmenu_remove_watched_status': menu_data['path'][1] == 'continueWatching',
'active_profile_guid': G.LOCAL_DB.get_active_profile_guid(),
'marks_tvshow_started': G.ADDON.getSettingBool('marks_tvshow_started'),
'trackid': trackid
})
directory_items = [_create_video_item(videoid_value, video, video_list, perpetual_range_start, common_data)
for videoid_value, video
Expand Down Expand Up @@ -299,15 +303,14 @@ def _create_video_item(videoid_value, video, video_list, perpetual_range_start,
add_info_list_item(list_item, videoid, video, video_list.data, is_in_mylist, common_data)
if not is_folder:
set_watched_status(list_item, video, common_data)
trackid = video_list.component_summary.get('trackIds', {}).get('trackId', '')
if is_playable:
# The movie or tvshow (episodes) is playable
url = common.build_url(videoid=videoid,
mode=G.MODE_DIRECTORY if is_folder else G.MODE_PLAY,
params=None if is_folder else common_data['params'])
list_item.addContextMenuItems(generate_context_menu_items(videoid, is_in_mylist, perpetual_range_start,
common_data['ctxmenu_remove_watched_status'],
trackid))
common_data['trackid']))
else:
# The movie or tvshow (episodes) is not available
# Try check if there is a availability date
Expand All @@ -320,7 +323,7 @@ def _create_video_item(videoid_value, video, video_list, perpetual_range_start,
except CacheMiss:
# The website check the "Remind Me" value on key "inRemindMeList" and also "queue"/"inQueue"
is_in_remind_me = video['inRemindMeList']['value'] or video['queue']['value']['inQueue']
list_item.addContextMenuItems(generate_context_menu_remind_me(videoid, is_in_remind_me, trackid))
list_item.addContextMenuItems(generate_context_menu_remind_me(videoid, is_in_remind_me, common_data['trackid']))
url = common.build_url(['show_availability_message'], videoid=videoid, mode=G.MODE_ACTION)
return url, list_item, is_folder and is_playable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def req_video_list_sorted(self, context_name, context_id=None, perpetual_range_s
_base_path.append(RANGE_PLACEHOLDER)
if not menu_data.get('query_without_reference', False):
_base_path.append('reference')
paths = build_paths(_base_path, VIDEO_LIST_PARTIAL_PATHS)
paths = (build_paths(_base_path, VIDEO_LIST_PARTIAL_PATHS) +
[base_path[:-1] + [['id', 'name', 'requestId', 'trackIds']]])

path_response = self.nfsession.perpetual_path_request(paths, [response_type, base_path], perpetual_range_start)
return VideoListSorted(path_response, context_name, context_id, req_sort_order_type)
Expand Down Expand Up @@ -244,7 +245,8 @@ def req_datatype_video_list_full(self, context_name, switch_profiles=False):
contains only minimal video info
"""
LOG.debug('Requesting the full video list for {}', context_name)
paths = build_paths([context_name, 'az', RANGE_PLACEHOLDER], VIDEO_LIST_BASIC_PARTIAL_PATHS)
paths = (build_paths([context_name, 'az', RANGE_PLACEHOLDER], VIDEO_LIST_BASIC_PARTIAL_PATHS) +
[[context_name, ['id', 'name', 'requestId', 'trackIds']]])
call_args = {
'paths': paths,
'length_params': ['stdlist', [context_name, 'az']],
Expand Down
6 changes: 3 additions & 3 deletions resources/lib/utils/api_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def rate_thumb(videoid, rating, track_id_jaw):

def update_remindme(operation, videoid, trackid):
"""Call API to add / remove "Remind Me" to not available videos"""
if not trackid:
raise Exception('Unable update remind me, trackid not found.')
if trackid == 'None':
raise Exception('Unable update my list, trackid not found.')
response = common.make_call(
'post_safe',
{'endpoint': 'playlistop',
Expand All @@ -128,7 +128,7 @@ def update_remindme(operation, videoid, trackid):
@measure_exec_time_decorator()
def update_my_list(videoid, operation, params):
"""Call API to add / remove videos to my list"""
if not params['trackid']:
if params['trackid'] == 'None':
raise Exception('Unable update my list, trackid not found.')
LOG.debug('My List: {} {}', operation, videoid)
response = common.make_call(
Expand Down
8 changes: 6 additions & 2 deletions resources/lib/utils/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ def __init__(self, path_response, context_name, context_id, req_sort_order_type)
self.videoids = []
self.component_summary = {}
if has_data:
self.data_lists = path_response[context_name][context_id][req_sort_order_type] \
if context_id else path_response[context_name][req_sort_order_type]
if context_id:
self.data_lists = path_response[context_name][context_id][req_sort_order_type]
self.component_summary = {'trackIds': self.data[context_name][context_id]['trackIds'].get('value', {})}
else:
self.data_lists = path_response[context_name][req_sort_order_type]
self.component_summary = {'trackIds': self.data[context_name]['trackIds'].get('value', {})}
self.videos = OrderedDict(resolve_refs(self.data_lists, self.data))
if self.videos:
# self.artitem = next(self.videos.values())
Expand Down

0 comments on commit c031116

Please sign in to comment.