python-plexapi icon indicating copy to clipboard operation
python-plexapi copied to clipboard

feat: python class for available filters

Open Dr-Blank opened this issue 1 year ago • 3 comments

What is your feature request?

search(title=None, libtype=None, **kwargs) and other methods which rely on kwargs for search would be able to accept this filter object will add editor support for filters

Are there any workarounds?

currently one needs to refer documentation for this and pass in the filters as kwargs, which do not give proper developer support

Code Snippets

No response

Additional Context

somehting like this

filter = Filter().genre("foo").year(le=2020)
# or 
filter = Filter(genre="foo", year=2020)

lib.search(filter=filter)

Dr-Blank avatar Dec 26 '23 23:12 Dr-Blank

Where should I put classes and functions related to this PR?

utils.py is growing and there is no discussion on #1291 yet

proof of concept here

Dr-Blank avatar Jan 29 '24 10:01 Dr-Blank

I don't see the point of doing this. It overcomplicates things.

JonnyWong16 avatar Jan 29 '24 15:01 JonnyWong16

I don't see the point of doing this. It overcomplicates things.

I understand your concern about potential overcomplication, but I would like to reiterate the benefits and the rationale behind this proposed feature as I feel i might have done a poor job in the first place.

  1. Compatibility: One of the key advantages of the proposed changes is that they do not break compatibility. Users who are comfortable with the existing method of using strings and dictionaries for filtering can continue doing so without any disruption. The introduction of Python mappings simply provides an additional, more convenient option for those who prefer a more programmatic approach.
  2. Project Intention and Pythonic Design: The core purpose of our project is to provide a Python interface to the Plex API. By introducing Python mappings for generating filters, we are aligning with the Pythonic principles and making the API more intuitive for Python developers. This enhancement is designed to facilitate a smoother and more natural interaction with the Plex API, which is consistent with the goals of the project.
  3. Editor Support and Reduced Error-Prone Usage: The introduction of Python mappings not only enhances the development experience but also significantly reduces the chances of errors. Developers can benefit from improved editor support, including autocompletion, which streamlines the coding process and minimizes the need for constant reference to documentation. This feature can be particularly helpful for those who are new to the project or have limited familiarity with the available attributes.
  4. Parallels with SQLAlchemy: SQLAlchemy adopts a Pythonic approach by offering a Python interface instead of relying on raw strings for queries. This design choice has been well-received in the community and has contributed to the popularity and usability of the library.

here is how it would look if implemented

from plexapi.audio import Album, Artist, Track
from plexapi.utils import Filter

# Using Python mappings for filter generation
lib.search(filter=Filter(
    Album.genre == "Rock",
    Track.rating > 3,
    Artist.collection != 'Christmas'
))

I appreciate your time and consideration on this matter, and I am open to further discussion or modifications to address any concerns you may have.

Dr-Blank avatar Jan 29 '24 21:01 Dr-Blank