[157] update overlay reset

pull/1142/head
meisnate12 2 years ago
parent 7901dfb3ec
commit e61085a859

@ -1 +1 @@
1.17.3-develop156 1.17.3-develop157

@ -1,5 +1,5 @@
############################################################################## ##############################################################################
# Other Awards Collections # # Collectionless Collection #
# Created by Yozora, Bullmoose20, & Sohjiro # # Created by Yozora, Bullmoose20, & Sohjiro #
# EDITING THIS FILE MAY CAUSE PULLING NEW UPDATES TO FAIL # # EDITING THIS FILE MAY CAUSE PULLING NEW UPDATES TO FAIL #
# https://metamanager.wiki/en/latest/defaults/both/collectionless.html # # https://metamanager.wiki/en/latest/defaults/both/collectionless.html #
@ -23,10 +23,8 @@ templates:
- collection_mode - collection_mode
- exclude - exclude
url_poster: <<url_poster>> url_poster: <<url_poster>>
collection_mode: hide
collection_order: <<collection_order>> collection_order: <<collection_order>>
sort_title: <<sort_title>> sort_title: <<sort_title>>
sync_mode: sync
summary: <<summary>>> summary: <<summary>>>
name: <<name>> name: <<name>>
plex_collectionless: plex_collectionless:

@ -233,30 +233,26 @@ templates:
- rating_alignment: horizontal - rating_alignment: horizontal
horizontal_position: center horizontal_position: center
rating1: none rating1: none
value: -<<ch2_offset>> value: <<ch2_offset>>
- rating_alignment: horizontal - rating_alignment: horizontal
horizontal_position: center horizontal_position: center
rating3: none rating3: none
value: -<<ch2_offset>> value: -<<ch2_offset>>
- rating_alignment: horizontal - rating_alignment: horizontal
horizontal_position: center horizontal_position: center
value: -<<ch3_offset>> value: <<center_offset>>
- rating_alignment: horizontal - rating_alignment: horizontal
horizontal_position: right horizontal_position: right
rating1: none rating1: none
rating3: none rating3: none
value: <<standard_offset>> value: <<standard_offset>>
- rating_alignment: horizontal
horizontal_position: right
rating1: none
value: <<h2_offset>>
- rating_alignment: horizontal - rating_alignment: horizontal
horizontal_position: right horizontal_position: right
rating3: none rating3: none
value: <<h2_offset>> value: <<standard_offset>>
- rating_alignment: horizontal - rating_alignment: horizontal
horizontal_position: right horizontal_position: right
value: <<h3_offset>> value: <<h2_offset>>
- rating_alignment: horizontal - rating_alignment: horizontal
horizontal_position: left horizontal_position: left
rating1: none rating1: none

@ -232,7 +232,7 @@ libraries:
report_path: /config/reports/Movies.yml report_path: /config/reports/Movies.yml
``` ```
### Template Variables ### Library Template Variables
Library template variables to be applied to every Metadata and Overlay file run. Library template variables to be applied to every Metadata and Overlay file run.
@ -240,7 +240,7 @@ Library template variables to be applied to every Metadata and Overlay file run.
libraries: libraries:
Movies: Movies:
template_variables: template_variables:
collection_mode: true collection_mode: hide_items
``` ```
## Playlist Files Attribute ## Playlist Files Attribute

@ -21,9 +21,13 @@ The below YAML in your config.yml will create the collections:
```yaml ```yaml
libraries: libraries:
Movies: Movies:
template_variables:
collection_mode: hide_items
metadata_path: metadata_path:
- pmm: collectionless - pmm: collectionless
TV Shows: TV Shows:
template_variables:
collection_mode: hide_items
metadata_path: metadata_path:
- pmm: collectionless - pmm: collectionless
``` ```
@ -52,6 +56,8 @@ The below is an example config.yml extract with some Template Variables added in
```yaml ```yaml
libraries: libraries:
Movies: Movies:
template_variables:
collection_mode: hide_items
metadata_path: metadata_path:
- pmm: collectionless - pmm: collectionless
template_variables: template_variables:

