From af97f16c258134106bd40b21125ffbaa5dd1ffa9 Mon Sep 17 00:00:00 2001 From: theguardian Date: Wed, 2 Oct 2013 11:26:06 -0700 Subject: [PATCH] Fixed bug where user-selected album release was overwritten by headphones hybrid release. --- headphones/importer.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/headphones/importer.py b/headphones/importer.py index b4874b79..a808d548 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -199,9 +199,9 @@ def addArtisttoDB(artistid, extrasonly=False): if len(artist['releasegroups']) != 0 and not extrasonly: for groups in artist['releasegroups']: group_list.append(groups['id']) - remove_missing_groups_from_albums = myDB.action("SELECT ReleaseID FROM albums WHERE ArtistID=?", [artistid]) + remove_missing_groups_from_albums = myDB.action("SELECT AlbumID, ReleaseID FROM albums WHERE ArtistID=?", [artistid]) for items in remove_missing_groups_from_albums: - if items['ReleaseID'] not in group_list: + if items['ReleaseID'] not in group_list and items['AlbumID']==items['ReleaseID']: #added 2nd clause for when user picks alternate release # Remove all from albums/tracks that aren't in release groups myDB.action("DELETE FROM albums WHERE ReleaseID=?", [items['ReleaseID']]) myDB.action("DELETE FROM allalbums WHERE ReleaseID=?", [items['ReleaseID']]) @@ -410,7 +410,10 @@ def addArtisttoDB(artistid, extrasonly=False): else: newValueDict['Status'] = "Skipped" - myDB.upsert("albums", newValueDict, controlValueDict) + #Only update albums table with hybrid release if user didn't choose an alternate release + check_alternate_release = myDB.action("SELECT AlbumID, ReleaseID FROM albums WHERE ArtistID=? AND AlbumID=?", ([artistid], [rg['id']])).fetchone() + if check_alternate_release[0] == check_alternate_release[1]: + myDB.upsert("albums", newValueDict, controlValueDict) myDB.action('DELETE from tracks WHERE AlbumID=?', [rg['id']]) tracks = myDB.action('SELECT * from alltracks WHERE ReleaseID=?', [releaseid]).fetchall() @@ -437,7 +440,10 @@ def addArtisttoDB(artistid, extrasonly=False): "BitRate": track['BitRate'] } - myDB.upsert("tracks", newValueDict, controlValueDict) + #Only update tracks table with hybrid release if user didn't choose an alternate release + check_alternate_release = myDB.action("SELECT AlbumID, ReleaseID FROM albums WHERE ArtistID=? AND AlbumID=?", ([artistid], [rg['id']])).fetchone() + if check_alternate_release[0] == check_alternate_release[1]: + myDB.upsert("tracks", newValueDict, controlValueDict) # Mark albums as downloaded if they have at least 80% (by default, configurable) of the album have_track_count = len(myDB.select('SELECT * from tracks WHERE AlbumID=? AND Location IS NOT NULL', [rg['id']]))