fixed playlist removal and various other bugs

pull/528/head
meisnate12 3 years ago
parent a5a27d25da
commit 856b96f819

@ -524,7 +524,7 @@ class CollectionBuilder:
raise Failed(f"{self.Type} Error: sort_by attribute is blank")
else:
logger.debug(f"Value: {self.data[methods['sort_by']]}")
if (self.library.is_movie and self.data[methods["sort_by"]] not in plex.movie_sorts) or (self.library.is_show and self.data[methods["sort_by"]] in plex.show_sorts):
if (self.library.is_movie and self.data[methods["sort_by"]] not in plex.movie_sorts) or (self.library.is_show and self.data[methods["sort_by"]] not in plex.show_sorts):
raise Failed(f"{self.Type} Error: sort_by attribute {self.data[methods['sort_by']]} invalid")
else:
self.sort_by = self.data[methods["sort_by"]]
@ -1747,13 +1747,13 @@ class CollectionBuilder:
self.library.alter_collection(item, name, smart_label_collection=self.smart_label_collection)
amount_added += 1
if self.details["collection_changes_webhooks"]:
if self.library.is_movie and item.ratingKey in self.library.movie_rating_key_map:
if item.ratingKey in self.library.movie_rating_key_map:
add_id = self.library.movie_rating_key_map[item.ratingKey]
elif self.library.is_show and item.ratingKey in self.library.show_rating_key_map:
elif item.ratingKey in self.library.show_rating_key_map:
add_id = self.library.show_rating_key_map[item.ratingKey]
else:
add_id = None
self.notification_additions.append({"title": item.title, "id": add_id})
self.notification_additions.append(util.item_set(item, add_id))
if self.playlist and playlist_adds and not self.obj:
self.obj = self.library.create_playlist(self.name, playlist_adds)
logger.info("")
@ -1782,14 +1782,15 @@ class CollectionBuilder:
self.library.alter_collection(item, self.name, smart_label_collection=self.smart_label_collection, add=False)
amount_removed += 1
if self.details["collection_changes_webhooks"]:
if self.library.is_movie and item.ratingKey in self.library.movie_rating_key_map:
if item.ratingKey in self.library.movie_rating_key_map:
remove_id = self.library.movie_rating_key_map[item.ratingKey]
elif self.library.is_show and item.ratingKey in self.library.show_rating_key_map:
elif item.ratingKey in self.library.show_rating_key_map:
remove_id = self.library.show_rating_key_map[item.ratingKey]
else:
remove_id = None
self.notification_removals.append({"title": item.title, "id": remove_id})
self.notification_removals.append(util.item_set(item, remove_id))
if self.playlist and playlist_removes:
self.obj.reload()
self.obj.removeItems(playlist_removes)
if amount_removed > 0:
logger.info("")
@ -2315,8 +2316,8 @@ class CollectionBuilder:
self.library.Webhooks.collection_hooks(
self.details["collection_changes_webhooks"],
self.obj,
poster_url=self.collection_poster.location if self.collection_poster.is_url else None,
background_url=self.collection_background.location if self.collection_background.is_url else None,
poster_url=self.collection_poster.location if self.collection_poster and self.collection_poster.is_url else None,
background_url=self.collection_background.location if self.collection_background and self.collection_background.is_url else None,
created=self.created,
deleted=self.deleted,
additions=self.notification_additions,
@ -2358,7 +2359,7 @@ class CollectionBuilder:
add_id = self.library.show_rating_key_map[current.ratingKey]
else:
add_id = None
self.notification_additions.append({"title": current.title, "id": add_id})
self.notification_additions.append(util.item_set(current, add_id))
self.send_notifications()
logger.info(f"{len(rating_keys)} {self.collection_level.capitalize()}{'s' if len(rating_keys) > 1 else ''} Processed")

@ -99,6 +99,7 @@ class ConfigFile:
if "settings" in new_config: new_config["settings"] = new_config.pop("settings")
if "webhooks" in new_config:
temp = new_config.pop("webhooks")
if "collection_changes" not in temp:
changes = []
def hooks(attr):
if attr in temp:
@ -147,9 +148,9 @@ class ConfigFile:
elif attribute not in loaded_config[parent]: loaded_config[parent][attribute] = default
else: endline = ""
yaml.round_trip_dump(loaded_config, open(self.config_path, "w"), indent=None, block_seq_indent=2)
if default_is_none and var_type in ["list", "int_list"]: return []
if default_is_none and var_type in ["list", "int_list"]: return default if default else []
elif data[attribute] is None:
if default_is_none and var_type in ["list", "int_list"]: return []
if default_is_none and var_type in ["list", "int_list"]: return default if default else []
elif default_is_none: return None
else: message = f"{text} is blank"
elif var_type == "url":
@ -512,7 +513,7 @@ class ConfigFile:
params["ignore_imdb_ids"] = check_for_attribute(lib, "ignore_imdb_ids", parent="settings", var_type="list", default_is_none=True, do_print=False, save=False)
params["ignore_imdb_ids"].extend([i for i in self.general["ignore_imdb_ids"] if i not in params["ignore_imdb_ids"]])
params["error_webhooks"] = check_for_attribute(lib, "error", parent="webhooks", var_type="list", default=self.webhooks["error"], do_print=False, save=False, default_is_none=True)
params["collection_changes_webhooks"] = check_for_attribute(lib, "collection_creation", parent="webhooks", var_type="list", default=self.webhooks["collection_changes"], do_print=False, save=False, default_is_none=True)
params["collection_changes_webhooks"] = check_for_attribute(lib, "collection_changes", parent="webhooks", var_type="list", default=self.webhooks["collection_changes"], do_print=False, save=False, default_is_none=True)
params["assets_for_all"] = check_for_attribute(lib, "assets_for_all", parent="settings", var_type="bool", default=self.general["assets_for_all"], do_print=False, save=False)
params["mass_genre_update"] = check_for_attribute(lib, "mass_genre_update", test_list=mass_update_options, default_is_none=True, save=False, do_print=False)
params["mass_audience_rating_update"] = check_for_attribute(lib, "mass_audience_rating_update", test_list=mass_update_options, default_is_none=True, save=False, do_print=False)

@ -259,6 +259,9 @@ def item_title(item):
else:
return item.title
def item_set(item, item_id):
return {"title": item_title(item), "tmdb" if isinstance(item, Movie) else "tvdb": item_id}
def is_locked(filepath):
locked = None
file_object = None

@ -79,22 +79,18 @@ class Webhooks:
if not poster_url and collection.thumb and next((f for f in collection.fields if f.name == "thumb"), None):
thumb = self.config.get_image_encoded(f"{self.library.url}{collection.thumb}?X-Plex-Token={self.library.token}")
art = None
if not background_url and collection.art and next((f for f in collection.fields if f.name == "art"), None):
if not playlist and not background_url and collection.art and next((f for f in collection.fields if f.name == "art"), None):
art = self.config.get_image_encoded(f"{self.library.url}{collection.art}?X-Plex-Token={self.library.token}")
json = {
self._request(webhooks, {
"server_name": self.library.PlexServer.friendlyName,
"library_name": self.library.name,
"type": "movie" if self.library.is_movie else "show",
"playlist" if playlist else "collection": collection.title,
"created": created,
"deleted": deleted,
"poster": thumb,
"background": art,
"poster_url": poster_url,
"background_url": background_url
}
if additions:
json["additions"] = additions
if removals:
json["removals"] = removals
self._request(webhooks, json)
"background_url": background_url,
"additions": additions if additions else [],
"removals": removals if removals else [],
})

@ -545,7 +545,7 @@ def update_libraries(config):
if builder.custom_sort:
builder.sort_collection()
builder.send_notifications()
builder.send_notifications(playlist=True)

Loading…
Cancel
Save