From db9df9b563f989d7e651dbb909e432cb79f877f0 Mon Sep 17 00:00:00 2001 From: Patrick Speiser Date: Tue, 11 Sep 2012 22:35:23 +0200 Subject: [PATCH] Allow deletion of empty artists (artists where you don't have any songs OR that haven't released any albums), should also work to fix Issue #569 and will in general be helpful --- data/interfaces/default/manage.html | 1 + headphones/webserve.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/data/interfaces/default/manage.html b/data/interfaces/default/manage.html index 19cc9ac4..88e26d8a 100644 --- a/data/interfaces/default/manage.html +++ b/data/interfaces/default/manage.html @@ -97,6 +97,7 @@ Force Update Active Artists Force Post-Process Albums in Download Folder Check for Headphones Updates + Delete empty Artists diff --git a/headphones/webserve.py b/headphones/webserve.py index 799d84f3..cbb82e4e 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -190,6 +190,20 @@ class WebInterface(object): raise cherrypy.HTTPRedirect("home") deleteArtist.exposed = True + + def deleteEmptyArtists(self): + logger.info(u"Deleting all empty artists") + myDB = db.DBConnection() + emptyArtistIDs = [row['ArtistID'] for row in myDB.select("SELECT ArtistID FROM artists WHERE HaveTracks == 0 OR LatestAlbum IS NULL")] + for ArtistID in emptyArtistIDs: + logger.info(u"Deleting all traces of artist: " + ArtistID) + myDB.action('DELETE from artists WHERE ArtistID=?', [ArtistID]) + myDB.action('DELETE from albums WHERE ArtistID=?', [ArtistID]) + myDB.action('DELETE from tracks WHERE ArtistID=?', [ArtistID]) + myDB.action('INSERT OR REPLACE into blacklist VALUES (?)', [ArtistID]) + deleteEmptyArtists.exposed = True + + def refreshArtist(self, ArtistID): threading.Thread(target=importer.addArtisttoDB, args=[ArtistID]).start() raise cherrypy.HTTPRedirect("artistPage?ArtistID=%s" % ArtistID)