diff --git a/VERSION b/VERSION index 2bd4e439..b7ef3c67 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.3-develop34 +1.18.3-develop35 diff --git a/modules/library.py b/modules/library.py index 60679d0e..8b7e6b8e 100644 --- a/modules/library.py +++ b/modules/library.py @@ -227,6 +227,16 @@ class Library(ABC): def upload_poster(self, item, image, url=False): pass + def poster_update(self, item, image, tmdb=None, title=None): + return self.image_update(item, image, tmdb=tmdb, title=title) + + def background_update(self, item, image, tmdb=None, title=None): + return self.image_update(item, image, tmdb=tmdb, title=title, poster=False) + + @abstractmethod + def image_update(self, item, image, tmdb=None, title=None, poster=True): + pass + @abstractmethod def reload(self, item, force=False): pass diff --git a/modules/operations.py b/modules/operations.py index 80db93dd..33ecbd4f 100644 --- a/modules/operations.py +++ b/modules/operations.py @@ -503,61 +503,8 @@ class Operations: name = None new_poster = None new_background = None - if self.library.mass_poster_update: - if self.library.mass_poster_update == "lock": - self.library.query(item.lockPoster) - logger.info("Poster | Locked") - elif self.library.mass_poster_update == "unlock": - self.library.query(item.unlockPoster) - logger.info("Poster | Unlocked") - else: - poster_location = "the Assets Directory" if new_poster else "" - poster_url = False if new_poster else True - new_poster = new_poster.location if new_poster else None - if not new_poster: - if self.library.mass_poster_update == "tmdb" and tmdb_item: - new_poster = tmdb_item.poster_url - poster_location = "TMDb" - if not new_poster: - poster = next((p for p in item.posters()), None) - if poster: - new_poster = f"{self.library.url}{poster.key}&X-Plex-Token={self.library.token}" - poster_location = "Plex" - if new_poster: - self.library.upload_poster(item, new_poster, url=poster_url) - logger.info(f"Poster | Reset from {poster_location}") - if "Overlay" in [la.tag for la in self.library.item_labels(item)]: - logger.info(self.library.edit_tags("label", item, remove_tags="Overlay", do_print=False)) - else: - logger.warning("Poster | No Reset Image Found") - item.reload() - - if self.library.mass_background_update: - if self.library.mass_background_update == "lock": - self.library.query(item.lockArt) - logger.info(f"Background | Locked") - elif self.library.mass_background_update == "unlock": - self.library.query(item.unlockArt) - logger.info(f"Background | Unlocked") - else: - background_location = "the Assets Directory" if new_background else "" - background_url = False if new_background else True - new_background = new_background.location if new_background else None - if not new_background: - if self.library.mass_background_update == "tmdb" and tmdb_item: - new_background = tmdb_item.backdrop_url - background_location = "TMDb" - if not new_background: - background = next((p for p in item.arts()), None) - if background: - new_background = f"{self.library.url}{background.key}&X-Plex-Token={self.library.token}" - background_location = "Plex" - if new_background: - self.library.upload_background(item, new_background, url=background_url) - logger.info(f"Background | Reset from {background_location}") - else: - logger.warning(f"Background | No Reset Image Found") - item.reload() + self.library.poster_update(item, new_poster, tmdb=tmdb_item.poster_url) + self.library.background_update(item, new_background, tmdb=tmdb_item.backdrop_url) if self.library.is_show: real_show = tmdb_item.load_show() if tmdb_item else None @@ -568,56 +515,10 @@ class Operations: except Failed: season_poster = None season_background = None + tmdb_poster = tmdb_seasons[season.seasonNumber].poster_url if season.seasonNumber in tmdb_seasons else None + self.library.poster_update(season, season_poster, tmdb=tmdb_poster, title=season.title) + self.library.background_update(season, season_background, title=season.title) - if self.library.mass_poster_update: - if self.library.mass_poster_update == "lock": - self.library.query(season.lockPoster) - logger.info(f"{season.title} Poster | Locked") - elif self.library.mass_poster_update == "unlock": - self.library.query(season.unlockPoster) - logger.info(f"{season.title} Poster | Unlocked") - else: - poster_location = "the Assets Directory" if season_poster else "" - poster_url = False if season_poster else True - season_poster = season_poster.location if season_poster else None - if not season_poster: - if self.library.mass_poster_update == "tmdb" and season.seasonNumber in tmdb_seasons: - season_poster = tmdb_seasons[season.seasonNumber].poster_url - poster_location = "TMDb" - if not season_poster: - poster = next((p for p in season.posters()), None) - if poster: - season_poster = f"{self.library.url}{poster.key}&X-Plex-Token={self.library.token}" - poster_location = "Plex" - if season_poster: - self.library.upload_poster(season, season_poster, url=poster_url) - logger.info(f"{season.title} Poster | Reset from {poster_location}") - if "Overlay" in [la.tag for la in self.library.item_labels(season)]: - logger.info(self.library.edit_tags("label", season, remove_tags="Overlay", do_print=False)) - else: - logger.warning(f"{season.title} Poster | No Reset Image Found") - item.reload() - if self.library.mass_background_update: - if self.library.mass_background_update == "lock": - self.library.query(season.lockArt) - logger.info(f"{season.title} Background | Locked") - elif self.library.mass_background_update == "unlock": - self.library.query(season.unlockArt) - logger.info(f"{season.title} Background | Unlocked") - else: - background_location = "the Assets Directory" if season_background else "" - background_url = False if season_background else True - season_background = season_background.location if season_background else None - if not season_background: - background = next((p for p in item.arts()), None) - if background: - season_background = f"{self.library.url}{background.key}&X-Plex-Token={self.library.token}" - background_location = "Plex" - if season_background: - self.library.upload_background(item, season_background, url=background_url) - logger.info(f"{season.title} Background | Reset from {background_location}") - else: - logger.warning(f"{season.title} Background | No Reset Image Found") tmdb_episodes = {} if season.seasonNumber in tmdb_seasons: for episode in tmdb_seasons[season.seasonNumber].episodes: @@ -632,57 +533,9 @@ class Operations: except Failed: episode_poster = None episode_background = None - - if self.library.mass_poster_update: - if self.library.mass_poster_update == "lock": - self.library.query(episode.lockPoster) - logger.info(f"{episode.title} Poster | Locked") - elif self.library.mass_poster_update == "unlock": - self.library.query(episode.unlockPoster) - logger.info(f"{episode.title} Poster | Unlocked") - else: - poster_location = "the Assets Directory" if episode_poster else "" - poster_url = False if episode_poster else True - episode_poster = episode_poster.location if episode_poster else None - if not episode_poster: - if self.library.mass_poster_update == "tmdb" and episode.episodeNumber in tmdb_episodes: - episode_poster = tmdb_episodes[episode.episodeNumber].still_url - poster_location = "TMDb" - if not episode_poster: - poster = next((p for p in episode.posters()), None) - if poster: - episode_poster = f"{self.library.url}{poster.key}&X-Plex-Token={self.library.token}" - poster_location = "Plex" - if episode_poster: - self.library.upload_poster(episode, episode_poster, url=poster_url) - logger.info(f"{episode.title} Poster | Reset from {poster_location}") - if "Overlay" in [la.tag for la in self.library.item_labels(episode)]: - logger.info(self.library.edit_tags("label", episode, remove_tags="Overlay", do_print=False)) - else: - logger.warning(f"{episode.title} Poster | No Reset Image Found") - item.reload() - if self.library.mass_background_update: - if self.library.mass_background_update == "lock": - self.library.query(episode.lockArt) - logger.info(f"{episode.title} Background | Locked") - elif self.library.mass_background_update == "unlock": - self.library.query(episode.unlockArt) - logger.info(f"{episode.title} Background | Unlocked") - else: - background_location = "the Assets Directory" if episode_background else "" - background_url = False if episode_background else True - episode_background = episode_background.location if episode_background else None - if not episode_background: - background = next((p for p in item.arts()), None) - if background: - episode_background = f"{self.library.url}{background.key}&X-Plex-Token={self.library.token}" - background_location = "Plex" - if episode_background: - self.library.upload_background(item, episode_background, url=background_url) - logger.info(f"{episode.title} Background | Reset from {background_location}") - else: - logger.warning(f"{episode.title} Background | No Reset Image Found") - item.reload() + tmdb_poster = tmdb_episodes[episode.episodeNumber].still_url if episode.episodeNumber in tmdb_episodes else None + self.library.poster_update(episode, episode_poster, tmdb=tmdb_poster, title=episode.title) + self.library.background_update(episode, episode_background, title=episode.title) episode_ops = [self.library.mass_episode_audience_rating_update, self.library.mass_episode_critic_rating_update, self.library.mass_episode_user_rating_update] diff --git a/modules/plex.py b/modules/plex.py index f7cdc5eb..35c9dd12 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -1067,6 +1067,44 @@ class Plex(Library): logger.info(final) return final[28:] if final else final + def image_update(self, item, image, tmdb=None, title=None, poster=True): + text = f"{f'{title} ' if title else ''}{'Poster' if poster else 'Background'}" + attr = self.mass_poster_update if poster else self.mass_background_update + if attr == "lock": + self.query(item.lockPoster if poster else item.lockArt) + logger.info(f"{text} | Locked") + elif attr == "unlock": + self.query(item.unlockPoster if poster else item.unlockArt) + logger.info(f"{text} | Unlocked") + else: + location = "the Assets Directory" if image else "" + image_url = False if image else True + image = image.location if image else None + if not image: + if attr == "tmdb" and tmdb: + image = tmdb + location = "TMDb" + if not image: + images = item.posters() if poster else item.arts() + temp_image = next((p for p in images), None) + if temp_image: + if temp_image.key.startswith("/"): + image = f"{self.url}{temp_image.key}&X-Plex-Token={self.token}" + else: + image = temp_image.key + location = "Plex" + if image: + logger.info(f"{text} | Reset from {location}") + if poster: + self.upload_poster(item, image, url=image_url) + else: + self.upload_background(item, image, url=image_url) + if poster and "Overlay" in [la.tag for la in self.item_labels(item)]: + logger.info(self.edit_tags("label", item, remove_tags="Overlay", do_print=False)) + else: + logger.warning(f"{text} | No Reset Image Found") + item.reload() + def item_images(self, item, group, alias, initial=False, asset_location=None, asset_directory=None, title=None, image_name=None, folder_name=None): if title is None: title = item.title