From 4ea867836e59ba3fa581d55f1618f31a4cc28928 Mon Sep 17 00:00:00 2001 From: theguardian Date: Wed, 9 Oct 2013 16:11:25 -0700 Subject: [PATCH] Optimized a few scan functions. --- headphones/librarysync.py | 17 +++++++++-------- headphones/webserve.py | 5 +++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/headphones/librarysync.py b/headphones/librarysync.py index 6af6c4fb..b60ab590 100644 --- a/headphones/librarysync.py +++ b/headphones/librarysync.py @@ -315,13 +315,14 @@ def update_album_status(AlbumID=None): album_completion = 0 logger.info('Album %s does not have any tracks in database' % album['AlbumTitle']) - if album['Status'] == "Downloaded" or album['Status'] == "Skipped": - if album_completion >= headphones.ALBUM_COMPLETION_PCT: - new_album_status = "Downloaded" - myDB.upsert("albums", {'Status' : "Downloaded"}, {'AlbumID' : album['AlbumID']}) - else: + if album_completion >= headphones.ALBUM_COMPLETION_PCT: + new_album_status = "Downloaded" + else: + if album['Status'] == "Skipped" or album['Status'] == "Downloaded": new_album_status = "Skipped" - myDB.upsert("albums", {'Status' : "Skipped"}, {'AlbumID' : album['AlbumID']}) - if new_album_status != album['Status']: - logger.info('Album %s changed to %s' % (album['AlbumTitle'], new_album_status)) + else: + new_album_status = album['Status'] + myDB.upsert("albums", {'Status' : new_album_status}, {'AlbumID' : album['AlbumID']}) + if new_album_status != album['Status']: + logger.info('Album %s changed to %s' % (album['AlbumTitle'], new_album_status)) logger.info('Album status update complete') \ No newline at end of file diff --git a/headphones/webserve.py b/headphones/webserve.py index 784ef20e..d3838bf0 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -408,17 +408,18 @@ class WebInterface(object): match_alltracks = myDB.action('SELECT CleanName from alltracks WHERE CleanName=?', [new_clean_filename]).fetchone() if match_alltracks: myDB.upsert("alltracks", newValueDict, controlValueDict) - match_tracks = myDB.action('SELECT CleanName from tracks WHERE CleanName=?', [new_clean_filename]).fetchone() + match_tracks = myDB.action('SELECT CleanName, AlbumID from tracks WHERE CleanName=?', [new_clean_filename]).fetchone() if match_tracks: myDB.upsert("tracks", newValueDict, controlValueDict) myDB.action('UPDATE have SET Matched="Manual" WHERE CleanName=?', [new_clean_filename]) + album_id = match_tracks['AlbumID'] update_count+=1 #This was throwing errors and I don't know why, but it seems to be working fine. #else: #logger.info("There was an error modifying Artist %s. This should not have happened" % existing_artist) logger.info("Manual matching yielded %s new matches for Artist %s" % (update_count, new_artist)) if update_count > 0: - librarysync.update_album_status() + librarysync.update_album_status(album_id) else: logger.info("Artist %s already named appropriately; nothing to modify" % existing_artist)