@ -2603,8 +2603,11 @@ class CollectionBuilder:
advance_update = True advance_update = True
if "collection_filtering" in self.details: if "collection_filtering" in self.details:
try:
self.library.edit_query(self.obj, {"collectionFilterBasedOnUser": 0 if self.details["collection_filtering"] == "admin" else 1}, advanced=True) self.library.edit_query(self.obj, {"collectionFilterBasedOnUser": 0 if self.details["collection_filtering"] == "admin" else 1}, advanced=True)
advance_update = True advance_update = True
except NotFound:
logger.error("Collection Error: collection_filtering requires a more recent version of Plex Media Server")
if "collection_order" in self.details: if "collection_order" in self.details:
if int(self.obj.collectionSort) not in plex.collection_order_keys \ if int(self.obj.collectionSort) not in plex.collection_order_keys \

@ -23,9 +23,15 @@ class Overlays:
logger.info("") logger.info("")
os.makedirs(self.library.overlay_backup, exist_ok=True) os.makedirs(self.library.overlay_backup, exist_ok=True)
key_to_overlays = {}
queues = {}
properties = None
if not self.library.remove_overlays:
key_to_overlays, properties, queues = self.compile_overlays()
ignore_list = [rk for rk in key_to_overlays]
old_overlays = [la for la in self.library.Plex.listFilterChoices("label") if str(la.title).lower().endswith(" overlay")] old_overlays = [la for la in self.library.Plex.listFilterChoices("label") if str(la.title).lower().endswith(" overlay")]
if old_overlays: if old_overlays:
logger.info("")
logger.separator(f"Removing Old Overlays for the {self.library.name} Library") logger.separator(f"Removing Old Overlays for the {self.library.name} Library")
logger.info("") logger.info("")
for old_overlay in old_overlays: for old_overlay in old_overlays:
@ -40,13 +46,7 @@ class Overlays:
self.remove_overlay(item, item_title, old_overlay.title, [ self.remove_overlay(item, item_title, old_overlay.title, [
os.path.join(self.library.overlay_folder, old_overlay.title[:-8], f"{item.ratingKey}.png") os.path.join(self.library.overlay_folder, old_overlay.title[:-8], f"{item.ratingKey}.png")
]) ])
logger.info("")
key_to_overlays = {}
queues = {}
properties = None
if not self.library.remove_overlays:
key_to_overlays, properties, queues = self.compile_overlays()
ignore_list = [rk for rk in key_to_overlays]
remove_overlays = self.get_overlay_items(ignore=ignore_list) remove_overlays = self.get_overlay_items(ignore=ignore_list)
if self.library.is_show: if self.library.is_show:
@ -55,9 +55,8 @@ class Overlays:
elif self.library.is_music: elif self.library.is_music:
remove_overlays.extend(self.get_overlay_items(libtype="album", ignore=ignore_list)) remove_overlays.extend(self.get_overlay_items(libtype="album", ignore=ignore_list))
logger.info("")
if remove_overlays: if remove_overlays:
logger.separator(f"Removing Overlays for the {self.library.name} Library") logger.separator(f"Removing {'All ' if self.library.remove_overlays else ''}Overlays for the {self.library.name} Library")
for i, item in enumerate(remove_overlays, 1): for i, item in enumerate(remove_overlays, 1):
item_title = self.library.get_item_sort_title(item, atr="title") item_title = self.library.get_item_sort_title(item, atr="title")
logger.ghost(f"Restoring: {i}/{len(remove_overlays)} {item_title}") logger.ghost(f"Restoring: {i}/{len(remove_overlays)} {item_title}")
@ -70,7 +69,6 @@ class Overlays:
logger.separator(f"No Overlays to Remove for the {self.library.name} Library") logger.separator(f"No Overlays to Remove for the {self.library.name} Library")
logger.info("") logger.info("")
if not self.library.remove_overlays: if not self.library.remove_overlays:
logger.info("")
logger.separator(f"{'Re-' if self.library.reapply_overlays else ''}Applying Overlays for the {self.library.name} Library") logger.separator(f"{'Re-' if self.library.reapply_overlays else ''}Applying Overlays for the {self.library.name} Library")
logger.info("") logger.info("")
for i, (over_key, (item, over_names)) in enumerate(sorted(key_to_overlays.items(), key=lambda io: self.library.get_item_sort_title(io[1][0])), 1): for i, (over_key, (item, over_names)) in enumerate(sorted(key_to_overlays.items(), key=lambda io: self.library.get_item_sort_title(io[1][0])), 1):
@ -158,19 +156,22 @@ class Overlays:
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
elif has_overlay: elif has_overlay:
if self.library.reset_overlays is not None: if os.path.exists(os.path.join(self.library.overlay_backup, f"{item.ratingKey}.png")):
if self.library.reset_overlays == "tmdb":
new_backup = self.find_poster_url(item)
else:
posters = item.posters()
if posters:
new_backup = posters[0]
elif 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")
elif os.path.exists(os.path.join(self.library.overlay_backup, f"{item.ratingKey}.jpg")): elif os.path.exists(os.path.join(self.library.overlay_backup, f"{item.ratingKey}.jpg")):
has_original = os.path.join(self.library.overlay_backup, f"{item.ratingKey}.jpg") has_original = os.path.join(self.library.overlay_backup, f"{item.ratingKey}.jpg")
else: if self.library.reset_overlays is not None or has_original is None:
if self.library.reset_overlays == "tmdb":
try:
new_backup = self.find_poster_url(item) new_backup = self.find_poster_url(item)
except Failed as e:
logger.error(e)
else:
poster = next((p for p in item.posters() if p.provider == "local"), None)
if poster:
new_backup = f"{self.library.url}{poster.key}&X-Plex-Token={self.library.token}"
if not new_backup:
logger.error("Overlay Error: Reset Failed")
else: else:
new_backup = item.posterUrl new_backup = item.posterUrl
if new_backup: if new_backup:
@ -424,6 +425,26 @@ class Overlays:
logger.error(e) logger.error(e)
logger.info("") logger.info("")
logger.separator(f"Overlay Operation for the {self.library.name} Library")
logger.debug("")
logger.debug(f"Remove Overlays: {self.library.remove_overlays}")
logger.debug(f"Reapply Overlays: {self.library.reapply_overlays}")
logger.debug(f"Reset Overlays: {self.library.reset_overlays}")
logger.debug("")
logger.separator(f"Number of Items Per Overlay", space=False, border=False)
logger.debug("")
longest = 7
for overlay_name in properties:
if len(overlay_name) > longest:
longest = len(overlay_name)
logger.debug(f"{'Overlay':^{longest}} | Number |")
logger.debug(f"{logger.separating_character * longest} | {logger.separating_character * 6} |")
for overlay_name, over_obj in properties.items():
logger.debug(f"{overlay_name:<{longest}} | {len(over_obj.keys):^6} |")
logger.debug("")
for overlay_name, over_obj in properties.items(): for overlay_name, over_obj in properties.items():
if over_obj.group: if over_obj.group:
if over_obj.group not in overlay_groups: if over_obj.group not in overlay_groups:
@ -460,7 +481,6 @@ class Overlays:
return key_to_overlays, properties, queues return key_to_overlays, properties, queues
def find_poster_url(self, item): def find_poster_url(self, item):
try:
if isinstance(item, Movie): if isinstance(item, Movie):
if item.ratingKey in self.library.movie_rating_key_map: if item.ratingKey in self.library.movie_rating_key_map:
return self.config.TMDb.get_movie(self.library.movie_rating_key_map[item.ratingKey]).poster_url return self.config.TMDb.get_movie(self.library.movie_rating_key_map[item.ratingKey]).poster_url
@ -474,8 +494,6 @@ class Overlays:
return self.config.TMDb.get_season(tmdb_id, item.seasonNumber).poster_url return self.config.TMDb.get_season(tmdb_id, item.seasonNumber).poster_url
elif isinstance(item, Episode): elif isinstance(item, Episode):
return self.config.TMDb.get_episode(tmdb_id, item.seasonNumber, item.episodeNumber).still_url return self.config.TMDb.get_episode(tmdb_id, item.seasonNumber, item.episodeNumber).still_url
except Failed as e:
logger.error(e)
def get_overlay_items(self, label="Overlay", libtype=None, ignore=None): def get_overlay_items(self, label="Overlay", libtype=None, ignore=None):
items = self.library.search(label=label, libtype=libtype) items = self.library.search(label=label, libtype=libtype)
@ -488,14 +506,18 @@ class Overlays:
poster = None poster = None
is_url = False is_url = False
original = None original = 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))) original = next((loc for loc in locations if os.path.exists(loc)))
poster_location = original poster_location = original
else: if not poster_location:
is_url = True is_url = True
try:
poster_location = self.find_poster_url(item) poster_location = self.find_poster_url(item)
except Failed as e:
logger.error(e)
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)

Loading…
Cancel
Save