Skip to content

Commit

Permalink
simplify for time test
Browse files Browse the repository at this point in the history
  • Loading branch information
cmathews393 committed Sep 2, 2024
1 parent d9abb8f commit 2b3a0f5
Showing 1 changed file with 33 additions and 53 deletions.
86 changes: 33 additions & 53 deletions spotiplex/modules/plex/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,61 +44,41 @@ def match_spotify_tracks_in_plex(
artist_tracks_in_plex = music_library.search(
title=artist_name.replace("'", ""),
)
if not artist_tracks_in_plex:
logger.debug(f"No results found for artist: {artist_name}")
missing_tracks.append((track_name, artist_name))
continue
logger.debug(f"No results found for artist: {artist_name}")
missing_tracks.append((track_name, artist_name))
continue

try:
plex_track = next(
(
track.track(title=track_name)
for track in artist_tracks_in_plex
if track.track(title=track_name)
),
None,
)
except NotFound:
logger.debug(
f"Track '{track_name}' by '{artist_name}' not found in Plex.",
)
plex_track = None
except (Exception, BadRequest) as plex_search_exception:
logger.debug(
f"Exception trying to search for artist '{artist_name}', track '{track_name}': {plex_search_exception}",
)
plex_track = None

if not plex_track:
try:
track_name_no_apostrophe = track_name.replace("'", "")
plex_track = next(
(
track.track(title=track_name_no_apostrophe)
for track in artist_tracks_in_plex
if track.track(title=track_name_no_apostrophe)
),
None,
)
except NotFound:
logger.debug(
f"Track '{track_name}' by '{artist_name}' not found in Plex.",
)
plex_track = None
except (Exception, BadRequest) as plex_search_exception:
logger.debug(
f"Exception trying to search for artist '{artist_name}', track '{track_name}': {plex_search_exception}",
)
plex_track = None
logger.debug("Song not in Plex!")
logger.debug(
f"Found artists for '{artist_name}' ({len(artist_tracks_in_plex)})",
)
logger.debug(f"Attempted to match song '{track_name}', but could not!")
missing_tracks.append((track_name, artist_name))
try:
track_name_no_apostrophe = track_name.replace("'", "")
plex_track = next(
(
track.track(title=track_name_no_apostrophe)
for track in artist_tracks_in_plex
if track.track(title=track_name_no_apostrophe)
),
None,
)
except NotFound:
logger.debug(
f"Track '{track_name}' by '{artist_name}' not found in Plex.",
)
plex_track = None
except (Exception, BadRequest) as plex_search_exception:
logger.debug(
f"Exception trying to search for artist '{artist_name}', track '{track_name}': {plex_search_exception}",
)
plex_track = None

else:
matched_tracks.append(plex_track)
if not plex_track:
logger.debug("Song not in Plex!")
logger.debug(
f"Found artists for '{artist_name}' ({len(artist_tracks_in_plex)})",
)
logger.debug(f"Attempted to match song '{track_name}', but could not!")
missing_tracks.append((track_name, artist_name))

else:
matched_tracks.append(plex_track)

success_percentage = (
(len(matched_tracks) / total_tracks) * 100 if total_tracks else 0
Expand Down

0 comments on commit 2b3a0f5

Please sign in to comment.