[86] add number and list` dynamic collection types

This commit is contained in:
meisnate12 2022-05-11 02:40:50 -04:00
parent 8f30b75788
commit 97f874067c
4 changed files with 122 additions and 7 deletions

View file

@ -1 +1 @@
1.16.5-develop85
1.16.5-develop86

View file

@ -130,6 +130,8 @@ Depending on the `type` of dynamic collection, `data` is used to specify the opt
| [`network`](#network) | Create a collection for each network found in the library | ❌ | ❌ | ✅ | ❌ | ❌ |
| [`mood`](#mood) | Create a collection for each mood found in the library | ❌ | ❌ | ❌ | ✅ | ❌ |
| [`style`](#style) | Create a collection for each style found in the library | ❌ | ❌ | ❌ | ✅ | ❌ |
| [`number`](#number) | Creates a collection for each number defined | ✅ | ✅ | ✅ | ✅ | ✅ |
| [`list`](#list) | Creates a collection for each item in the list defined | ✅ | ✅ | ✅ | ✅ | ✅ |
### TMDb Collection
@ -1562,6 +1564,90 @@ dynamic_collections:
template: style collection
```
### Number
Creates a collection for each number defined.
<table class="dualTable colwidths-auto align-default table">
<tr>
<th><code>type</code> Option</th>
<td><code>number</code></td>
</tr>
<tr>
<th><code>data</code> Values</th>
<td>
<table class="clearTable">
<tr>
<th>Attribute</th>
<th>Description & Values</th>
</tr>
<tr>
<td><code>starting</code></td>
<td><strong>Values:</strong> Number greater then 0</td>
<td><strong>Default:</strong> 0</td>
</tr>
<tr>
<td><code>ending</code></td>
<td><strong>Values:</strong> Number greater then 1</td>
<td><strong>Default:</strong> 1</td>
</tr>
<tr>
<td><code>increment</code></td>
<td><strong>Values:</strong> Number greater then 0</td>
<td><strong>Default:</strong> 1</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Keys</th>
<td>Number</td>
</tr>
<tr>
<th>Key Names</th>
<td>Number</td>
</tr>
<tr>
<th>Default <code>title_format</code></th>
<td><code>&lt;&lt;key_name&gt;&gt;</code></td>
</tr>
<tr>
<th>Default Template</th>
<td>**None**</td>
</tr>
</table>
### List
Creates a collection for each item in the list defined .
<table class="dualTable colwidths-auto align-default table">
<tr>
<th><code>type</code> Option</th>
<td><code>list</code></td>
</tr>
<tr>
<th><code>data</code> Values</th>
<td>Strings to iterate</td>
</tr>
<tr>
<th>Keys</th>
<td>String</td>
</tr>
<tr>
<th>Key Names</th>
<td>String</td>
</tr>
<tr>
<th>Default <code>title_format</code></th>
<td><code>&lt;&lt;key_name&gt;&gt;</code></td>
</tr>
<tr>
<th>Default Template</th>
<td>**None**</td>
</tr>
</table>
## Exclude
Exclude this list of `keys` from being created into collections.

View file

@ -331,18 +331,15 @@ class CollectionBuilder:
else:
raise Failed("Playlist Error: libraries attribute is required")
self.sync_to_users = config.general["playlist_sync_to_users"]
if "sync_to_users" in methods or "sync_to_user" in methods:
s_attr = f"sync_to_user{'s' if 'sync_to_users' in methods else ''}"
logger.debug("")
logger.debug(f"Validating Method: {s_attr}")
logger.debug(f"Value: {self.data[methods[s_attr]]}")
if self.data[methods[s_attr]]:
self.sync_to_users = self.data[methods[s_attr]]
else:
logger.warning(f"Playlist Error: sync_to_users attribute is blank defaulting to playlist_sync_to_users: {self.sync_to_users}")
self.sync_to_users = self.data[methods[s_attr]]
else:
logger.warning(f"Playlist Error: sync_to_users attribute not found defaulting to playlist_sync_to_users: {self.sync_to_users}")
self.sync_to_users = config.general["playlist_sync_to_users"]
plex_users = self.library.users
if self.sync_to_users:

View file

@ -7,7 +7,7 @@ from ruamel import yaml
logger = util.logger
all_auto = ["genre"]
all_auto = ["genre", "number", "list"]
ms_auto = [
"actor", "year", "content_rating", "original_language", "tmdb_popular_people", "trakt_user_lists", "studio",
"trakt_liked_lists", "trakt_people_list", "subtitle_language", "audio_language", "resolution", "decade"
@ -451,6 +451,36 @@ class MetadataFile(DataFile):
all_keys.append(role["name"])
person_count += 1
default_template = {"plex_search": {"any": {auto_type: "<<value>>"}}}
elif auto_type == "number":
if "data" in methods:
dynamic_data = util.parse("Config", "data", dynamic, parent=map_name, methods=methods, datatype="dict")
else:
raise Failed(f"Config Error: {map_name} data attribute not found")
number_methods = {nm.lower(): nm for nm in dynamic_data}
if "starting" in number_methods and dynamic_data[number_methods["starting"]] == "current_year":
starting = datetime.now().year
else:
starting = util.parse("Config", "starting", dynamic_data, parent=f"{map_name} data", methods=number_methods, datatype="int", default=0, minimum=0)
if "ending" in number_methods and dynamic_data[number_methods["ending"]] == "current_year":
ending = datetime.now().year
else:
ending = util.parse("Config", "ending", dynamic_data, parent=f"{map_name} data", methods=number_methods, datatype="int", default=0, minimum=1)
increment = util.parse("Config", "increment", dynamic_data, parent=f"{map_name} data", methods=number_methods, datatype="int", default=1, minimum=1)
if starting > ending:
raise Failed(f"Config Error: {map_name} data ending must be greater then starting")
current = starting
while starting <= ending:
all_keys.append(str(current))
if str(current) not in exclude and current not in exclude:
auto_list[str(current)] = str(current)
current += increment
elif auto_type == "list":
if "data" not in methods:
raise Failed(f"Config Error: {map_name} data attribute not found")
for list_item in util.parse("Config", "data", dynamic, parent=map_name, methods=methods, datatype="strlist"):
all_keys.append(list_item)
if list_item not in exclude:
auto_list[list_item] = list_item
elif auto_type == "trakt_user_lists":
dynamic_data = util.parse("Config", "data", dynamic, parent=map_name, methods=methods, datatype="list")
for option in dynamic_data:
@ -505,6 +535,8 @@ class MetadataFile(DataFile):
has_var = True
if not has_var:
raise Failed(f"Config Error: One {map_name} template: {template_names} is required to have the template variable <<value>>")
elif auto_type in ["number", "list"]:
raise Failed(f"Config Error: {map_name} template required for type: {auto_type}")
else:
self.templates[map_name] = (default_template if default_template else default_templates[auto_type], {})
template_names = [map_name]