@@ -44,41 +44,61 @@ def match_spotify_tracks_in_plex(
44
44
artist_tracks_in_plex = music_library .search (
45
45
title = artist_name .replace ("'" , "" ),
46
46
)
47
- logger .debug (f"No results found for artist: { artist_name } " )
48
- missing_tracks .append ((track_name , artist_name ))
49
- continue
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
50
51
51
- try :
52
- track_name_no_apostrophe = track_name .replace ("'" , "" )
53
- plex_track = next (
54
- (
55
- track .track (title = track_name_no_apostrophe )
56
- for track in artist_tracks_in_plex
57
- if track .track (title = track_name_no_apostrophe )
58
- ),
59
- None ,
60
- )
61
- except NotFound :
62
- logger .debug (
63
- f"Track '{ track_name } ' by '{ artist_name } ' not found in Plex." ,
64
- )
65
- plex_track = None
66
- except (Exception , BadRequest ) as plex_search_exception :
67
- logger .debug (
68
- f"Exception trying to search for artist '{ artist_name } ', track '{ track_name } ': { plex_search_exception } " ,
69
- )
70
- plex_track = None
71
-
72
- if not plex_track :
73
- logger .debug ("Song not in Plex!" )
74
- logger .debug (
75
- f"Found artists for '{ artist_name } ' ({ len (artist_tracks_in_plex )} )" ,
76
- )
77
- logger .debug (f"Attempted to match song '{ track_name } ', but could not!" )
78
- missing_tracks .append ((track_name , artist_name ))
52
+ try :
53
+ plex_track = next (
54
+ (
55
+ track .track (title = track_name )
56
+ for track in artist_tracks_in_plex
57
+ if track .track (title = track_name )
58
+ ),
59
+ None ,
60
+ )
61
+ except NotFound :
62
+ logger .debug (
63
+ f"Track '{ track_name } ' by '{ artist_name } ' not found in Plex." ,
64
+ )
65
+ plex_track = None
66
+ except (Exception , BadRequest ) as plex_search_exception :
67
+ logger .debug (
68
+ f"Exception trying to search for artist '{ artist_name } ', track '{ track_name } ': { plex_search_exception } " ,
69
+ )
70
+ plex_track = None
71
+
72
+ 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
93
+ logger .debug ("Song not in Plex!" )
94
+ logger .debug (
95
+ f"Found artists for '{ artist_name } ' ({ len (artist_tracks_in_plex )} )" ,
96
+ )
97
+ logger .debug (f"Attempted to match song '{ track_name } ', but could not!" )
98
+ missing_tracks .append ((track_name , artist_name ))
79
99
80
- else :
81
- matched_tracks .append (plex_track )
100
+ else :
101
+ matched_tracks .append (plex_track )
82
102
83
103
success_percentage = (
84
104
(len (matched_tracks ) / total_tracks ) * 100 if total_tracks else 0
0 commit comments