def all(cls, types=None, keys=None, titles=None): types = to_iterable(types) sections = Plex['library'].sections().filter(types, keys, titles) if sections is None: log.warn('Unable to retrieve any sections (request failed)') return None result = {} for section in sections: if section.agent == "com.plexapp.agents.none": # Exclude sections that don't have an agent continue if section.type not in result: result[section.type] = {} for item in section.all(): cls.item_map(result[section.type], item) if types and len(types) == 1: # Return single type-map if only one was requested return result.get(types[0], {}) return result
def filter(self, identifiers=None): identifiers = to_iterable(identifiers) for client in self: if not self.filter_passes(identifiers, client.machine_identifier): continue yield client
def filter(self, keys=None): keys = to_iterable(keys) for item in self: if not self.filter_passes(keys, item.session.key): continue yield item
def filter(self, types=None, keys=None, titles=None): types = to_iterable(types) keys = to_iterable(keys) titles = to_iterable(titles) if titles: # Flatten titles titles = [flatten(x) for x in titles] for section in self: if not self.filter_passes(types, section.type): continue if not self.filter_passes(keys, section.key): continue if not self.filter_passes(titles, flatten(section.title)): continue yield section
def test_to_iterable(): assert to_iterable(None) is None assert to_iterable("test") == ["test"] assert to_iterable(100) == [100] assert to_iterable([100]) == [100] assert to_iterable([]) == [] assert to_iterable((100, )) == (100, ) assert to_iterable(tuple([])) == tuple([])
def filter(self, types=None, keys=None, titles=None): types = to_iterable(types) keys = to_iterable(keys) titles = to_iterable(titles) if titles: # Normalize titles titles = [x.lower() for x in titles] for section in self: if not self.filter_passes(types, section.type): continue if not self.filter_passes(keys, section.key): continue if not self.filter_passes(titles, section.title.lower()): continue yield section
def test_to_iterable(): assert to_iterable(None) is None assert to_iterable("test") == ["test"] assert to_iterable(100) == [100] assert to_iterable([100]) == [100] assert to_iterable([]) == [] assert to_iterable((100,)) == (100,) assert to_iterable(tuple([])) == tuple([])