diff --git a/data/interfaces/default/album.html b/data/interfaces/default/album.html
index 9f803a75..92b78890 100644
--- a/data/interfaces/default/album.html
+++ b/data/interfaces/default/album.html
@@ -33,7 +33,7 @@
else:
alternate_album_name = alternate_album['AlbumTitle'] + " (" + alternate_album['ReleaseCountry'] + ", " + alternate_album['ReleaseFormat'] + ")"
%>
- ${alternate_album_name}
+ ${alternate_album_name}
%endfor
%endif
diff --git a/headphones/__init__.py b/headphones/__init__.py
index 83b48d62..e61cb103 100644
--- a/headphones/__init__.py
+++ b/headphones/__init__.py
@@ -868,6 +868,11 @@ def dbcheck():
c.execute('SELECT ReleaseID from tracks')
except sqlite3.OperationalError:
c.execute('ALTER TABLE tracks ADD COLUMN ReleaseID TEXT DEFAULT NULL')
+
+ try:
+ c.execute('SELECT Matched from have')
+ except sqlite3.OperationalError:
+ c.execute('ALTER TABLE have ADD COLUMN Matched TEXT DEFAULT NULL')
conn.commit()
c.close()
diff --git a/headphones/albumswitcher.py b/headphones/albumswitcher.py
index d75e779c..377d32af 100644
--- a/headphones/albumswitcher.py
+++ b/headphones/albumswitcher.py
@@ -22,10 +22,10 @@ def switch(AlbumID, ReleaseID):
the albums & tracks table.
'''
myDB = db.DBConnection()
- oldalbumdata = myDB.select('SELECT * from albums WHERE AlbumID=?', [AlbumID])
- newalbumdata = myDB.select('SELECT * from allalbums WHERE ReleaseID=?', [ReleaseID])
- newtrackdata = myDB.select('SELECT * from alltracks WHERE ReleaseID=?', [ReleaseID])
- myDB.action('DELETE * from tracks WHERE AlbumID=?', [AlbumID])
+ oldalbumdata = myDB.action('SELECT * from albums WHERE AlbumID=?', [AlbumID]).fetchone()
+ newalbumdata = myDB.action('SELECT * from allalbums WHERE ReleaseID=?', [ReleaseID]).fetchone()
+ newtrackdata = myDB.action('SELECT * from alltracks WHERE ReleaseID=?', [ReleaseID]).fetchall()
+ myDB.action('DELETE from tracks WHERE AlbumID=?', [AlbumID])
controlValueDict = {"AlbumID": AlbumID}
@@ -45,7 +45,7 @@ def switch(AlbumID, ReleaseID):
for track in newtrackdata:
controlValueDict = {"TrackID": track['TrackID'],
- "AlbumID": AlbumID
+ "AlbumID": AlbumID}
newValueDict = {"ArtistID": track['ArtistID'],
"ArtistName": track['ArtistName'],
@@ -64,14 +64,15 @@ def switch(AlbumID, ReleaseID):
myDB.upsert("tracks", newValueDict, controlValueDict)
# Mark albums as downloaded if they have at least 80% (by default, configurable) of the album
+ total_track_count = len(newtrackdata)
have_track_count = len(myDB.select('SELECT * from tracks WHERE AlbumID=? AND Location IS NOT NULL', [AlbumID]))
if oldalbumdata['Status'] == 'Skipped' and ((have_track_count/float(total_track_count)) >= (headphones.ALBUM_COMPLETION_PCT/100.0)):
- myDB.action('UPDATE albums SET Status=? WHERE AlbumID=?', ['Downloaded', rg['id']])
+ myDB.action('UPDATE albums SET Status=? WHERE AlbumID=?', ['Downloaded', AlbumID])
# Update have track counts on index
- totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [artistid]))
- havetracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=? AND Location IS NOT NULL', [artistid])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [artist['artist_name']]))
+ totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [newalbumdata['ArtistID']]))
+ havetracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=? AND Location IS NOT NULL', [newalbumdata['ArtistID']])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [newalbumdata['ArtistID']]))
controlValueDict = {"ArtistID": newalbumdata['ArtistID']}
diff --git a/headphones/importer.py b/headphones/importer.py
index e8949e1d..e4f46a0a 100644
--- a/headphones/importer.py
+++ b/headphones/importer.py
@@ -153,6 +153,8 @@ def addArtisttoDB(artistid, extrasonly=False):
for rg in artist['releasegroups']:
+ logger.info("Now adding/updating: " + rg['title'])
+
rgid = rg['id']
# check if the album already exists
@@ -177,7 +179,7 @@ def addArtisttoDB(artistid, extrasonly=False):
try:
releasedict = mb.getRelease(releaseid, include_artist_info=False)
except Exception, e:
- logger.info('Unable to get release information for %s' % release['id'])
+ logger.info('Unable to get release information for %s: %s' % (release['id'], e))
continue
if not releasedict:
@@ -287,7 +289,7 @@ def addArtisttoDB(artistid, extrasonly=False):
myDB.upsert("alltracks", newValueDict, controlValueDict)
# Delete matched tracks from the have table
- myDB.action('DELETE * from have WHERE Matched="True"')
+ myDB.action('DELETE from have WHERE Matched="True"')
# If there's no release in the main albums tables, add the default (hybrid)
# If there is a release, check the ReleaseID against the AlbumID to see if they differ (user updated)
@@ -298,7 +300,7 @@ def addArtisttoDB(artistid, extrasonly=False):
else:
releaseid = rg_exists['ReleaseID']
- album = myDB.select('SELECT * from allallbums WHERE ReleaseID=?', releaseid)
+ album = myDB.action('SELECT * from allalbums WHERE ReleaseID=?', [releaseid]).fetchone()
controlValueDict = {"AlbumID": rg['id']}
@@ -319,15 +321,15 @@ def addArtisttoDB(artistid, extrasonly=False):
if headphones.AUTOWANT_ALL:
newValueDict['Status'] = "Wanted"
- elif release_dict['releasedate'] > helpers.today() and headphones.AUTOWANT_UPCOMING:
+ elif album['ReleaseDate'] > helpers.today() and headphones.AUTOWANT_UPCOMING:
newValueDict['Status'] = "Wanted"
else:
newValueDict['Status'] = "Skipped"
myDB.upsert("albums", newValueDict, controlValueDict)
- myDB.action('DELETE * from tracks WHERE AlbumID=?', rg['id'])
- tracks = myDB.select('SELECT * from alltracks WHERE ReleaseID=?', [releaseid])
+ myDB.action('DELETE from tracks WHERE AlbumID=?', [rg['id']])
+ tracks = myDB.action('SELECT * from alltracks WHERE ReleaseID=?', [releaseid]).fetchall()
# This is used to see how many tracks you have from an album - to mark it as downloaded. Default is 80%, can be set in config as ALBUM_COMPLETION_PCT
total_track_count = len(tracks)
@@ -363,7 +365,7 @@ def addArtisttoDB(artistid, extrasonly=False):
if ((have_track_count/float(total_track_count)) >= (headphones.ALBUM_COMPLETION_PCT/100.0)):
myDB.action('UPDATE albums SET Status=? WHERE AlbumID=?', ['Downloaded', rg['id']])
- logger.debug(u"Updating album cache for " + rg['title'])
+ logger.info(u"Seeing if we need album art for " + rg['title'])
cache.getThumb(AlbumID=rg['id'])
latestalbum = myDB.action('SELECT AlbumTitle, ReleaseDate, AlbumID from albums WHERE ArtistID=? order by ReleaseDate DESC', [artistid]).fetchone()
@@ -388,7 +390,7 @@ def addArtisttoDB(artistid, extrasonly=False):
myDB.upsert("artists", newValueDict, controlValueDict)
- logger.debug(u"Updating cache for: " + artist['artist_name'])
+ logger.info(u"Seeing if we need album art for: " + artist['artist_name'])
cache.getThumb(ArtistID=artistid)
logger.info(u"Updating complete for: " + artist['artist_name'])
@@ -603,7 +605,7 @@ def getHybridRelease(fullreleaselist):
for item in sortable_release_list:
item['trackscount_delta'] = abs(average_tracks - item['trackscount'])
- a = multikeysort(sortable_release_list, ['-hasasin', 'country', 'format', 'trackscount_delta'])
+ a = helpers.multikeysort(sortable_release_list, ['-hasasin', 'country', 'format', 'trackscount_delta'])
release_dict = {'ReleaseDate' : sortable_release_list[0]['releasedate'],
'Tracks' : a[0]['tracks'],
diff --git a/headphones/mb.py b/headphones/mb.py
index 7212c2ff..c98e5b07 100644
--- a/headphones/mb.py
+++ b/headphones/mb.py
@@ -315,8 +315,15 @@ def getRelease(releaseid, include_artist_info=True):
release['id'] = unicode(results['id'])
release['asin'] = unicode(results['asin']) if 'asin' in results else None
release['date'] = unicode(results['date'])
- release['format'] = unicode(results['medium-list'][0]['format'])
- release['country'] = unicode(results['country'])
+ try:
+ release['format'] = unicode(results['medium-list'][0]['format'])
+ except:
+ release['format'] = u'Unknown'
+
+ try:
+ release['country'] = unicode(results['country'])
+ except:
+ release['country'] = u'Unknown'
if include_artist_info:
diff --git a/headphones/webserve.py b/headphones/webserve.py
index 9810a3a3..2f88c041 100644
--- a/headphones/webserve.py
+++ b/headphones/webserve.py
@@ -218,6 +218,7 @@ class WebInterface(object):
'''
from headphones import albumswitcher
albumswitcher.switch(AlbumID, ReleaseID)
+ raise cherrypy.HTTPRedirect("albumPage?AlbumID=%s" % AlbumID)
switchAlbum.exposed = True
def upcoming(self):