def count_references(source): counter = 0 for index, ref in sorted({int(k): v # pylint: disable=unused-variable for k, v in iteritems(source) if common.is_numeric(k)}.items()): path = reference_path(ref) if path is None: continue if path[0] == 'characters': continue counter += 1 return counter
def perpetual_path_request(self, paths, path_type, length_params1=None, length_params2=None): """Perform a perpetual path request against the Shakti API to retrieve a possibly large video list. If the requested video list's size is larger than MAX_PATH_REQUEST_SIZE, multiple path requests will be executed with forward shifting range selectors and the results will be combined into one path response.""" if length_params2 is None: length_params = [length_params1] else: length_params = [length_params1, length_params2] length = apipaths.LENGTH_ATTRIBUTES[path_type] range_start = 0 range_end = MAX_PATH_REQUEST_SIZE range_limit = int(g.ADDON.getSetting('list_limit_results'))\ if common.is_numeric(g.ADDON.getSetting('list_limit_results')) else 0 merged_response = {} while range_start < range_end: # We limit the number of results of the list, a very high number has more chance of causing, # AddonSignals call timed out, for the time it takes to request information # Would be more suitable that when you reach the end of the list, # you load the next block of results. if range_start >= range_limit > 0: range_start = range_end continue path_response = self._path_request( _set_range_selector(paths, range_start, range_end)) common.debug('perpetual_path_request path_response: ' + str(path_response)) range_start = range_end + 1 if len(path_response) != 0: common.merge_dicts(path_response, merged_response) videos_count = length(path_response, * length_params) - 1 #has zero base # If the number of video elements is lower, we've come to the end # Note: when the request is made with 'genre' context, # the response strangely does not respect the number of objects requested, # returning 2 more items, i couldn't understand why if videos_count >= MAX_PATH_REQUEST_SIZE: common.debug( '{} has more items, doing another path request'.format( path_type)) range_end += MAX_PATH_REQUEST_SIZE + 1 return merged_response
def count_references(source): counter = 0 for index, ref in sorted({int(k): v for k, v in source.iteritems() if common.is_numeric(k)}.iteritems()): path = reference_path(ref) if path is None: continue elif path[0] == 'characters': continue else: counter += 1 return counter
def iterate_references(source): """Generator expression that iterates over a dictionary of index=>reference pairs (sorted in ascending order by indices) until it reaches the first empty reference, which signals the end of the reference list. Items with a key that do not represent an integer are ignored.""" for index, ref in sorted( {int(k): v for k, v in iteritems(source) if common.is_numeric(k)}.items()): path = reference_path(ref) if path is None: break if path[0] == 'characters': # TODO: Implement handling of character references in Kids profiles continue yield (index, path)