From 149b835ad3bd62f4979ab67250b0b12a8a565d55 Mon Sep 17 00:00:00 2001 From: Rick Date: Fri, 24 Apr 2020 22:04:53 +0200 Subject: [PATCH] Added match by Plex show original and sort title For see more see issue #24 --- anilist.py | 30 ++++++++++++++++++++++++++++-- plexmodule.py | 28 +++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/anilist.py b/anilist.py index e74ec12..881648b 100644 --- a/anilist.py +++ b/anilist.py @@ -462,9 +462,17 @@ def match_to_plex( logger.info('[ANILIST] Matching Plex series to Anilist') for plex_series in plex_series_watched: plex_title = plex_series.title + plex_title_sort = plex_series.title_sort + plex_title_original = plex_series.title_original plex_title_clean = re.sub( '[^A-Za-z0-9]+', '', plex_title.lower().strip()) + plex_title_sort_clean = re.sub( + '[^A-Za-z0-9]+', '', plex_title_sort.lower().strip()) + plex_title_original_clean = re.sub( + '[^A-Za-z0-9]+', '', plex_title_original.lower().strip()) plex_title_clean_without_year = plex_title_clean + plex_title_sort_clean_without_year = plex_title_sort_clean + plex_title_original_clean_without_year = plex_title_original_clean plex_watched_episode_count = plex_series.episodes_watched plex_year = plex_series.year plex_total_seasons = plex_series.total_seasons @@ -475,18 +483,36 @@ def match_to_plex( yearString = '(%s)' % (year) plex_title_clean_without_year = plex_title.replace( yearString, '').strip() + if '(' in plex_title_sort and ')' in plex_title_sort: + year = re.search(r"(\d{4})", plex_title_sort).group(1) + yearString = '(%s)' % (year) + plex_title_sort_clean_without_year = plex_title_sort.replace( + yearString, '').strip() + if '(' in plex_title_original and ')' in plex_title_original: + year = re.search(r"(\d{4})", plex_title_original).group(1) + yearString = '(%s)' % (year) + plex_title_original_clean_without_year = plex_title_original.replace( + yearString, '').strip() except BaseException: pass found_match = False skip_year_check = False matched_anilist_series = [] - + potential_titles = [ plex_title.lower(), + plex_title_sort, + plex_title_original, guessit(plex_title)['title'].lower(), + guessit(plex_title_sort)['title'].lower(), + guessit(plex_title_original)['title'].lower(), plex_title_clean, - plex_title_clean_without_year] + plex_title_sort_clean, + plex_title_original_clean, + plex_title_clean_without_year, + plex_title_sort_clean_without_year, + plex_title_original_clean_without_year] logger.info('--------------------------------------------------') if(plex_total_seasons == 1): diff --git a/plexmodule.py b/plexmodule.py index e09c4f8..94d3a03 100644 --- a/plexmodule.py +++ b/plexmodule.py @@ -18,9 +18,11 @@ class plex_watched_series: - def __init__(self, title, year, episodes_watched, total_seasons): + def __init__(self, title, title_sort, title_original, year, episodes_watched, total_seasons): self.series_id = id self.title = title + self.title_sort = title_sort + self.title_original = title_original self.year = year self.episodes_watched = episodes_watched self.total_seasons = total_seasons @@ -180,9 +182,19 @@ def get_watched_shows(shows): year = 1900 if show.year: year = show.year + + if not hasattr(show, 'titleSort'): + show.titleSort = show.title + elif show.titleSort == '': + show.titleSort = show.title + + if not hasattr(show, 'originalTitle'): + show.originalTitle = show.title + elif show.originalTitle == '': + show.originalTitle = show.title watched_show = plex_watched_series( - show.title.strip(), year, episodes_watched, season_total) + show.title.strip(), show.titleSort.strip(), show.originalTitle.strip(), year, episodes_watched, season_total) watched_series.append(watched_show) # logger.info( @@ -199,8 +211,18 @@ def get_watched_shows(shows): if show.year: year = show.year + if not hasattr(show, 'titleSort'): + show.titleSort = show.title + elif show.titleSort == '': + show.titleSort = show.title + + if not hasattr(show, 'originalTitle'): + show.originalTitle = show.title + elif show.originalTitle == '': + show.originalTitle = show.title + watched_show = plex_watched_series( - show.title.strip(), show.year, 1, 1) + show.title.strip(), show.titleSort.strip(), show.originalTitle.strip(), show.year, 1, 1) watched_series.append(watched_show) ovas_found += 1