From 9190b30a47af300e79e49dd8d9d25612d7c423d7 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Sun, 12 Sep 2021 22:42:33 -0400 Subject: [PATCH] #390 Add .is and .isnot to String searches and filters --- modules/builder.py | 12 ++++++------ modules/plex.py | 21 +++++---------------- modules/util.py | 5 +++-- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/modules/builder.py b/modules/builder.py index 0c0ad5ef..259e9dec 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -94,12 +94,12 @@ sonarr_details = [ all_filters = [ "actor", "actor.not", "audio_language", "audio_language.not", - "audio_track_title", "audio_track_title.not", "audio_track_title.begins", "audio_track_title.ends", "audio_track_title.regex", + "audio_track_title", "audio_track_title.not", "audio_track_title.is", "audio_track_title.isnot", "audio_track_title.begins", "audio_track_title.ends", "audio_track_title.regex", "collection", "collection.not", "content_rating", "content_rating.not", "country", "country.not", "director", "director.not", - "filepath", "filepath.not", "filepath.begins", "filepath.ends", "filepath.regex", + "filepath", "filepath.not", "filepath.is", "filepath.isnot", "filepath.begins", "filepath.ends", "filepath.regex", "genre", "genre.not", "label", "label.not", "producer", "producer.not", @@ -108,7 +108,7 @@ all_filters = [ "last_played", "last_played.not", "last_played.before", "last_played.after", "last_played.regex", "first_episode_aired", "first_episode_aired.not", "first_episode_aired.before", "first_episode_aired.after", "first_episode_aired.regex", "last_episode_aired", "last_episode_aired.not", "last_episode_aired.before", "last_episode_aired.after", "last_episode_aired.regex", - "title", "title.not", "title.begins", "title.ends", "title.regex", + "title", "title.not", "title.is", "title.isnot", "title.begins", "title.ends", "title.regex", "plays.gt", "plays.gte", "plays.lt", "plays.lte", "tmdb_vote_count.gt", "tmdb_vote_count.gte", "tmdb_vote_count.lt", "tmdb_vote_count.lte", "duration.gt", "duration.gte", "duration.lt", "duration.lte", @@ -116,7 +116,7 @@ all_filters = [ "user_rating.gt", "user_rating.gte", "user_rating.lt", "user_rating.lte", "audience_rating.gt", "audience_rating.gte", "audience_rating.lt", "audience_rating.lte", "critic_rating.gt", "critic_rating.gte", "critic_rating.lt", "critic_rating.lte", - "studio", "studio.not", "studio.begins", "studio.ends", "studio.regex", + "studio", "studio.not", "studio.is", "studio.isnot", "studio.begins", "studio.ends", "studio.regex", "subtitle_language", "subtitle_language.not", "resolution", "resolution.not", "writer", "writer.not", @@ -126,7 +126,7 @@ all_filters = [ tmdb_filters = ["original_language", "tmdb_vote_count", "tmdb_year", "first_episode_aired", "last_episode_aired"] movie_only_filters = [ "audio_language", "audio_language.not", - "audio_track_title", "audio_track_title.not", "audio_track_title.begins", "audio_track_title.ends", "audio_track_title.regex", + "audio_track_title", "audio_track_title.not", "audio_track_title.is", "audio_track_title.isnot", "audio_track_title.begins", "audio_track_title.ends", "audio_track_title.regex", "country", "country.not", "director", "director.not", "duration.gt", "duration.gte", "duration.lt", "duration.lte", @@ -1383,7 +1383,7 @@ class CollectionBuilder: else: logger.error(err) return valid_regex - elif attribute in ["title", "studio", "episode_title", "audio_track_title"] and modifier in ["", ".not", ".begins", ".ends"]: + elif attribute in ["title", "studio", "episode_title", "audio_track_title"] and modifier in ["", ".not", ".is", ".isnot", ".begins", ".ends"]: return smart_pair(util.get_list(data, split=False)) elif attribute == "original_language": return util.get_list(data, lower=True) diff --git a/modules/plex.py b/modules/plex.py index b2ef9109..aec168d8 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -66,7 +66,7 @@ show_translation = { "label": "show.label", } modifier_translation = { - "": "", ".not": "!", ".gt": "%3E%3E", ".gte": "%3E", ".lt": "%3C%3C", ".lte": "%3C", + "": "", ".not": "!", ".is": "%3D", ".isnot": "!%3D", ".gt": "%3E%3E", ".gte": "%3E", ".lt": "%3C%3C", ".lte": "%3C", ".before": "%3C%3C", ".after": "%3E%3E", ".begins": "%3C", ".ends": "%3E" } episode_sorting_options = {"default": "-1", "oldest": "0", "newest": "1"} @@ -101,8 +101,8 @@ item_advance_keys = { } new_plex_agents = ["tv.plex.agents.movie", "tv.plex.agents.series"] searches = [ - "title", "title.not", "title.begins", "title.ends", - "studio", "studio.not", "studio.begins", "studio.ends", + "title", "title.not", "title.is", "title.isnot", "title.begins", "title.ends", + "studio", "studio.not", "studio.is", "studio.isnot", "studio.begins", "studio.ends", "actor", "actor.not", "audio_language", "audio_language.not", "collection", "collection.not", @@ -126,7 +126,7 @@ searches = [ "audience_rating.gt", "audience_rating.gte", "audience_rating.lt", "audience_rating.lte", "year", "year.not", "year.gt", "year.gte", "year.lt", "year.lte", "unplayed_episodes", "episode_unplayed", "episode_duplicate", "episode_progress", "episode_unmatched", - "episode_title", "episode_title.not", "episode_title.begins", "episode_title.ends", + "episode_title", "episode_title.not", "episode_title.is", "episode_title.isnot", "episode_title.begins", "episode_title.ends", "episode_added", "episode_added.not", "episode_added.before", "episode_added.after", "episode_air_date", "episode_air_date.not", "episode_air_date.before", "episode_air_date.after", "episode_last_played", "episode_last_played.not", "episode_last_played.before", "episode_last_played.after", @@ -151,7 +151,7 @@ movie_only_searches = [ ] show_only_searches = [ "network", "network.not", - "episode_title", "episode_title.not", "episode_title.begins", "episode_title.ends", + "episode_title", "episode_title.not", "episode_title.is", "episode_title.isnot", "episode_title.begins", "episode_title.ends", "episode_added", "episode_added.not", "episode_added.before", "episode_added.after", "episode_air_date", "episode_air_date.not", "episode_air_date.before", "episode_air_date.after", @@ -170,17 +170,6 @@ tmdb_attributes = ["actor", "director", "producer", "writer"] date_attributes = ["added", "episode_added", "release", "episode_air_date", "last_played", "episode_last_played", "first_episode_aired", "last_episode_aired"] number_attributes = ["plays", "episode_plays", "duration", "tmdb_vote_count"] + date_attributes search_display = {"added": "Date Added", "release": "Release Date", "hdr": "HDR", "progress": "In Progress", "episode_progress": "Episode In Progress"} -sorts = { - None: None, - "title.asc": "titleSort:asc", "title.desc": "titleSort:desc", - "originally_available.asc": "originallyAvailableAt:asc", "originally_available.desc": "originallyAvailableAt:desc", - "release.asc": "originallyAvailableAt:asc", "release.desc": "originallyAvailableAt:desc", - "critic_rating.asc": "rating:asc", "critic_rating.desc": "rating:desc", - "audience_rating.asc": "audienceRating:asc", "audience_rating.desc": "audienceRating:desc", - "duration.asc": "duration:asc", "duration.desc": "duration:desc", - "added.asc": "addedAt:asc", "added.desc": "addedAt:desc" -} -modifiers = {".not": "!", ".begins": "<", ".ends": ">", ".before": "<<", ".after": ">>", ".gt": ">>", ".gte": "__gte", ".lt": "<<", ".lte": "__lte"} tags = [ "actor", "audio_language", "collection", "content_rating", "country", "director", "genre", "label", "network", "producer", "resolution", "studio", "subtitle_language", "writer" diff --git a/modules/util.py b/modules/util.py index b972270f..1eb6dc0b 100644 --- a/modules/util.py +++ b/modules/util.py @@ -49,7 +49,7 @@ days_alias = { "sunday": 6, "sun": 6, "su": 6, "u": 6 } mod_displays = { - "": "is", ".not": "is not", ".begins": "begins with", ".ends": "ends with", ".before": "is before", ".after": "is after", + "": "is", ".not": "is not", ".is": "is", ".isnot": "is not", ".begins": "begins with", ".ends": "ends with", ".before": "is before", ".after": "is after", ".gt": "is greater than", ".gte": "is greater than or equal", ".lt": "is less than", ".lte": "is less than or equal" } pretty_days = {0: "Monday", 1: "Tuesday", 2: "Wednesday", 3: "Thursday", 4: "Friday", 5: "Saturday", 6: "Sunday"} @@ -282,13 +282,14 @@ def is_string_filter(values, modifier, data): for value in values: for check_value in data: if (modifier in ["", ".not"] and check_value.lower() in value.lower()) \ + or (modifier in [".is", ".isnot"] and value.lower() == check_value.lower()) \ or (modifier == ".begins" and value.lower().startswith(check_value.lower())) \ or (modifier == ".ends" and value.lower().endswith(check_value.lower())) \ or (modifier == ".regex" and re.compile(check_value).match(value)): jailbreak = True break if jailbreak: break - return (jailbreak and modifier == ".not") or (not jailbreak and modifier in ["", ".begins", ".ends", ".regex"]) + return (jailbreak and modifier in [".not", ".isnot"]) or (not jailbreak and modifier in ["", ".is", ".begins", ".ends", ".regex"]) def parse(attribute, data, datatype=None, methods=None, parent=None, default=None, options=None, translation=None, minimum=1, maximum=None, regex=None): display = f"{parent + ' ' if parent else ''}{attribute} attribute"