Skip to content

Commit f19e544

Browse files
committed
Lets try searching with and without apostrophe
1 parent 5960e78 commit f19e544

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

spotiplex/modules/plex/main.py

+29-6
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@ def match_spotify_tracks_in_plex(
4141
title=artist_name.replace("'", ""),
4242
)
4343
if not artist_tracks_in_plex:
44-
logger.debug(f"No results found for artist: {artist_name}")
45-
missing_tracks.append((track_name, artist_name))
46-
continue
44+
artist_tracks_in_plex = music_library.search(
45+
title=artist_name.replace("'", ""),
46+
)
47+
if not artist_tracks_in_plex:
48+
logger.debug(f"No results found for artist: {artist_name}")
49+
missing_tracks.append((track_name, artist_name))
50+
continue
4751

4852
try:
49-
track_name_no_apostrophe = track_name.replace("'", "")
5053
plex_track = next(
5154
(
52-
track.track(title=track_name_no_apostrophe)
55+
track.track(title=track_name)
5356
for track in artist_tracks_in_plex
54-
if track.track(title=track_name_no_apostrophe)
57+
if track.track(title=track_name)
5558
),
5659
None,
5760
)
@@ -67,6 +70,26 @@ def match_spotify_tracks_in_plex(
6770
plex_track = None
6871

6972
if not plex_track:
73+
try:
74+
track_name_no_apostrophe = track_name.replace("'", "")
75+
plex_track = next(
76+
(
77+
track.track(title=track_name_no_apostrophe)
78+
for track in artist_tracks_in_plex
79+
if track.track(title=track_name_no_apostrophe)
80+
),
81+
None,
82+
)
83+
except NotFound:
84+
logger.debug(
85+
f"Track '{track_name}' by '{artist_name}' not found in Plex.",
86+
)
87+
plex_track = None
88+
except (Exception, BadRequest) as plex_search_exception:
89+
logger.debug(
90+
f"Exception trying to search for artist '{artist_name}', track '{track_name}': {plex_search_exception}",
91+
)
92+
plex_track = None
7093
logger.debug("Song not in Plex!")
7194
logger.debug(
7295
f"Found artists for '{artist_name}' ({len(artist_tracks_in_plex)})",

0 commit comments

Comments
 (0)