Skip to content

Commit

Permalink
Reduce some log levels, fix custom mapping logic
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
reconman committed Dec 9, 2023
1 parent 789e955 commit 583981c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
42 changes: 26 additions & 16 deletions plexanisync/anilist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions plexanisync/custom_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions plexanisync/plexmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 583981c

Please sign in to comment.