Beispiel #1
0
 def search(self,
            title=None,
            sort=None,
            maxresults=999999,
            libtype=None,
            **kwargs):
     """ Search the library. If there are many results, they will be fetched from the server
         in batches of X_PLEX_CONTAINER_SIZE amounts. If you're only looking for the first <num>
         results, it would be wise to set the maxresults option to that amount so this functions
         doesn't iterate over all results on the server.
         title: General string query to search for.
         sort: column:dir; column can be any of {addedAt, originallyAvailableAt, lastViewedAt,
           titleSort, rating, mediaHeight, duration}. dir can be asc or desc.
         maxresults: Only return the specified number of results
         libtype: Filter results to a spcifiec libtype {movie, show, episode, artist, album, track}
         kwargs: Any of the available filters for the current library section. Partial string
           matches allowed. Multiple matches OR together. All inputs will be compared with the
           available options and a warning logged if the option does not appear valid.
             'unwatched': Display or hide unwatched content (True, False). [all]
             'duplicate': Display or hide duplicate items (True, False). [movie]
             'actor': List of actors to search ([actor_or_id, ...]). [movie]
             'collection': List of collections to search within ([collection_or_id, ...]). [all]
             'contentRating': List of content ratings to search within ([rating_or_key, ...]). [movie, tv]
             'country': List of countries to search within ([country_or_key, ...]). [movie, music]
             'decade': List of decades to search within ([yyy0, ...]). [movie]
             'director': List of directors to search ([director_or_id, ...]). [movie]
             'genre': List Genres to search within ([genere_or_id, ...]). [all]
             'network': List of TV networks to search within ([resolution_or_key, ...]). [tv]
             'resolution': List of video resolutions to search within ([resolution_or_key, ...]). [movie]
             'studio': List of studios to search within ([studio_or_key, ...]). [music]
             'year': List of years to search within ([yyyy, ...]). [all]
     """
     # Cleanup the core arguments
     args = {}
     for category, value in kwargs.items():
         args[category] = self._cleanSearchFilter(category, value, libtype)
     if title is not None:
         args['title'] = title
     if sort is not None:
         args['sort'] = self._cleanSearchSort(sort)
     if libtype is not None:
         args['type'] = plexobjects.searchType(libtype)
     # Iterate over the results
     results, subresults = [], '_init'
     args['X-Plex-Container-Start'] = 0
     args['X-Plex-Container-Size'] = min(util.X_PLEX_CONTAINER_SIZE,
                                         maxresults)
     while subresults and maxresults > len(results):
         query = '/library/sections/%s/all%s' % (self.key,
                                                 util.joinArgs(args))
         subresults = plexobjects.listItems(self.server, query)
         results += subresults[:maxresults - len(results)]
         args['X-Plex-Container-Start'] += args['X-Plex-Container-Size']
     return results
Beispiel #2
0
 def search(self, title, libtype=None, **kwargs):
     """ Searching within a library section is much more powerful. It seems certain attributes on the media
         objects can be targeted to filter this search down a bit, but I havent found the documentation for
         it. For example: "studio=Comedy%20Central" or "year=1999" "title=Kung Fu" all work. Other items
         such as actor=<id> seem to work, but require you already know the id of the actor.
         TLDR: This is untested but seems to work. Use library section search when you can.
     """
     args = {}
     if title:
         args['title'] = title
     if libtype:
         args['type'] = plexobjects.searchType(libtype)
     for attr, value in kwargs.items():
         args[attr] = value
     query = '/library/all%s' % util.joinArgs(args)
     return plexobjects.listItems(self.server, query)
Beispiel #3
0
    def listChoices(self, category, libtype=None, **kwargs):
        """ List choices for the specified filter category. kwargs can be any of the same
            kwargs in self.search() to help narrow down the choices to only those that
            matter in your current context.
        """
        if category in kwargs:
            raise exceptions.BadRequest(
                'Cannot include kwarg equal to specified category: %s' %
                category)
        args = {}
        for subcategory, value in kwargs.items():
            args[category] = self._cleanSearchFilter(subcategory, value)
        if libtype is not None:
            args['type'] = plexobjects.searchType(libtype)
        query = '/library/sections/%s/%s%s' % (self.key, category,
                                               util.joinArgs(args))

        return plexobjects.listItems(self.server, query, bytag=True)