11
11
def initialize_soulseek_client ():
12
12
host = headphones .CONFIG .SOULSEEK_API_URL
13
13
api_key = headphones .CONFIG .SOULSEEK_API_KEY
14
- return slskd_api .SlskdClient (host = host , api_key = api_key )
14
+ try :
15
+ return slskd_api .SlskdClient (host = host , api_key = api_key )
16
+ except :
17
+ logger .info ("Something went wrong while connecting to the soulseek client" )
15
18
16
19
# Search logic, calling search and processing fucntions
17
20
def search (artist , album , year , num_tracks , losslessOnly ):
@@ -24,14 +27,14 @@ def search(artist, album, year, num_tracks, losslessOnly):
24
27
return processed_results
25
28
26
29
# Stage 2: If Stage 1 fails, search with artist, album, and num_tracks (excluding year)
27
- logger .info ("Soulseek search stage 1 did not meet criteria. Retrying without year..." )
30
+ logger .debug ("Soulseek search stage 1 did not meet criteria. Retrying without year..." )
28
31
results = execute_search (client , artist , album , None , losslessOnly )
29
32
processed_results = process_results (results , losslessOnly , num_tracks )
30
33
if processed_results :
31
34
return processed_results
32
35
33
36
# Stage 3: Final attempt, search only with artist and album
34
- logger .info ("Soulseek search stage 2 did not meet criteria. Final attempt with only artist and album." )
37
+ logger .debug ("Soulseek search stage 2 did not meet criteria. Final attempt with only artist and album." )
35
38
results = execute_search (client , artist , album , None , losslessOnly )
36
39
processed_results = process_results (results , losslessOnly , num_tracks , ignore_track_count = True )
37
40
@@ -42,9 +45,8 @@ def execute_search(client, artist, album, year, losslessOnly):
42
45
if year :
43
46
search_text += f" { year } "
44
47
if losslessOnly :
45
- search_text += ".flac"
48
+ search_text += " .flac"
46
49
47
- # Actual search
48
50
search_response = client .searches .search_text (searchText = search_text , filterResponses = True )
49
51
search_id = search_response .get ('id' )
50
52
@@ -112,7 +114,6 @@ def download(user, filelist):
112
114
client = initialize_soulseek_client ()
113
115
client .transfers .enqueue (username = user , files = filelist )
114
116
115
-
116
117
def download_completed ():
117
118
client = initialize_soulseek_client ()
118
119
all_downloads = client .transfers .get_all_downloads (includeRemoved = False )
@@ -166,10 +167,7 @@ def download_completed():
166
167
print (f"Failed to cancel download for file ID: { file_id } " )
167
168
168
169
# Clear completed/canceled/errored stuff from client downloads
169
- try :
170
- client .transfers .remove_completed_downloads ()
171
- except Exception as e :
172
- print (f"Failed to remove completed downloads: { e } " )
170
+ client .transfers .remove_completed_downloads ()
173
171
174
172
# Identify completed albums
175
173
completed_albums = {album for album , counts in album_completion_tracker .items () if counts ['total' ] == counts ['completed' ]}
0 commit comments