From 0604171b38e15ded4f9a179ec8b68d24e88345d4 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Wed, 30 Jun 2021 11:07:02 -0400 Subject: [PATCH] #260 added visibility options --- modules/builder.py | 22 ++++++++++++++++++++++ modules/plex.py | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/modules/builder.py b/modules/builder.py index a23890f1..30618498 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -135,6 +135,9 @@ background_details = [ "url_background", "tmdb_background", "tvdb_background", "file_background" ] boolean_details = [ + "visible_library", + "visible_home", + "visible_shared", "show_filtered", "show_missing", "save_missing" @@ -1772,6 +1775,25 @@ class CollectionBuilder: self.library.collection_order_query(self.obj, self.details["collection_order"]) logger.info(f"Detail: collection_order updated Collection Order to {self.details['collection_order']}") + if "visible_library" in self.details or "visible_home" in self.details or "visible_shared" in self.details: + visibility = self.library.collection_visibility(self.obj) + visible_library = None + visible_home = None + visible_shared = None + + if "visible_library" in self.details and self.details["visible_library"] != visibility["library"]: + visible_library = self.details["visible_library"] + + if "visible_home" in self.details and self.details["visible_home"] != visibility["library"]: + visible_home = self.details["visible_home"] + + if "visible_shared" in self.details and self.details["visible_shared"] != visibility["library"]: + visible_shared = self.details["visible_shared"] + + if visible_library is not None or visible_home is not None or visible_shared is not None: + self.library.collection_visibility_update(self.obj, visibility=visibility, library=visible_library, home=visible_home, shared=visible_shared) + logger.info("Detail: Collection visibility updated") + add_tags = self.details["label"] if "label" in self.details else None remove_tags = self.details["label.remove"] if "label.remove" in self.details else None sync_tags = self.details["label.sync"] if "label.sync" in self.details else None diff --git a/modules/plex.py b/modules/plex.py index adb50747..724438e5 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -516,6 +516,7 @@ class Plex: elif put: method = self.Plex._server._session.put else: method = None self.Plex._server.query(key, method=method) + return self.Plex._server.query(key, method=method) def smart_label_url(self, title, sort): labels = self.get_labels() @@ -558,6 +559,26 @@ class Plex: smart_filter = self.get_collection(collection).content return smart_filter[smart_filter.index("?"):] + def collection_visibility(self, collection): + try: + attrs = self._query(f"/hubs/sections/{self.Plex.key}/manage?metadataItemId={collection.ratingKey}")[0].attrib + return { + "library": utils.cast(bool, attrs.get("promotedToRecommended", "0")), + "home": utils.cast(bool, attrs.get("promotedToOwnHome", "0")), + "shared": utils.cast(bool, attrs.get("promotedToSharedHome", "0")) + } + except IndexError: + return {"library": False, "home": False, "shared": False} + + def collection_visibility_update(self, collection, visibility=None, library=None, home=None, shared=None): + if visibility is None: + visibility = self.collection_visibility(collection) + key = f"/hubs/sections/{self.Plex.key}/manage?metadataItemId={collection.ratingKey}" + key += f"&promotedToRecommended={1 if (library is None and visibility['library']) or library else 0}" + key += f"&promotedToOwnHome={1 if (home is None and visibility['home']) or home else 0}" + key += f"&promotedToSharedHome={1 if (shared is None and visibility['shared']) or shared else 0}" + self._query(key, post=True) + def get_collection(self, data): if isinstance(data, int): collection = self.fetchItem(data)