Skip to content

Commit

Permalink
Handle title mismatches on Plex for titles with commas
Browse files Browse the repository at this point in the history
Implements fix for #327
  • Loading branch information
CollinHeist committed Apr 17, 2023
1 parent fe71d30 commit f7c0932
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
19 changes: 15 additions & 4 deletions modules/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def create_shows(self) -> None:
def assign_interfaces(self) -> None:
"""Assign all interfaces to each Show known to this Manager"""

for show in tqdm(self.shows + self.archives,
desc='Assigning interfaces',
# Assign interfaces for each show
for show in tqdm(self.shows + self.archives,desc='Assigning interfaces',
**TQDM_KWARGS):
show.assign_interfaces(
self.emby_interface,
Expand All @@ -198,8 +198,10 @@ def assign_interfaces(self) -> None:
def set_show_ids(self) -> None:
"""Set the series ID's of each Show known to this Manager"""

# For each show in the Manager, set series IDs
for show in tqdm(self.shows + self.archives, desc='Setting series IDs',
**TQDM_KWARGS):
# Select interfaces based on what's enabled
show.set_series_ids()


Expand All @@ -211,6 +213,7 @@ def read_show_source(self) -> None:
multipart episodes.
"""

# Read source files for Show objects
for show in (pbar := tqdm(self.shows + self.archives, **TQDM_KWARGS)):
pbar.set_description(f'Reading source files for {show}')
show.read_source()
Expand All @@ -221,6 +224,8 @@ def read_show_source(self) -> None:
def add_new_episodes(self) -> None:
"""Add any new episodes to this Manager's shows."""

# For each show in the Manager, look for new episodes using any of the
# possible interfaces
for show in (pbar := tqdm(self.shows + self.archives, **TQDM_KWARGS)):
pbar.set_description(f'Adding new episodes for {show}')
show.add_new_episodes()
Expand All @@ -230,6 +235,7 @@ def add_new_episodes(self) -> None:
def set_episode_ids(self) -> None:
"""Set all episode ID's for all shows."""

# For each show in the Manager, set IDs for every episode
for show in (pbar := tqdm(self.shows + self.archives, **TQDM_KWARGS)):
pbar.set_description(f'Setting episode IDs for {show}')
show.set_episode_ids()
Expand All @@ -243,6 +249,7 @@ def add_translations(self) -> None:
if not self.preferences.use_tmdb:
return None

# For each show in the Manager, add translation
for show in (pbar := tqdm(self.shows + self.archives, **TQDM_KWARGS)):
pbar.set_description(f'Adding translations for {show}')
show.add_translations()
Expand All @@ -256,6 +263,7 @@ def download_logos(self) -> None:
if not self.preferences.use_tmdb:
return None

# For each show in the Manager, download a logo
for show in (pbar := tqdm(self.shows + self.archives, **TQDM_KWARGS)):
pbar.set_description(f'Downloading logo for {show}')
show.download_logo()
Expand All @@ -265,6 +273,7 @@ def download_logos(self) -> None:
def select_source_images(self) -> None:
"""Select and download the source images for all shows."""

# Go through each show and download source images
for show in (pbar := tqdm(self.shows + self.archives, **TQDM_KWARGS)):
pbar.set_description(f'Selecting sources for {show}')
show.select_source_images()
Expand All @@ -274,6 +283,7 @@ def select_source_images(self) -> None:
def create_missing_title_cards(self) -> None:
"""Creates all missing title cards for all shows."""

# Go through every show in the Manager, create cards
for show in (pbar := tqdm(self.shows, **TQDM_KWARGS)):
pbar.set_description(f'Creating cards for {show}')
show.create_missing_title_cards()
Expand All @@ -283,6 +293,7 @@ def create_missing_title_cards(self) -> None:
def create_season_posters(self) -> None:
"""Create season posters for all shows."""

# For each show in the Manager, create its posters
for show in tqdm(self.shows + self.archives,
desc='Creating season posters',**TQDM_KWARGS):
show.create_season_posters()
Expand All @@ -295,13 +306,13 @@ def update_media_server(self) -> None:
if Emby/Jellyfin/Plex are globally enabled.
"""

# If no media servers aren't enabled, skip
# If no media servers are enabled, skip
if (not self.preferences.use_emby
and not self.preferences.use_jellyfin
and not self.preferences.use_plex):
return None

# Go through each show in the Manager, update the server
# Go through each show in the Manager, update Plex
for show in (pbar := tqdm(self.shows, **TQDM_KWARGS)):
pbar.set_description(f'Updating Server for {show}')
show.update_media_server()
Expand Down
50 changes: 23 additions & 27 deletions modules/PlexInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def __get_library(self, library_name: str) -> 'Library':
def __get_series(self, library: 'Library',
series_info: SeriesInfo) -> 'Show':
"""
Get the Series object from within the given Library associated with the
given SeriesInfo. This tries to match by TVDb ID, TMDb ID, name, and
finally full name.
Get the Series object from within the given Library associated
with the given SeriesInfo. This tries to match by TVDb ID,
TMDb ID, name, and finally name.
Args:
library: The Library object to search for within Plex.
Expand Down Expand Up @@ -176,33 +176,27 @@ def __get_series(self, library: 'Library',
except NotFound:
pass

# Try by full name
# Try by name
try:
series = library.get(series_info.full_name)
if series.year == series_info.year:
return series
raise NotFound
for series in library.search(title=series_info.name,
year=series_info.year, libtype='show'):
if series.title in (series_info.name, series_info.full_name):
return series
except NotFound:
pass

# Try by name and match the year
try:
if (ser := library.get(series_info.name)).year == series_info.year:
return ser
raise NotFound
except NotFound:
key = f'{library.title}-{series_info.full_name}'
if key not in self.__warned:
log.warning(f'Series "{series_info}" was not found under '
f'library "{library.title}" in Plex')
self.__warned.add(key)

return None
# Not found, return None
key = f'{library.title}-{series_info.full_name}'
if key not in self.__warned:
log.warning(f'Series "{series_info}" was not found under '
f'library "{library.title}" in Plex')
self.__warned.add(key)

return None

@catch_and_log('Error getting library paths', default={})
def get_library_paths(self,filter_libraries: list[str]=[]
) -> dict[str, list[str]]:
def get_library_paths(self,
filter_libraries: list[str] = []) -> dict[str, list[str]]:
"""
Get all libraries and their associated base directories.
Expand Down Expand Up @@ -382,8 +376,8 @@ def has_series(self, library_name: str, series_info: 'SeriesInfo') -> bool:
Determine whether the given series is present within Plex.
Args:
library_name: The name of the library potentially containing the
series.
library_name: The name of the library potentially containing
the series.
series_info: The series to being evaluated.
Returns:
Expand Down Expand Up @@ -496,8 +490,10 @@ def set_series_ids(self, library_name: str,


@catch_and_log("Error setting episode ID's")
def set_episode_ids(self, library_name: str, series_info: SeriesInfo,
infos: list[EpisodeInfo]) -> None:
def set_episode_ids(self,
library_name: str,
series_info: SeriesInfo,
infos: list[EpisodeInfo]) -> None:
"""
Set all the episode ID's for the given list of EpisodeInfo objects. This
sets the Sonarr and TVDb ID's for each episode. As a byproduct, this
Expand Down
3 changes: 1 addition & 2 deletions modules/cards/AnimeTitleCard.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class AnimeTitleCard(BaseCardType):
"""
This class describes a type of CardType that produces title cards in
the anime-styled cards designed by reddit user /u/Recker_Man. These
cards don't support custom fonts, but does support optional kanji
text.
cards support custom fonts, and optional kanji text.
"""

"""API Parameters"""
Expand Down

0 comments on commit f7c0932

Please sign in to comment.