Skip to content

Commit be6c8c5

Browse files
committed
Lossy will be set to Wanted Lossless during processing
1 parent 81f6d9e commit be6c8c5

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

headphones/postprocessor.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,15 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list,
405405
# Need to update the downloaded track list with the new location.
406406
# Could probably just throw in the "headphones-modified" folder,
407407
# but this is good to make sure we're not counting files that may have failed to move
408+
408409
if new_folder:
409410
downloaded_track_list = []
410411
for r, d, f in os.walk(albumpath):
411412
for files in f:
412413
if any(files.lower().endswith('.' + x.lower()) for x in headphones.MEDIA_FORMATS):
413414
downloaded_track_list.append(os.path.join(r, files))
415+
416+
all_files_lossless = all(file.lower().endswith(tuple('.' + format.lower() for format in headphones.LOSSLESS_MEDIA_FORMATS)) for file in downloaded_track_list)
414417

415418
builder = metadata.AlbumMetadataBuilder()
416419
# Check if files are valid media files and are writable, before the steps
@@ -504,11 +507,19 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list,
504507
if headphones.CONFIG.FILE_PERMISSIONS_ENABLED:
505508
updateFilePermissions(albumpaths)
506509

507-
myDB = db.DBConnection()
508-
myDB.action('UPDATE albums SET status = "Downloaded" WHERE AlbumID=?', [albumid])
509-
myDB.action(
510-
'UPDATE snatched SET status = "Processed" WHERE Status NOT LIKE "Seed%" and AlbumID=?',
511-
[albumid])
510+
# If the downloaded tracks are lossy, but lossless is wanted, set status to wanted lossless
511+
if not all_files_lossless and headphones.CONFIG.PREFERRED_QUALITY == 1:
512+
myDB = db.DBConnection()
513+
myDB.action('UPDATE albums SET status = "Wanted Lossless" WHERE AlbumID=?', [albumid])
514+
myDB.action(
515+
'UPDATE snatched SET status = "Processed" WHERE Status NOT LIKE "Seed%" and AlbumID=?',
516+
[albumid])
517+
else:
518+
myDB = db.DBConnection()
519+
myDB.action('UPDATE albums SET status = "Downloaded" WHERE AlbumID=?', [albumid])
520+
myDB.action(
521+
'UPDATE snatched SET status = "Processed" WHERE Status NOT LIKE "Seed%" and AlbumID=?',
522+
[albumid])
512523

513524
# Check if torrent has finished seeding
514525
if headphones.CONFIG.TORRENT_DOWNLOADER != 0:

headphones/soulseek.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
def initialize_soulseek_client():
1212
host = headphones.CONFIG.SOULSEEK_API_URL
1313
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")
1518

1619
# Search logic, calling search and processing fucntions
1720
def search(artist, album, year, num_tracks, losslessOnly):
@@ -24,14 +27,14 @@ def search(artist, album, year, num_tracks, losslessOnly):
2427
return processed_results
2528

2629
# 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...")
2831
results = execute_search(client, artist, album, None, losslessOnly)
2932
processed_results = process_results(results, losslessOnly, num_tracks)
3033
if processed_results:
3134
return processed_results
3235

3336
# 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.")
3538
results = execute_search(client, artist, album, None, losslessOnly)
3639
processed_results = process_results(results, losslessOnly, num_tracks, ignore_track_count=True)
3740

@@ -42,9 +45,8 @@ def execute_search(client, artist, album, year, losslessOnly):
4245
if year:
4346
search_text += f" {year}"
4447
if losslessOnly:
45-
search_text += ".flac"
48+
search_text += " .flac"
4649

47-
# Actual search
4850
search_response = client.searches.search_text(searchText=search_text, filterResponses=True)
4951
search_id = search_response.get('id')
5052

@@ -112,7 +114,6 @@ def download(user, filelist):
112114
client = initialize_soulseek_client()
113115
client.transfers.enqueue(username=user, files=filelist)
114116

115-
116117
def download_completed():
117118
client = initialize_soulseek_client()
118119
all_downloads = client.transfers.get_all_downloads(includeRemoved=False)
@@ -166,10 +167,7 @@ def download_completed():
166167
print(f"Failed to cancel download for file ID: {file_id}")
167168

168169
# 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()
173171

174172
# Identify completed albums
175173
completed_albums = {album for album, counts in album_completion_tracker.items() if counts['total'] == counts['completed']}

0 commit comments

Comments
 (0)