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,17 +45,23 @@ 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
50
# Actual search
48
- search_response = client .searches .search_text (searchText = search_text , filterResponses = True )
51
+ try :
52
+ search_response = client .searches .search_text (searchText = search_text , filterResponses = True )
53
+ except :
54
+ logger .info ('Something went wrong trying to search soulseek' )
49
55
search_id = search_response .get ('id' )
50
56
51
57
# Wait for search completion and return response
52
58
while not client .searches .state (id = search_id ).get ('isComplete' ):
53
59
time .sleep (2 )
54
60
55
- return client .searches .search_responses (id = search_id )
61
+ try :
62
+ return client .searches .search_responses (id = search_id )
63
+ except :
64
+ logger .info ('Something went wrong getting search responsed from soulseek' )
56
65
57
66
# Processing the search result passed
58
67
def process_results (results , losslessOnly , num_tracks , ignore_track_count = False ):
@@ -110,12 +119,18 @@ def process_results(results, losslessOnly, num_tracks, ignore_track_count=False)
110
119
111
120
def download (user , filelist ):
112
121
client = initialize_soulseek_client ()
113
- client .transfers .enqueue (username = user , files = filelist )
122
+ try :
123
+ client .transfers .enqueue (username = user , files = filelist )
124
+ except :
125
+ logger .info ('Something went wrong enqueueing downloads in soulseek' )
114
126
115
127
116
128
def download_completed ():
117
129
client = initialize_soulseek_client ()
118
- all_downloads = client .transfers .get_all_downloads (includeRemoved = False )
130
+ try :
131
+ all_downloads = client .transfers .get_all_downloads (includeRemoved = False )
132
+ except :
133
+ logger .info ('Something went wrong grabbing all downloads from soulseek' )
119
134
album_completion_tracker = {} # Tracks completion state of each album's songs
120
135
album_errored_tracker = {} # Tracks albums with errored downloads
121
136
@@ -161,15 +176,18 @@ def download_completed():
161
176
# Extract 'id' and 'username' for each file to cancel the download
162
177
file_id = file_data .get ('id' , '' )
163
178
username = file_data .get ('username' , '' )
164
- success = client .transfers .cancel_download (username , file_id )
179
+ try :
180
+ success = client .transfers .cancel_download (username , file_id )
181
+ except :
182
+ logger .info ('Something went wrong canceling downloads in soulseek' )
165
183
if not success :
166
184
print (f"Failed to cancel download for file ID: { file_id } " )
167
185
168
186
# Clear completed/canceled/errored stuff from client downloads
169
187
try :
170
188
client .transfers .remove_completed_downloads ()
171
- except Exception as e :
172
- print (f"Failed to remove completed downloads: { e } " )
189
+ except :
190
+ print (f"Failed to remove completed downloads" )
173
191
174
192
# Identify completed albums
175
193
completed_albums = {album for album , counts in album_completion_tracker .items () if counts ['total' ] == counts ['completed' ]}
0 commit comments