def add_items(self, items): '''Adds ListItems to the XBMC interface. Each item in the provided list should either be instances of xbmcswift2.ListItem, or regular dictionaries that will be passed to xbmcswift2.ListItem.from_dict. Returns the list of ListItems. :param items: An iterable of items where each item is either a dictionary with keys/values suitable for passing to :meth:`xbmcswift2.ListItem.from_dict` or an instance of :class:`xbmcswift2.ListItem`. ''' # For each item if it is not already a list item, we need to create one _items = [] # Create ListItems for anything that is not already an instance of # ListItem for item in items: if not isinstance(item, xbmcswift2.ListItem): item = xbmcswift2.ListItem.from_dict(**item) _items.append(item) tuples = [item.as_tuple() for item in _items] xbmcplugin.addDirectoryItems(self.handle, tuples, len(tuples)) # We need to keep track internally of added items so we can return them # all at the end for testing purposes self.added_items.extend(_items) # Possibly need an if statement if only for debug mode return _items
def add_items(self, items): '''Adds ListItems to the XBMC interface. Each item in the provided list should either be instances of xbmcswift2.ListItem, or regular dictionaries that will be passed to xbmcswift2.ListItem.from_dict. Returns the list of ListItems. :param items: An iterable of items where each item is either a dictionary with keys/values suitable for passing to :meth:`xbmcswift2.ListItem.from_dict` or an instance of :class:`xbmcswift2.ListItem`. ''' # For each item if it is not already a list item, we need to create one _items = [] info_type = self.info_type if hasattr(self, 'info_type') else 'video' # Create ListItems for anything that is not already an instance of # ListItem for item in items: if not isinstance(item, xbmcswift2.ListItem): if 'info_type' not in item.keys(): item['info_type'] = info_type item = xbmcswift2.ListItem.from_dict(**item) _items.append(item) tuples = [item.as_tuple() for item in _items] xbmcplugin.addDirectoryItems(self.handle, tuples, len(tuples)) # We need to keep track internally of added items so we can return them # all at the end for testing purposes self.added_items.extend(_items) # Possibly need an if statement if only for debug mode return _items
def add_items(self, items): '''Adds ListItems to the XBMC interface. Each item in the provided list should either be instances of xbmcswift2.ListItem, or regular dictionaries that will be passed to xbmcswift2.ListItem.from_dict. Returns the list of ListItems. :param items: An iterable of items where each item is either a dictionary with keys/values suitable for passing to :meth:`xbmcswift2.ListItem.from_dict` or an instance of :class:`xbmcswift2.ListItem`. ''' _items = [self._listitemify(item) for item in items] tuples = [item.as_tuple() for item in _items] for index in range(0, len(tuples)): listitem = tuples[index][1] thumbnail = listitem.getArt("thumb") if thumbnail: listitem.setArt({'poster': thumbnail}) xbmcplugin.addDirectoryItems(self.handle, tuples, len(tuples)) # We need to keep track internally of added items so we can return them # all at the end for testing purposes self.added_items.extend(_items) # Possibly need an if statement if only for debug mode return _items
def add_items(self, items, total_items=None): """Adds ListItems to the XBMC interface. Each item in the provided list should either be instances of xbmcswift2.ListItem, or regular dictionaries that will be passed to xbmcswift2.ListItem.from_dict. Returns the list of ListItems. :param items: An iterable of items where each item is either a dictionary with keys/values suitable for passing to :meth:`xbmcswift2.ListItem.from_dict` or an instance of :class:`xbmcswift2.ListItem`. """ _items = [self._listitemify(item) for item in items] tuples = [item.as_tuple() for item in _items] xbmcplugin.addDirectoryItems(self.handle, tuples, total_items or len(tuples)) # We need to keep track internally of added items so we can return them # all at the end for testing purposes self.added_items.extend(_items) # Possibly need an if statement if only for debug mode return _items