#260 added visibility options

pull/309/head
meisnate12 3 years ago
parent be985fd7df
commit 0604171b38

@ -135,6 +135,9 @@ background_details = [
"url_background", "tmdb_background", "tvdb_background", "file_background" "url_background", "tmdb_background", "tvdb_background", "file_background"
] ]
boolean_details = [ boolean_details = [
"visible_library",
"visible_home",
"visible_shared",
"show_filtered", "show_filtered",
"show_missing", "show_missing",
"save_missing" "save_missing"
@ -1772,6 +1775,25 @@ class CollectionBuilder:
self.library.collection_order_query(self.obj, self.details["collection_order"]) 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']}") 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 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 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 sync_tags = self.details["label.sync"] if "label.sync" in self.details else None

@ -516,6 +516,7 @@ class Plex:
elif put: method = self.Plex._server._session.put elif put: method = self.Plex._server._session.put
else: method = None else: method = None
self.Plex._server.query(key, method=method) self.Plex._server.query(key, method=method)
return self.Plex._server.query(key, method=method)
def smart_label_url(self, title, sort): def smart_label_url(self, title, sort):
labels = self.get_labels() labels = self.get_labels()
@ -558,6 +559,26 @@ class Plex:
smart_filter = self.get_collection(collection).content smart_filter = self.get_collection(collection).content
return smart_filter[smart_filter.index("?"):] 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): def get_collection(self, data):
if isinstance(data, int): if isinstance(data, int):
collection = self.fetchItem(data) collection = self.fetchItem(data)

Loading…
Cancel
Save