From 68a7aa616dc4f871d89c30c6d8107f4a0b5ba66b Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Wed, 20 Mar 2024 15:29:52 -0400 Subject: [PATCH 1/3] add `mapping_sort` variable, like `collection_sort` Simply doing the same thing with `move_prefix`, but on the mapping name. --- modules/meta.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/meta.py b/modules/meta.py index 624eb863..873bcdf7 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -436,6 +436,7 @@ class DataFile: optional.append(f"{final_key}_encoded") sort_name = None + sort_mapping = None if "move_prefix" in template or "move_collection_prefix" in template: prefix = None if "move_prefix" in template: @@ -448,10 +449,13 @@ class DataFile: for op in util.get_list(prefix): if variables[name_var].startswith(f"{op} "): sort_name = f"{variables[name_var][len(op):].strip()}, {op}" - break + if variables["mapping_name"].startswith(f"{op} "): + sort_mapping = f"{variables['mapping_name'][len(op):].strip()}, {op}" + break if sort_name and sort_mapping else: raise Failed(f"{self.data_type} Error: template sub-attribute move_prefix is blank") variables[f"{self.data_type.lower()}_sort"] = sort_name if sort_name else variables[name_var] + variables["mapping_sort"] = sort_mapping if sort_mapping else variables["mapping_name"] for key, value in variables.copy().items(): if "<<" in key and ">>" in key: From 6c87b9303031a0a170153c34a51a90cfaed70e69 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Wed, 20 Mar 2024 15:31:38 -0400 Subject: [PATCH 2/3] add documentation for `mapping_sort` --- docs/files/templates.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/files/templates.md b/docs/files/templates.md index ada30993..36557e35 100644 --- a/docs/files/templates.md +++ b/docs/files/templates.md @@ -210,7 +210,7 @@ In addition, templates also have a few special attributes that they can use:
The `move_prefix` attribute can be used to specify a list or comma-separated string of prefixes to move to the end of the collection/playlist name for sorting. This changes the template variables - `collection_sort` and `playlist_sort`. + `collection_sort`, `playlist_sort`, and `mapping_sort`. ???+ example "Example" @@ -241,6 +241,7 @@ Every template also has access to these template variables: * Either `<>`, `<>`, or `<>` which is the name of the definition. * `<>` is the original mapping name for the definition in the YAML file. * Either `<>` or `<>` which is the name of the definition after `move_prefix` is applied. +* `<>` which is the original mapping name for the definition after `move_prefix` is applied. * `<>` which is the library type (`movie`, `show`, `artist`, `video`). * `<>` which is the name of the library. * All template variables can append `_encoded` to the variable name to use a URL encode version of the variable. ex. From aca30dadea00deada686541247c4b4898a40b5b3 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Wed, 20 Mar 2024 16:38:15 -0400 Subject: [PATCH 3/3] don't process sort_name or sort_mapping repeatedly Once they're set, they should be left alone. Maybe doing this in one loop isn't the clearest way to do it. --- modules/meta.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/meta.py b/modules/meta.py index 873bcdf7..a59aa64e 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -447,9 +447,9 @@ class DataFile: prefix = template["move_collection_prefix"] if prefix: for op in util.get_list(prefix): - if variables[name_var].startswith(f"{op} "): + if not sort_name and variables[name_var].startswith(f"{op} "): sort_name = f"{variables[name_var][len(op):].strip()}, {op}" - if variables["mapping_name"].startswith(f"{op} "): + if not sort_mapping and variables["mapping_name"].startswith(f"{op} "): sort_mapping = f"{variables['mapping_name'][len(op):].strip()}, {op}" break if sort_name and sort_mapping else: