From 5f742615e6d4dc3398ec849e530051d0a55563db Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Sat, 16 Jul 2022 15:28:16 -0400 Subject: [PATCH] [35] small fixes --- VERSION | 2 +- docs/metadata/templates.md | 38 +++++++++++++++++++++++++++++++++++++- modules/builder.py | 1 - modules/meta.py | 1 + modules/trakt.py | 2 +- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index a11ad454..7b5ee1a9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.1-develop34 +1.17.1-develop35 diff --git a/docs/metadata/templates.md b/docs/metadata/templates.md index 1e31de8f..66e9f796 100644 --- a/docs/metadata/templates.md +++ b/docs/metadata/templates.md @@ -101,10 +101,11 @@ collections: ## Special Template Attributes -There are three attributes unique to `templates`; `default`, `optional`, and `move_prefix`. +There are some attributes unique to `templates`; `default`, `optional`, `conditionals`, and `move_prefix`. * `default` can set default values for template variables to be used if they're not specified in the call. * `optional` can specify variables that if not specified on the template call will cause any attribute using one of those variables to be ignored in the template. You can make any template variable optional per collection by setting it to `null`. +* `conditionals` can specify variables based on conditions set by the user. See more [here](#conditionals) * `move_prefix` can be given a list or comma-separated string of prefixes to move to the end of the collection/playlist name for sorting. i.e. If you have `move_prefix: The` and a collection is called `The Avengers` then `<>` is replaced with `Avengers, The` instead of `The Avengers` for that collection. @@ -115,6 +116,41 @@ Every template call is given these template variables. * `<>` which is the library type * All Template Variables can append `_encoded` to the variable name to use a URL encode version of the variable. ex. `<>` +### Conditionals + +Each conditional is identified by its mapping name and has one required attribute; `conditions` and one optional attribute; `default`. + +`default` is the default value for the variable when no condition is met. If default is not specified the variable becomes an optional variable. + +`conditions` is a list of sets of conditions where if all conditions are met then the variable will be the `value` specified in that condition. + +Each set of conditions must have the `value` attribute which is the value of the variable if the condition is met. + +All other attribute pairs in the set of conditions will check a variable of the attribute key and see if the variable is the attribute value or in the list of attribute values. + +Here's an example from the [PMM default ratings file](https://github.com/meisnate12/Plex-Meta-Manager-Configs/blob/master/PMM/overlays/ratings.yml). + +```yaml +templates: + Rating: + conditionals: + rating1_horizontal_offset: + default: 30 # If no condition sets below are meet + conditions: + - side: [top, bottom] + rating2: none + rating3: none + value: 0 # If side is 'top' or 'bottom' and rating2 is 'none' and rating3 is 'none' + - side: [top, bottom] + rating2: none + value: -165 # If side is 'top' or 'bottom' and rating2 is 'none' and no previous conditions are meet + - side: [top, bottom] + rating3: none + value: -165 # If side is 'top' or 'bottom' rating3 is 'none' and no previous conditions are meet + - side: [top, bottom] + value: -335 # If side is 'top' or 'bottom' and no previous conditions are meet +``` + ## Advance Example Here's an example IMDb Genre template and two different ways to call it. diff --git a/modules/builder.py b/modules/builder.py index 9b69b278..cac97486 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -505,7 +505,6 @@ class CollectionBuilder: results = self.config.TMDb.search_people(tmdb_person) if results: valid_names.append(tmdb_person) - valid_names.append(results[0].name) if results[0].biography: self.summaries["tmdb_person"] = results[0].biography if results[0].profile_url: diff --git a/modules/meta.py b/modules/meta.py index 436ca65f..8e9ce15f 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -141,6 +141,7 @@ class DataFile: name_var = f"{self.data_type.lower()}_name" variables[name_var] = str(name) + variables["mapping_name"] = mapping_name variables["library_type"] = self.library.type.lower() if self.library else "items" variables["library_name"] = self.library.name if self.library else "playlist" diff --git a/modules/trakt.py b/modules/trakt.py index e9268db6..d845fb6c 100644 --- a/modules/trakt.py +++ b/modules/trakt.py @@ -470,7 +470,7 @@ class Trakt: userlist = util.parse(err_type, "userlist", trakt_dict, methods=dict_methods, parent=method_name, options=["recommended", "watched", "collected", "watchlist"]) user = util.parse(err_type, "user", trakt_dict, methods=dict_methods, parent=method_name, default="me") sort_by = None - if userlist in ["recommended", "watchlist"] and "sort" in dict_methods: + if userlist in ["recommended", "watchlist"] and "sort_by" in dict_methods: sort_by = util.parse(err_type, "sort_by", trakt_dict, methods=dict_methods, parent=method_name, default="rank", options=["rank", "added", "released", "title"]) self._userlist("collection" if userlist == "collected" else userlist, user, is_movie, sort_by=sort_by) valid_dicts.append({"userlist": userlist, "user": user, "sort_by": sort_by})