def _create_episode_item(seasonid, episodeid_value, episode, episodes_list, common_data): is_playable = episode['summary']['isPlayable'] episodeid = seasonid.derive_episode(episodeid_value) list_item = ListItemW(label=episode['title']) list_item.setProperties({ 'isPlayable': str(is_playable).lower(), 'nf_videoid': episodeid.to_string() }) add_info_list_item(list_item, episodeid, episode, episodes_list.data, False, common_data) set_watched_status(list_item, episode, common_data) if is_playable: url = common.build_url(videoid=episodeid, mode=G.MODE_PLAY, params=common_data['params']) list_item.addContextMenuItems( generate_context_menu_items(episodeid, False, None)) else: # The video is not playable, try check if there is a date list_item.setProperty('nf_availability_message', get_availability_message(episode)) url = common.build_url(['show_availability_message'], mode=G.MODE_ACTION) return url, list_item, False
def _create_season_item(tvshowid, seasonid_value, season, season_list, common_data): seasonid = tvshowid.derive_season(seasonid_value) list_item = ListItemW(label=season['summary']['name']) list_item.setProperty('nf_videoid', seasonid.to_string()) add_info_list_item(list_item, seasonid, season, season_list.data, False, common_data, art_item=season_list.artitem) list_item.addContextMenuItems(generate_context_menu_items(seasonid, False, None)) return common.build_url(videoid=seasonid, mode=G.MODE_DIRECTORY), list_item, True
def _create_video_item(videoid_value, video, video_list, perpetual_range_start, common_data): # pylint: disable=unused-argument videoid = common.VideoId.from_videolist_item(video) is_folder = videoid.mediatype == common.VideoId.SHOW is_playable = video['availability']['isPlayable'] is_video_playable = not is_folder and is_playable is_in_mylist = videoid in common_data['mylist_items'] list_item = ListItemW(label=video['title']) list_item.setProperties({ 'isPlayable': str(is_video_playable).lower(), 'nf_videoid': videoid.to_string(), 'nf_is_in_mylist': str(is_in_mylist), 'nf_perpetual_range_start': str(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) 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'])) else: # The movie or tvshow (episodes) is not available # Try check if there is a availability date list_item.setProperty('nf_availability_message', get_availability_message(video)) # Check if the user has set "Remind Me" feature, try: # Due to the add-on cache we can not change in easy way the value stored in database cache, # then we temporary override the value (see 'remind_me' in navigation/actions.py) is_in_remind_me = G.CACHE.get(CACHE_BOOKMARKS, f'is_in_remind_me_{videoid}') except CacheMiss: # The website check the "Remind Me" value on key "inRemindMeList" and also "queue"/"inQueue" is_in_remind_me = video['inRemindMeList'] or video['queue'][ 'inQueue'] trackid = video['trackIds']['trackId_jaw'] list_item.addContextMenuItems( generate_context_menu_remind_me(videoid, is_in_remind_me, trackid)) url = common.build_url(['show_availability_message'], videoid=videoid, mode=G.MODE_ACTION) return url, list_item, is_folder and is_playable
def set_watched_status(list_item: ListItemW, video_data, common_data): """Check and set progress status (watched and resume)""" if not common_data['set_watched_status']: return video_id = str(video_data['summary']['id']) # Check from db if user has manually changed the watched status is_watched_user_overrided = G.SHARED_DB.get_watched_status( common_data['active_profile_guid'], video_id, None, bool) resume_time = 0 if is_watched_user_overrided is None: # Note to shakti properties: # 'watched': unlike the name this value is used to other purposes, so not to set a video as watched # 'watchedToEndOffset': this value is used to determine if a video is watched but # is available only with the metadata api and only for "episode" video type # 'creditsOffset' : this value is used as position where to show the (play) "Next" (episode) button # on the website, but it may not be always available with the "movie" video type if 'creditsOffset' in video_data: # To better ensure that a video is marked as watched also when a user do not reach the ending credits # we generally lower the watched threshold by 50 seconds for 50 minutes of video (3000 secs) lower_value = video_data['runtime'] / 3000 * 50 watched_threshold = video_data['creditsOffset'] - lower_value else: # When missing the value should be only a video of movie type, # then we simulate the default Kodi playcount behaviour (playcountminimumpercent) watched_threshold = video_data['runtime'] / 100 * 90 # To avoid asking to the server again the entire list of titles (after watched a video) # to get the updated value, we override the value with the value saved in memory (see am_video_events.py) try: bookmark_position = G.CACHE.get(CACHE_BOOKMARKS, video_id) except CacheMiss: # NOTE shakti 'bookmarkPosition' tag when it is not set have -1 value bookmark_position = video_data['bookmarkPosition'] playcount = '1' if bookmark_position >= watched_threshold else '0' if playcount == '0' and bookmark_position > 0: resume_time = bookmark_position else: playcount = '1' if is_watched_user_overrided else '0' # We have to set playcount with setInfo(), because the setProperty('PlayCount', ) have a bug # when a item is already watched and you force to set again watched, the override do not work list_item.updateInfo({'PlayCount': playcount}) list_item.setProperty('TotalTime', str(video_data['runtime'])) list_item.setProperty('ResumeTime', str(resume_time))
def _create_video_item(videoid_value, video, video_list, perpetual_range_start, common_data): # pylint: disable=unused-argument videoid = common.VideoId.from_videolist_item(video) is_folder = videoid.mediatype == common.VideoId.SHOW is_playable = video['availability']['isPlayable'] is_video_playable = not is_folder and is_playable is_in_mylist = videoid in common_data['mylist_items'] list_item = ListItemW(label=video['title']) list_item.setProperties({ 'isPlayable': str(is_video_playable).lower(), 'nf_videoid': videoid.to_string(), 'nf_is_in_mylist': str(is_in_mylist), 'nf_perpetual_range_start': str(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) if 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'])) else: # The video is not playable, try check if there is a date list_item.setProperty('nf_availability_message', get_availability_message(video)) url = common.build_url(['show_availability_message'], mode=G.MODE_ACTION) return url, list_item, is_folder and is_playable
def add_items_previous_next_page(directory_items, pathitems, perpetual_range_selector, sub_genre_id=None, path_params=None): if pathitems and perpetual_range_selector: if 'previous_start' in perpetual_range_selector: params = {'perpetual_range_start': perpetual_range_selector.get('previous_start'), 'sub_genre_id': sub_genre_id if perpetual_range_selector.get('previous_start') == 0 else None} if path_params: params.update(path_params) previous_page_item = ListItemW(label=common.get_local_string(30148)) previous_page_item.setProperty('specialsort', 'top') # Force an item to stay on top previous_page_item.setArt({'thumb': _get_custom_thumb_path('FolderPagePrevious.png')}) directory_items.insert(0, (common.build_url(pathitems=pathitems, params=params, mode=G.MODE_DIRECTORY), previous_page_item, True)) if 'next_start' in perpetual_range_selector: params = {'perpetual_range_start': perpetual_range_selector.get('next_start')} if path_params: params.update(path_params) next_page_item = ListItemW(label=common.get_local_string(30147)) next_page_item.setProperty('specialsort', 'bottom') # Force an item to stay on bottom next_page_item.setArt({'thumb': _get_custom_thumb_path('FolderPageNext.png')}) directory_items.append((common.build_url(pathitems=pathitems, params=params, mode=G.MODE_DIRECTORY), next_page_item, True))