From 583981c44cc668666a5efcd0644c6247c8d789f8 Mon Sep 17 00:00:00 2001 From: reconman Date: Sat, 9 Dec 2023 01:18:40 +0100 Subject: [PATCH] Reduce some log levels, fix custom mapping logic - Some spammy messages were moved to debug log level - When 1 season was mapped to multiple entries, PAS calculated incorrect episodes for the first few entries - Anilist is skipped for entries with custom mappings where the episode count is the same --- plexanisync/anilist.py | 42 +++++++++++++++++++++------------- plexanisync/custom_mappings.py | 4 ++-- plexanisync/plexmodule.py | 4 ++-- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/plexanisync/anilist.py b/plexanisync/anilist.py index fc63aab2..0e0ce8a7 100644 --- a/plexanisync/anilist.py +++ b/plexanisync/anilist.py @@ -446,17 +446,24 @@ def __add_or_update_show_by_id( ): series = self.__find_mapped_series(anilist_series, anime_id) if series: - logger.info( - f"Updating series: {series.title_english} | Episodes watched: {watched_episodes}" - ) - self.__update_entry( - plex_title, - plex_year, - watched_episodes, - [series], - skip_year_check, - plex_rating - ) + if series.progress < watched_episodes: + logger.info( + f"Updating series: {series.title_english} | Episodes watched: {watched_episodes}" + ) + self.__update_entry( + plex_title, + plex_year, + watched_episodes, + [series], + skip_year_check, + plex_rating + ) + elif series.progress == watched_episodes: + logger.debug("Episodes watched was the same on AniList and Plex so skipping update") + else: + logger.debug( + f"Episodes watched was higher on AniList [{series.progress}] than on Plex [{watched_episodes}] so skipping update" + ) else: logger.warning( f"Adding new series id to list: {anime_id} | Episodes watched: {watched_episodes}" @@ -506,7 +513,7 @@ def __update_entry( ) self.graphql.update_score(series.anilist_id, plex_rating) else: - logger.info( + logger.debug( "Series is already marked as completed on AniList so skipping update" ) return @@ -587,7 +594,7 @@ def __update_entry( ) self.graphql.update_score(series.anilist_id, plex_rating) else: - logger.info( + logger.debug( "Episodes watched was the same on AniList and Plex so skipping update" ) return @@ -620,7 +627,7 @@ def __update_entry( ) self.graphql.update_score(series.anilist_id, plex_rating) else: - logger.info( + logger.debug( f"Episodes watched was higher on AniList [{anilist_episodes_watched}] than on Plex [{watched_episode_count}] so skipping update" ) elif anilist_total_episodes <= 0: @@ -660,9 +667,12 @@ def __map_watchcount_to_seasons( total_mapped_episodes = 0 season = season_mappings[0].season - for mapping in season_mappings: + # sort mappings so the one with the highest start comes first + sorted_mapping = sorted(season_mappings, key=lambda x: x.start, reverse=True) + + for mapping in sorted_mapping: if watched_episodes >= mapping.start: - episodes_in_season = watched_episodes - mapping.start + 1 + episodes_in_season = watched_episodes - mapping.start - total_mapped_episodes + 1 total_mapped_episodes += episodes_in_season episodes_in_anilist_entry[mapping.anime_id] = episodes_in_season diff --git a/plexanisync/custom_mappings.py b/plexanisync/custom_mappings.py index 124494cf..b387a782 100644 --- a/plexanisync/custom_mappings.py +++ b/plexanisync/custom_mappings.py @@ -148,13 +148,13 @@ def __add_mappings(custom_mappings, mapping_location, file_mappings): season = file_season['season'] anilist_id = file_season['anilist-id'] start = file_season.get('start', 1) - logger.info( + logger.debug( f"Adding custom mapping from {mapping_location} " f"| title: {series_title} | season: {season} | anilist id: {anilist_id}" ) series_mappings.append(AnilistCustomMapping(season, anilist_id, start)) if synonyms: - logger.info(f"{series_title} has synonyms: {synonyms}") + logger.debug(f"{series_title} has synonyms: {synonyms}") for title in [series_title] + synonyms: title_lower = title.lower() if title_lower in custom_mappings: diff --git a/plexanisync/plexmodule.py b/plexanisync/plexmodule.py index 60fcb4a9..552f02a5 100644 --- a/plexanisync/plexmodule.py +++ b/plexanisync/plexmodule.py @@ -164,7 +164,7 @@ def get_anime_shows_filter(self, show_name): return shows_filtered def get_watched_shows(self, shows: List[Show]) -> Optional[List[PlexWatchedSeries]]: - logger.info("Retrieving watch count for series") + logger.debug("Retrieving watch count for series") watched_series: List[PlexWatchedSeries] = [] ovas_found = 0 @@ -287,7 +287,7 @@ def __get_watched_episodes_for_show_season(self, season: Season) -> int: # len(watched_episodes_of_season) only works when the user didn't skip any episodes episodes_watched = max(map(lambda e: int(e.index), watched_episodes_of_season), default=0) - logger.info(f'{episodes_watched} episodes watched for {season.parentTitle} season {season.seasonNumber}') + logger.debug(f'{episodes_watched} episodes watched for {season.parentTitle} season {season.seasonNumber}') return episodes_watched def __get_first_episode_for_show_season(self, season: Season) -> int: