mirror of
https://github.com/meisnate12/Plex-Meta-Manager
synced 2024-11-10 06:54:21 +00:00
#660 added blank_collection
This commit is contained in:
parent
3b8a9567fb
commit
6cb6cbca0e
3 changed files with 27 additions and 5 deletions
|
@ -95,7 +95,7 @@ string_details = ["sort_title", "content_rating", "name_mapping"]
|
|||
ignored_details = [
|
||||
"smart_filter", "smart_label", "smart_url", "run_again", "schedule", "sync_mode", "template", "test",
|
||||
"delete_not_scheduled", "tmdb_person", "build_collection", "collection_order", "collection_level",
|
||||
"validate_builders", "libraries", "sync_to_users", "collection_name", "playlist_name", "name"
|
||||
"validate_builders", "libraries", "sync_to_users", "collection_name", "playlist_name", "name", "blank_collection"
|
||||
]
|
||||
details = ["ignore_ids", "ignore_imdb_ids", "server_preroll", "changes_webhooks", "collection_mode",
|
||||
"minimum_items", "label", "album_sorting"] + boolean_details + scheduled_boolean + string_details
|
||||
|
@ -331,6 +331,13 @@ class CollectionBuilder:
|
|||
logger.debug(f"Value: {data[methods['build_collection']]}")
|
||||
self.build_collection = self._parse("build_collection", self.data, datatype="bool", methods=methods, default=True)
|
||||
|
||||
self.blank_collection = False
|
||||
if "blank_collection" in methods and not self.playlist:
|
||||
logger.debug("")
|
||||
logger.debug("Validating Method: blank_collection")
|
||||
logger.debug(f"Value: {data[methods['blank_collection']]}")
|
||||
self.blank_collection = self._parse("blank_collection", self.data, datatype="bool", methods=methods, default=False)
|
||||
|
||||
self.sync = self.library.sync_mode == "sync"
|
||||
if "sync_mode" in methods:
|
||||
logger.debug("")
|
||||
|
@ -571,9 +578,12 @@ class CollectionBuilder:
|
|||
else:
|
||||
logger.error(e)
|
||||
|
||||
if not self.server_preroll and not self.smart_url and len(self.builders) == 0:
|
||||
if not self.server_preroll and not self.smart_url and not self.blank_collection and len(self.builders) == 0:
|
||||
raise Failed(f"{self.Type} Error: No builders were found")
|
||||
|
||||
if self.blank_collection and len(self.builders) > 0:
|
||||
raise Failed(f"{self.Type} Error: No builders allowed with blank_collection")
|
||||
|
||||
if self.custom_sort is True and (len(self.builders) > 1 or self.builders[0][0] not in custom_sort_builders):
|
||||
raise Failed(f"{self.Type} Error: " + ('Playlists' if playlist else 'collection_order: custom') +
|
||||
(f" can only be used with a single builder per {self.type}" if len(self.builders) > 1 else f" cannot be used with {self.builders[0][0]}"))
|
||||
|
@ -2185,6 +2195,8 @@ class CollectionBuilder:
|
|||
def load_collection(self):
|
||||
if not self.obj and self.smart_url:
|
||||
self.library.create_smart_collection(self.name, self.smart_type_key, self.smart_url)
|
||||
elif not self.obj and self.blank_collection:
|
||||
self.library.create_blank_collection(self.name)
|
||||
elif self.smart_label_collection:
|
||||
try:
|
||||
smart_type, self.smart_url = self.library.smart_label_url(self.name, self.smart_sort)
|
||||
|
|
|
@ -631,13 +631,23 @@ class Plex(Library):
|
|||
}
|
||||
self._query(f"/library/collections{utils.joinArgs(args)}", post=True)
|
||||
|
||||
def create_blank_collection(self, title):
|
||||
args = {
|
||||
"type": 1 if self.is_movie else 2 if self.is_show else 8,
|
||||
"title": title,
|
||||
"smart": 0,
|
||||
"sectionId": self.Plex.key,
|
||||
"uri": f"{self.PlexServer._uriRoot()}/library/metadata"
|
||||
}
|
||||
self._query(f"/library/collections{utils.joinArgs(args)}", post=True)
|
||||
|
||||
def get_smart_filter_from_uri(self, uri):
|
||||
smart_filter = parse.parse_qs(parse.urlparse(uri.replace("/#!/", "/")).query)["key"][0]
|
||||
args = smart_filter[smart_filter.index("?"):]
|
||||
return self.build_smart_filter(args), int(args[args.index("type=") + 5:args.index("type=") + 6])
|
||||
|
||||
def build_smart_filter(self, uri_args):
|
||||
return f"server://{self.PlexServer.machineIdentifier}/com.plexapp.plugins.library/library/sections/{self.Plex.key}/all{uri_args}"
|
||||
return f"{self.PlexServer._uriRoot()}/library/sections/{self.Plex.key}/all{uri_args}"
|
||||
|
||||
def update_smart_collection(self, collection, uri_args):
|
||||
self.test_smart_filter(uri_args)
|
||||
|
|
|
@ -780,7 +780,7 @@ def run_collection(config, library, metadata, requested_collections):
|
|||
items_added = 0
|
||||
items_removed = 0
|
||||
valid = True
|
||||
if not builder.smart_url and builder.builders:
|
||||
if not builder.smart_url and builder.builders and not builder.blank_collection:
|
||||
logger.info("")
|
||||
logger.info(f"Sync Mode: {'sync' if builder.sync else 'append'}")
|
||||
|
||||
|
@ -821,7 +821,7 @@ def run_collection(config, library, metadata, requested_collections):
|
|||
library.status[mapping_name]["sonarr"] += sonarr_add
|
||||
|
||||
run_item_details = True
|
||||
if valid and builder.build_collection and (builder.builders or builder.smart_url):
|
||||
if valid and builder.build_collection and (builder.builders or builder.smart_url or builder.blank_collection):
|
||||
try:
|
||||
builder.load_collection()
|
||||
if builder.created:
|
||||
|
|
Loading…
Reference in a new issue