Skip to content

Commit

Permalink
Added match by Plex show original and sort title
Browse files Browse the repository at this point in the history
For see more see issue #24
  • Loading branch information
Rick authored and Rick committed Apr 24, 2020
1 parent ae3c949 commit 149b835
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
30 changes: 28 additions & 2 deletions anilist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
28 changes: 25 additions & 3 deletions plexmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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

Expand Down

0 comments on commit 149b835

Please sign in to comment.