Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to parse the smart filters from collections and playlists #781

Merged
merged 8 commits into from
Jul 16, 2021

Conversation

JonnyWong16
Copy link
Collaborator

@JonnyWong16 JonnyWong16 commented Jun 18, 2021

Description

Adds a filters() method to Collection and Playlist to parse out the smart filters originally used to create the collection or playlist. The filters returned from filters() can be passed directly into LibrarySection.search() as kwargs to return the list of items.

Note: Only supports parsing filters using the new advanced filters from Plex Web 4.56.3. Smart collections and playlists created before Plex Web 4.56.3 must be updated first.

Example:

advancedFilters = {
    'and': [
        {
            'or': [
                {'title': 'elephant'},
                {'title': 'bunny'}
            ]
        },
        {'year>>': 1990},
        {'unwatched': True}
    ]
}

collection = movies.createCollection(
    title='Smart Filters',
    smart=True,
    limit=2,
    sort='year:asc',
    filters=advancedFilters
)
collectionSmartFilters = collection.filters()
assert collection.items() == movies.search(**collectionSmartFilters)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the docstring for new or existing methods
  • I have added tests when applicable

Some sort fields don't follow the `defaultDirection` if the sort direction is not specified (e.g. `year` returns `year:asc` instead of the default `year:desc`). Allow blank `sortDir` and let the server handle it.
@JonnyWong16 JonnyWong16 force-pushed the feature/parse_smart_filter branch from 2b32156 to 663402e Compare June 18, 2021 22:26
@JonnyWong16 JonnyWong16 merged commit 82fa178 into pkkid:master Jul 16, 2021
@JonnyWong16 JonnyWong16 deleted the feature/parse_smart_filter branch October 4, 2021 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant