@@ -52,7 +52,7 @@ def __init__(self):
52
52
self .plex_service = PlexService ()
53
53
self .lidarr_api = lapi ()
54
54
55
- self .lidarr_sync = ( self .config .get ("lidarr_sync" , "false" )). lower ( )
55
+ self .lidarr_sync = self .config .get ("lidarr_sync" , False )
56
56
if (
57
57
self .config .get ("plex_users" ) != ""
58
58
and self .config .get ("plex_users" ) is not None
@@ -65,7 +65,7 @@ def __init__(self):
65
65
self .replace_existing = self .config .get ("replace_existing" )
66
66
self .seconds_interval = int (self .config .get ("seconds_interval" ))
67
67
68
- if self .lidarr_sync == "true" :
68
+ if self .lidarr_sync is True :
69
69
self .sync_lists = self .lidarr_api .get_lidarr_playlists ()
70
70
else :
71
71
self .sync_lists = []
@@ -161,18 +161,41 @@ def process_playlist(
161
161
print (f"Error processing playlist '{ playlist } ':" , e )
162
162
163
163
def get_data_for_playlist (self ):
164
- playlists_data = {}
165
- for playlist in self .sync_lists :
164
+ def fetch_playlist_data (playlist ):
166
165
try :
167
166
playlist_id = Spotiplex .extract_playlist_id (playlist )
168
167
playlist_name = self .spotify_service .get_playlist_name (playlist_id )
168
+ if playlist_name is None :
169
+ playlist_name = f"Error processing playlist ID { playlist_id } "
169
170
spotify_tracks = self .spotify_service .get_playlist_tracks (playlist_id )
170
- playlists_data [ playlist_name ] = spotify_tracks
171
+ return playlist_name , spotify_tracks
171
172
except Exception as e :
172
173
print (f"Error processing playlist { playlist } : { e } " )
173
- # Optionally, handle the error (e.g., by logging or skipping the problematic playlist)
174
- continue
174
+ # Return a tuple indicating an error with the playlist to handle later
175
+ return f"Error processing playlist ID { playlist_id } " , None
176
+
177
+ playlists_data = {}
178
+ with ThreadPoolExecutor (max_workers = self .worker_count ) as executor :
179
+ # Schedule the fetch_playlist_data function to be called for each playlist
180
+ future_to_playlist = {
181
+ executor .submit (fetch_playlist_data , playlist ): playlist
182
+ for playlist in self .sync_lists
183
+ }
184
+
185
+ for future in concurrent .futures .as_completed (future_to_playlist ):
186
+ playlist = future_to_playlist [future ]
187
+ try :
188
+ playlist_name , spotify_tracks = future .result ()
189
+ if (
190
+ spotify_tracks is not None
191
+ ): # Ensure there was no error fetching data
192
+ playlists_data [playlist_name ] = spotify_tracks
193
+ except Exception as e :
194
+ print (f"Exception processing playlist { playlist } : { e } " )
195
+ continue
196
+
175
197
return playlists_data
198
+
176
199
def configurator (self ):
177
200
# Config for Spotiplex
178
201
0 commit comments