From 5fc03e782a3af0d5937202de15760de2b3c89b93 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Fri, 13 Jul 2012 15:31:06 +0530 Subject: [PATCH 1/2] Persist new artists through restart (new artists now stored in db table 'newartists'), delete artist from newartists when added. Modified templates to use db instead of variable --- data/interfaces/brink/managenew.html | 4 ++-- data/interfaces/classic/managenew.html | 4 ++-- data/interfaces/default/managenew.html | 4 ++-- data/interfaces/remix/managenew.html | 4 ++-- headphones/__init__.py | 2 +- headphones/importer.py | 2 ++ headphones/librarysync.py | 4 +++- headphones/webserve.py | 4 +++- 8 files changed, 17 insertions(+), 11 deletions(-) diff --git a/data/interfaces/brink/managenew.html b/data/interfaces/brink/managenew.html index 0f6dd919..cd75ddee 100644 --- a/data/interfaces/brink/managenew.html +++ b/data/interfaces/brink/managenew.html @@ -20,7 +20,7 @@ - %for artist in headphones.NEW_ARTISTS: + %for artist in newartists: ${artist} @@ -49,4 +49,4 @@ }); }); - \ No newline at end of file + diff --git a/data/interfaces/classic/managenew.html b/data/interfaces/classic/managenew.html index bea493b2..eefe2881 100644 --- a/data/interfaces/classic/managenew.html +++ b/data/interfaces/classic/managenew.html @@ -20,7 +20,7 @@ - %for artist in headphones.NEW_ARTISTS: + %for artist in newartists: ${artist} @@ -49,4 +49,4 @@ }); }); - \ No newline at end of file + diff --git a/data/interfaces/default/managenew.html b/data/interfaces/default/managenew.html index c261c52e..b77cbf76 100644 --- a/data/interfaces/default/managenew.html +++ b/data/interfaces/default/managenew.html @@ -31,7 +31,7 @@ - %for artist in headphones.NEW_ARTISTS: + %for artist in newartists: ${artist} @@ -64,4 +64,4 @@ initActions(); }); - \ No newline at end of file + diff --git a/data/interfaces/remix/managenew.html b/data/interfaces/remix/managenew.html index bea493b2..eefe2881 100644 --- a/data/interfaces/remix/managenew.html +++ b/data/interfaces/remix/managenew.html @@ -20,7 +20,7 @@ - %for artist in headphones.NEW_ARTISTS: + %for artist in newartists: ${artist} @@ -49,4 +49,4 @@ }); }); - \ No newline at end of file + diff --git a/headphones/__init__.py b/headphones/__init__.py index 3d81e2a7..bea13250 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -89,7 +89,6 @@ PREFERRED_QUALITY = None PREFERRED_BITRATE = None DETECT_BITRATE = False ADD_ARTISTS = False -NEW_ARTISTS = [] CORRECT_METADATA = False MOVE_FILES = False RENAME_FILES = False @@ -698,6 +697,7 @@ def dbcheck(): c.execute('CREATE TABLE IF NOT EXISTS lastfmcloud (ArtistName TEXT, ArtistID TEXT, Count INTEGER)') c.execute('CREATE TABLE IF NOT EXISTS descriptions (ArtistID TEXT, ReleaseGroupID TEXT, ReleaseID TEXT, Summary TEXT, Content TEXT, LastUpdated TEXT)') c.execute('CREATE TABLE IF NOT EXISTS blacklist (ArtistID TEXT UNIQUE)') + c.execute('CREATE TABLE IF NOT EXISTS newartists (ArtistName TEXT UNIQUE)') c.execute('CREATE TABLE IF NOT EXISTS releases (ReleaseID TEXT, ReleaseGroupID TEXT, UNIQUE(ReleaseID, ReleaseGroupID))') c.execute('CREATE INDEX IF NOT EXISTS tracks_albumid ON tracks(AlbumID ASC)') c.execute('CREATE INDEX IF NOT EXISTS album_artistid_reldate ON albums(ArtistID ASC, ReleaseDate DESC)') diff --git a/headphones/importer.py b/headphones/importer.py index 838d4e2f..9dea738b 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -245,6 +245,8 @@ def addArtisttoDB(artistid, extrasonly=False): myDB.upsert("artists", newValueDict, controlValueDict) + myDB.action('DELETE from newartists WHERE ArtistName=?', [artist['artist_name']]) + logger.debug(u"Updating cache for: " + artist['artist_name']) cache.getThumb(ArtistID=artistid) diff --git a/headphones/librarysync.py b/headphones/librarysync.py index fe9bfaa1..162f8e17 100644 --- a/headphones/librarysync.py +++ b/headphones/librarysync.py @@ -126,7 +126,9 @@ def libraryScan(dir=None): importer.artistlist_to_mbids(artist_list) else: logger.info('To add these artists, go to Manage->Manage New Artists') - headphones.NEW_ARTISTS = artist_list + myDB.action('DELETE * from newartists') + for artist in artist_list: + myDB.action('INSERT into newartists VALUES (?)', [artist]) if headphones.DETECT_BITRATE: headphones.PREFERRED_BITRATE = sum(bitrates)/len(bitrates)/1000 diff --git a/headphones/webserve.py b/headphones/webserve.py index bcced9eb..bd2c11e1 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -236,7 +236,9 @@ class WebInterface(object): manageAlbums.exposed = True def manageNew(self): - return serve_template(templatename="managenew.html", title="Manage New Artists") + myDB = db.DBConnection() + newartists = myDB.select('SELECT * from newartists') + return serve_template(templatename="managenew.html", title="Manage New Artists", newartists=newartists) manageNew.exposed = True def markArtists(self, action=None, **args): From dfc0ffd6f89a5f65f77cf2ebbc4e6e0794fe3abc Mon Sep 17 00:00:00 2001 From: rembo10 Date: Fri, 13 Jul 2012 16:28:53 +0530 Subject: [PATCH 2/2] Bug fixes, moved delete from newartists to the artistlist_to_mbids function, don't check if blacklisted --- data/interfaces/brink/managenew.html | 4 ++-- data/interfaces/classic/managenew.html | 4 ++-- data/interfaces/default/managenew.html | 4 ++-- data/interfaces/remix/managenew.html | 4 ++-- headphones/importer.py | 22 ++++++++++++---------- headphones/librarysync.py | 2 +- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/data/interfaces/brink/managenew.html b/data/interfaces/brink/managenew.html index cd75ddee..8e34f561 100644 --- a/data/interfaces/brink/managenew.html +++ b/data/interfaces/brink/managenew.html @@ -22,8 +22,8 @@ %for artist in newartists: - - ${artist} + + ${artist['ArtistName']} %endfor diff --git a/data/interfaces/classic/managenew.html b/data/interfaces/classic/managenew.html index eefe2881..ac329cda 100644 --- a/data/interfaces/classic/managenew.html +++ b/data/interfaces/classic/managenew.html @@ -22,8 +22,8 @@ %for artist in newartists: - - ${artist} + + ${artist['ArtistName']} %endfor diff --git a/data/interfaces/default/managenew.html b/data/interfaces/default/managenew.html index b77cbf76..17d567f7 100644 --- a/data/interfaces/default/managenew.html +++ b/data/interfaces/default/managenew.html @@ -33,8 +33,8 @@ %for artist in newartists: - - ${artist} + + ${artist['ArtistName']} %endfor diff --git a/data/interfaces/remix/managenew.html b/data/interfaces/remix/managenew.html index eefe2881..ac329cda 100644 --- a/data/interfaces/remix/managenew.html +++ b/data/interfaces/remix/managenew.html @@ -22,8 +22,8 @@ %for artist in newartists: - - ${artist} + + ${artist['ArtistName']} %endfor diff --git a/headphones/importer.py b/headphones/importer.py index 9dea738b..5a5efa75 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -40,9 +40,6 @@ def is_exists(artistid): def artistlist_to_mbids(artistlist, forced=False): for artist in artistlist: - - if forced: - artist = unicode(artist, 'utf-8') results = mb.findArtist(artist, limit=1) @@ -57,12 +54,15 @@ def artistlist_to_mbids(artistlist, forced=False): logger.info('MusicBrainz query turned up no matches for: %s' % artist) continue - # Check if it's blacklisted/various artists + # Check if it's blacklisted/various artists (only check if it's not forced, e.g. through library scan auto-add.) + # Forced example = Adding an artist from Manage New Artists myDB = db.DBConnection() - bl_artist = myDB.action('SELECT * FROM blacklist WHERE ArtistID=?', [artistid]).fetchone() - if bl_artist or artistid == various_artists_mbid: - logger.info("Artist ID for '%s' is either blacklisted or Various Artists. To add artist, you must do it manually (Artist ID: %s)" % (artist, artistid)) - continue + + if not forced: + bl_artist = myDB.action('SELECT * FROM blacklist WHERE ArtistID=?', [artistid]).fetchone() + if bl_artist or artistid == various_artists_mbid: + logger.info("Artist ID for '%s' is either blacklisted or Various Artists. To add artist, you must do it manually (Artist ID: %s)" % (artist, artistid)) + continue # Add to database if it doesn't exist if not is_exists(artistid): @@ -73,6 +73,10 @@ def artistlist_to_mbids(artistlist, forced=False): havetracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [artistid])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [artist])) myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [havetracks, artistid]) + # Delete it from the New Artists if the request came from there + if forced: + myDB.action('DELETE from newartists WHERE ArtistName=?', [artist]) + # Update the similar artist tag cloud: logger.info('Updating artist information from Last.fm') try: @@ -245,8 +249,6 @@ def addArtisttoDB(artistid, extrasonly=False): myDB.upsert("artists", newValueDict, controlValueDict) - myDB.action('DELETE from newartists WHERE ArtistName=?', [artist['artist_name']]) - logger.debug(u"Updating cache for: " + artist['artist_name']) cache.getThumb(ArtistID=artistid) diff --git a/headphones/librarysync.py b/headphones/librarysync.py index 162f8e17..651ff7c8 100644 --- a/headphones/librarysync.py +++ b/headphones/librarysync.py @@ -126,7 +126,7 @@ def libraryScan(dir=None): importer.artistlist_to_mbids(artist_list) else: logger.info('To add these artists, go to Manage->Manage New Artists') - myDB.action('DELETE * from newartists') + myDB.action('DELETE from newartists') for artist in artist_list: myDB.action('INSERT into newartists VALUES (?)', [artist])