[51] remove old original posters if an asset is found

pull/1300/head
meisnate12 2 years ago
parent 16017a13a4
commit edc7781bd8

@ -1 +1 @@
1.18.3-develop50 1.18.3-develop51

@ -155,6 +155,10 @@ class Overlays:
if poster: if poster:
if image_compare and str(poster.compare) != str(image_compare): if image_compare and str(poster.compare) != str(image_compare):
changed_image = True changed_image = True
if os.path.exists(os.path.join(self.library.overlay_backup, f"{item.ratingKey}.png")):
os.remove(os.path.join(self.library.overlay_backup, f"{item.ratingKey}.png"))
if os.path.exists(os.path.join(self.library.overlay_backup, f"{item.ratingKey}.jpg")):
os.remove(os.path.join(self.library.overlay_backup, f"{item.ratingKey}.jpg"))
elif has_overlay: elif has_overlay:
if os.path.exists(os.path.join(self.library.overlay_backup, f"{item.ratingKey}.png")): if os.path.exists(os.path.join(self.library.overlay_backup, f"{item.ratingKey}.png")):
has_original = os.path.join(self.library.overlay_backup, f"{item.ratingKey}.png") has_original = os.path.join(self.library.overlay_backup, f"{item.ratingKey}.png")
@ -530,13 +534,11 @@ class Overlays:
except Failed: except Failed:
poster = None poster = None
is_url = False is_url = False
original = None
poster_location = None poster_location = None
if poster: if poster:
poster_location = poster.location poster_location = poster.location
elif any([os.path.exists(loc) for loc in locations]): elif any([os.path.exists(loc) for loc in locations]):
original = next((loc for loc in locations if os.path.exists(loc))) poster_location = next((loc for loc in locations if os.path.exists(loc)))
poster_location = original
if not poster_location: if not poster_location:
is_url = True is_url = True
try: try:
@ -546,7 +548,8 @@ class Overlays:
if poster_location: if poster_location:
self.library.upload_poster(item, poster_location, url=is_url) self.library.upload_poster(item, poster_location, url=is_url)
self.library.edit_tags("label", item, remove_tags=[label], do_print=False) self.library.edit_tags("label", item, remove_tags=[label], do_print=False)
if original: for loc in locations:
os.remove(original) if os.path.exists(loc):
os.remove(loc)
else: else:
logger.error(f"No Poster found to restore for {item_title}") logger.error(f"No Poster found to restore for {item_title}")

Loading…
Cancel
Save